• 请不要在回答技术问题时复制粘贴 AI 生成的内容
guanyin9cn
V2EX  ›  程序员

hw 海思内核模块, wireguard.ko

  •  
  •   guanyin9cn · Sep 9, 2021 · 3192 views
    This topic created in 1728 days ago, the information mentioned may be changed or developed.

    RT,

    光猫型号,hs8145x6, 电信最新款千兆猫,查了下自带 udp-tunnel.ko 。 想着能不能编译下 wireguard 模块。居然好像成功了。

    Supplement 1  ·  Sep 10, 2021
    用 lsmod 查看,wireguard 模块加载是成功的。
    运行 wg,没有显示协议不支持。

    但是,用 ip link add wg0 type wireguard, 显示 segment fault.
    dmesg 查看了下日志,没看懂。
    暂时不搞了。
    还是老老实实地用 ss 吧,毕竟不需要 内核模块支持。
    Supplement 2  ·  Sep 10, 2021

    具体编译,wireguard-linux-compat

    替换掉 Makefile

    PWD := $(shell pwd)
    obj-m += wireguard.o
    
    all:
            make ARCH=arm -C $(KERNEL)  M=$(PWD) modules
    clean:
            make -C $(KERNEL)  M=$(PWD) clean
    
    
    make ARCH=arm KERNEL=/mnt/linux-4.4.197 CROSS_COMPILE=/mnt/buildroot/output/host/bin/arm-linux-
    

    参考这里的编译方法。 github.com/0neday/OptiXstarHS8145X6/tree/main/persist-root-shell

    Supplement 3  ·  Sep 10, 2021
    编译 报 undefined,可能与 内核 的 config 有关,现在找不到适配的 config

    ```
    Building modules, stage 2.
    MODPOST 1 modules
    WARNING: "udp_tunnel_xmit_skb" [/mnt/wireguard-linux-compat/src/wireguard.ko] undefined!
    WARNING: "udp_sock_create6" [/mnt/wireguard-linux-compat/src/wireguard.ko] undefined!
    WARNING: "setup_udp_tunnel_sock" [/mnt/wireguard-linux-compat/src/wireguard.ko] undefined!
    WARNING: "udp_tunnel_sock_release" [/mnt/wireguard-linux-compat/src/wireguard.ko] undefined!
    WARNING: "udp_tunnel6_xmit_skb" [/mnt/wireguard-linux-compat/src/wireguard.ko] undefined!
    WARNING: "udp_sock_create4" [/mnt/wireguard-linux-compat/src/wireguard.ko] undefined!
    CC /mnt/wireguard-linux-compat/src/wireguard.mod.o
    LD [M] /mnt/wireguard-linux-compat/src/wireguard.ko
    make[1]: Leaving directory '/mnt/linux-4.4.197'
    ```
    Supplement 4  ·  Sep 10, 2021

    编译 报 undefined ,可能与 内核 的 config 有关,现在找不到适配的 config

    
      Building modules, stage 2.
      MODPOST 1 modules
    WARNING: "udp_tunnel_xmit_skb" [/mnt/wireguard-linux-compat/src/wireguard.ko] undefined!
    WARNING: "udp_sock_create6" [/mnt/wireguard-linux-compat/src/wireguard.ko] undefined!
    WARNING: "setup_udp_tunnel_sock" [/mnt/wireguard-linux-compat/src/wireguard.ko] undefined!
    WARNING: "udp_tunnel_sock_release" [/mnt/wireguard-linux-compat/src/wireguard.ko] undefined!
    WARNING: "udp_tunnel6_xmit_skb" [/mnt/wireguard-linux-compat/src/wireguard.ko] undefined!
    WARNING: "udp_sock_create4" [/mnt/wireguard-linux-compat/src/wireguard.ko] undefined!
      CC      /mnt/wireguard-linux-compat/src/wireguard.mod.o
      LD [M]  /mnt/wireguard-linux-compat/src/wireguard.ko
    make[1]: Leaving directory '/mnt/linux-4.4.197'
    
    
    Supplement 5  ·  Sep 10, 2021
    ```
    [root@x6 /mnt/jffs2/hw] # lsmod | grep wire
    wireguard 0
    ip6_udp_tunnel 2 wireguard,l2tp_core
    udp_tunnel 2 wireguard,l2tp_core
    ipv6 52 wireguard,bridge,datapath_v6ext,datapath...

    # busybox
    [root@x6 /mnt/jffs2/hw] # ip link add wg0 type wireguard
    ip: RTNETLINK answers: Operation not supported

    [root@x6 /mnt/jffs2/hw] # /bin/ip link add wg0 type wireguard
    Segmentation fault

    ```
    Supplement 6  ·  Sep 10, 2021
    [root@x6 /mnt/jffs2/hw] # lsmod | grep wire
    wireguard 0
    ip6_udp_tunnel 2 wireguard,l2tp_core
    udp_tunnel 2 wireguard,l2tp_core
    ipv6 52 wireguard,bridge,datapath_v6ext,datapath...
    
    # busybox
    [root@x6 /mnt/jffs2/hw] # ip link add wg0 type wireguard
    ip: RTNETLINK answers: Operation not supported
    
    [root@x6 /mnt/jffs2/hw] # /bin/ip link add wg0 type wireguard
    Segmentation fault
    
    # dmesg
    ip: unhandled page fault (11) , code 0x005
    CPU: 1 PID: 20978 Comm: ip Tainted: P        W  O    4.4.197 #1
    Hardware name: Hisilicon A9
    
    
    
    
    
    
    Supplement 7  ·  Sep 10, 2021
    [root@x6 /mnt/jffs2/hw] # wg setconf wg0 wg0.conf
    Unable to modify interface: Protocol not supported
    
    
    Supplement 8  ·  Sep 11, 2021

    big thanks ysc3839

    #static compile for armv7

    GOARM=5 GOARCH=arm GOOS=linux CGO_ENABLED=0 go build -ldflags "-extldflags '-static' -w -s " -o wireguard-go-armv5
    

    insmod tun.ko, 8145x6 tun.ko not default install

    insmod  /lib/modules/4.4.197/kernel/drivers/net/tun.ko
    

    exec

    LOG_LEVEL=debug wireguard-go-armv5  wg0
    

    check

    [root@x6 /mnt/jffs2/hw] # ifconfig  wg0
    wg0       Link encap:UNSPEC  HWaddr 
              POINTOPOINT NOARP MULTICAST  MTU:1420  Metric:1
    
    Supplement 9  ·  Sep 11, 2021

    #add conf

    #set ip
    ip -4 address add 172.16.0.2/32 dev wg0
    
    #up wg0
    ip link set mtu 1280 up dev wg0
    
    #add route
    ip -4 route add 172.217.0.1 dev wg0
    
    #set conf
    wg setconf wg0 wg0.conf
    
    

    能在光猫 x6上 ping 172.217.0.1, 在 电脑上无法ping。 很奇怪,难道要做什么iptables 策略吗?

    Supplement 10  ·  Sep 11, 2021
    ```
    [root@x6 /mnt/jffs2/hw] # route -n
    Kernel IP routing table
    Destination Gateway Genmask Flags Metric Ref Use Iface
    0.0.0.0 0.0.0.0 0.0.0.0 U 10 0 0 ppp257
    10.0.1.1 0.0.0.0 255.255.255.255 UH 0 0 0 wg0

    #ping test on x6
    [root@x6 /mnt/jffs2/hw] # ping 10.0.1.1
    PING 10.0.1.1 (10.0.1.1): 56 data bytes
    64 bytes from 10.0.1.1: seq=0 ttl=64 time=19.197 ms
    64 bytes from 10.0.1.1: seq=1 ttl=64 time=20.565 ms

    #ping on pc
    C:\Users\xxx>ping 10.0.1.1

    Pinging 10.0.1.1 with 32 bytes of data:

    ```
    11 replies    2021-11-18 10:02:56 +08:00
    sbilly
        1
    sbilly  
       Sep 10, 2021
    这玩意啥 CPU,性能咋样?
    guanyin9cn
        2
    guanyin9cn  
    OP
       Sep 10, 2021
    @sbilly 2 核海思 a9,千兆带宽能跑满,下载 douyin 视频啥,都是飞速。
    ysc3839
        3
    ysc3839  
       Sep 10, 2021
    你确定这设备用的是未经改动的主线内核吗? Linux 源代码不一致的情况下,编译出来的模块是不兼容的。config 不一样应该也是不兼容的。
    guanyin9cn
        4
    guanyin9cn  
    OP
       Sep 10, 2021
    @ysc3839 #3,海思肯定加了私货在里面。config 是从 光猫 /proc 里提取的
    请问,有 海思 开发板 kernel 4.4 的 config 吗?
    guanyin9cn
        5
    guanyin9cn  
    OP
       Sep 10, 2021
    @ysc3839 #3, 提前的 config,修改了 几个地方,为了保证 kernel ver magic 一致。
    wszgrcy
        6
    wszgrcy  
       Sep 10, 2021
    是不是 abi 不一样就可能不同?
    ysc3839
        7
    ysc3839  
       Sep 11, 2021 via Android
    另外,WireGuard 有用户模式的实现,如果只是为了用 WireGuard 可以试试这个。
    guanyin9cn
        8
    guanyin9cn  
    OP
       Sep 11, 2021
    @ysc3839 用户模式不需要内核模块?怎么实现
    guanyin9cn
        9
    guanyin9cn  
    OP
       Sep 11, 2021
    @ysc3839 #7, 谢谢,已成功
    guanyin9cn
        10
    guanyin9cn  
    OP
       Sep 13, 2021
    @ all
    此贴终结,wireguard.ko 不能运行的原因是 PLTs 问题。
    btworm
        11
    btworm  
       Nov 18, 2021
    @guanyin9cn #5 能否告知怎么保证 ver magic 一致。修改 config 的根据是什么?谢谢!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5336 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 95ms · UTC 08:03 · PVG 16:03 · LAX 01:03 · JFK 04:03
    ♥ Do have faith in what you're doing.