求基于linux内核3.16的netlink实例

我最近在搞一个基于内核的过滤模块,要用到netlink进行内核于用户程序的交互.
但网上关于netlink的实例基于的内核版本太低了,内核里面关于netlink的函数实现改的我无法下手.
求高手指导!!!感激不尽

1个回答

可以参考一下iproute2(ip和tc命令)和内核的通讯过程。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
用户空间程序ctrl+c中止,断掉netlink,内核异常

用户空间和内核采用netlink,一问一答,用户空间程序询问,内核驱动程序应答,内核注册到netlink_kernel_create()的回调函数是: static void netlink_loop(struct sk_buff *skb) { if(do_something()) { netlink_unicast(nl_sk,skb,dstPID,0); } } 其中,do_something是用DMA向设备发出设置命令,设置成功后返回(期间有100毫秒延时) 如果用户空间在连续向内核发包过程中,在终端用Ctrl+C中止发包,这时就会导致内核异常挂掉。非常奇怪,请问这是何原理? 而且,如果用户空间程序开着不断开netlink,这时候rmmod内核驱动不成功,提示正在使用中。。。

linux netlink netlink_kernel_create 总是创建失败

如题,在我的内核模块中,我尝试创建NETLINK__ROUTE 套接字来接受应用层RTM_NEWROUTE发来的消息,总是返回为NULL,一但修改成其他任意协议号,或在NETLINK_TEST自定义协议号,都可以创建成功,请问是为什么? 下面是自己写的内核模块代码,刚刚初学netlink,网上的例子很有限,自己查手册跟别人的代码写的一份,可以编译通过,流程不知道是否完善,但所能测试是否能创建套接字,就只有#define NETLINK_ROUTE 0 这个没法创建,实在是找不到原因,求助一下大家,拜托了 ``` #include <linux/init.h> #include <linux/module.h> #include <linux/types.h> #include <net/sock.h> #include <linux/netlink.h> #include <linux/err.h> //#include <linux/rtnetlink.h> MODULE_LICENSE("GPL"); MODULE_AUTHOR("liyishen"); MODULE_DESCRIPTION("rtnetlink"); struct sock*sk = NULL; extern struct net init_net; static void rtnetlink_rcv(struct sk_buff *skb){ struct nlmsghdr *nlh = NULL; char *umsg = NULL; if(skb->len >= nlmsg_total_size(0)){ nlh = nlmsg_hdr(skb); umsg = NLMSG_DATA(nlh); if(umsg){ printk("kernel recv from user: %s\n",umsg); } } } static int rtnetlink_net_init(struct net *net) { struct sk_buff *skb; skb = nlmsg_new(256, GFP_ATOMIC); if(!skb) { printk("netlink alloc failure\n"); return -1; } struct netlink_kernel_cfg cfg = { .groups = RTNLGRP_MAX, .input = rtnetlink_rcv, //.cb_mutex = &rtnl_mutex, .flags = NL_CFG_F_NONROOT_RECV, }; sk = netlink_kernel_create(net,17,&cfg);//就是这里,只要第二个参数传入NETLINK_ROUTE,就会返回NULL,其它协议都可以,甚至自定义的NETLINK_TEST也可以 if(NULL == sk){ printk("socked create failed\n"); return -1; } printk("rtnl sock create finished\n"); return 0; } int rtnl_init(void){ rtnetlink_net_init(&init_net); return 0; } void rtnl_exit(void){ if(sk){ netlink_kernel_release(sk); sk = NULL; } printk("rtnl_exit!\n"); } module_init(rtnl_init); module_exit(rtnl_exit); ```

netlink处理大数据在用户空间和用户态的通信问题时间问题?

在中断处理函数中进行网络报文的读取,然后通过netlink机制上传到用户态,进行报文分析。要求真个netlink上传数据,到数据处理完成,不超过250us,通过测试时间为2mn,左右 请问谁知道netlink用户态和内核通信时间大概多久?

在使用netlink时,提示创建netlink套接字失败?

程序在openwrt上运行,linux内核版本为3.10.44, 执行socket(PF_NETLINK, SOCK_RAW,NETLINK_FIREWALL);提示Unable to create netlink socket

linux netlink通信遇到一个奇怪的问题

各位: 通过netlink实现用户态与内核态通信。目前遇到一个问题,用户态发消息后,内核态的回掉函数触发了,但是传进来的sk_buff->len 为0.没有有效数据。用户态显示发送成功。有谁遇到过吗?内核版本3.18 ![图片说明](https://img-ask.csdn.net/upload/201506/26/1435289900_850491.png)

内核下半部用netlink向用户空间发包,发快了会挂掉

内核在下半部bh中,使用netlink_unicast向用户空间发包,发得快时,dmesg会显示竞争资源失败。下半部是否不能使用netlink_unicast这种函数?或者说应该加个什么保护,适时释放CPU?

Linux C获取socket接收缓冲区使用量大小

因为网络实验要求,需要获取socket接受缓冲区已经占用的量。 目前尝试了使用ioctl获取,但是被告知用netlink访问内核的方法更好。 但是查询过程中发现内核代码很不熟悉,希望能获得一个代码进行参考。

如何使用netlink for golang实现类似“ ipvsadm --restore”的功能

<div class="post-text" itemprop="text"> <p>I want implement a "ipvsadm --restore" like function, leveraging on github.com/vishvananda/netlink/nl. Search on github, I find a helpful golang ipvs lib in <a href="https://github.com/docker/libnetwork/tree/master/ipvs" rel="nofollow noreferrer">libnetwork</a>. </p> <p>However, it just provide New/Update/Delete functions for Service and Destination. </p> <p>I want a "ipvsadm --restore" like function. I am not an ipvs/netlink expert, is there anyone can kindly point out how to implement one. </p> <p>Actually, I have try to implement like this, but it does not work.</p> <pre class="lang-golang prettyprint-override"><code>package ipvs import ( "net" "syscall" "fmt" "os/exec" "strings" "github.com/vishvananda/netlink/nl" "bytes" "encoding/binary" ) // Service defines an IPVS service in its entirety. type Service struct { // Virtual service address. Address net.IP Protocol uint16 Port uint16 FWMark uint32 // Firewall mark of the service. // Virtual service options. SchedName string Flags uint32 Timeout uint32 Netmask uint32 AddressFamily uint16 PEName string } // Destination defines an IPVS destination (real server) in its // entirety. type Destination struct { Address net.IP Port uint16 Weight int ConnectionFlags uint32 AddressFamily uint16 UpperThreshold uint32 LowerThreshold uint32 } type ServiceDestination struct { Service *Service Destinations []*Destination } // Handle provides an ipvs handle to program ipvs rules. type IPVSHandle struct { ipvsFamily int } // NewIPVSHandler provides a new ipvs handler func NewIPVSHandle() (*IPVSHandle, error) { if out, err := exec.Command("modprobe", "-va", "ip_vs").CombinedOutput(); err != nil { return nil, fmt.Errorf("Running modprobe ip_vs failed with message: `%s`, error: %v", strings.TrimSpace(string(out)), err) } ipvsFamily, err := getIPVSFamily() if err != nil { return nil, fmt.Errorf("Could not get ipvs family information from the kernel. It is possible that ipvs is not enabled in your kernel.") } return &amp;IPVSHandle{ipvsFamily: ipvsFamily}, nil } func ( i *IPVSHandle) Restore(items []ServiceDestination)([][]byte, error) { req := nl.NewNetlinkRequest(i.ipvsFamily, syscall.NLM_F_REPLACE) req.AddData(&amp;genlMsgHdr{cmd: ipvsCmdSetConfig, version: 1}) listAttr := nl.NewRtAttr(ipvsCmdAttrUnspec, nl.Uint16Attr(uint16(i.ipvsFamily))) for _, item := range items { itemAttr := nl.NewRtAttr(ipvsCmdAttrUnspec, nl.Uint16Attr(uint16(i.ipvsFamily))) srvAttr := toServiceAttr(item.Service) nl.NewRtAttrChild(itemAttr, ipvsCmdAttrService, srvAttr.Serialize()) for _, d := range item.Destinations { nl.NewRtAttrChild(itemAttr, ipvsCmdAttrDest, fillDestinaton(d).Serialize()) } nl.NewRtAttrChild(listAttr, ipvsCmdAttrUnspec, itemAttr.Serialize()) } req.AddData(listAttr) return req.Execute(syscall.NETLINK_GENERIC, 0) } func toServiceAttr(s *Service) *nl.RtAttr { cmdAttr := nl.NewRtAttr(ipvsCmdAttrService, nil) nl.NewRtAttrChild(cmdAttr, ipvsSvcAttrAddressFamily, nl.Uint16Attr(s.AddressFamily)) if s.FWMark != 0 { nl.NewRtAttrChild(cmdAttr, ipvsSvcAttrFWMark, nl.Uint32Attr(s.FWMark)) } else { nl.NewRtAttrChild(cmdAttr, ipvsSvcAttrProtocol, nl.Uint16Attr(s.Protocol)) nl.NewRtAttrChild(cmdAttr, ipvsSvcAttrAddress, rawIPData(s.Address)) // Port needs to be in network byte order. portBuf := new(bytes.Buffer) binary.Write(portBuf, binary.BigEndian, s.Port) nl.NewRtAttrChild(cmdAttr, ipvsSvcAttrPort, portBuf.Bytes()) } nl.NewRtAttrChild(cmdAttr, ipvsSvcAttrSchedName, nl.ZeroTerminated(s.SchedName)) if s.PEName != "" { nl.NewRtAttrChild(cmdAttr, ipvsSvcAttrPEName, nl.ZeroTerminated(s.PEName)) } f := &amp;ipvsFlags{ flags: s.Flags, mask: 0xFFFFFFFF, } nl.NewRtAttrChild(cmdAttr, ipvsSvcAttrFlags, f.Serialize()) nl.NewRtAttrChild(cmdAttr, ipvsSvcAttrTimeout, nl.Uint32Attr(s.Timeout)) nl.NewRtAttrChild(cmdAttr, ipvsSvcAttrNetmask, nl.Uint32Attr(s.Netmask)) return cmdAttr } func fillDestinaton(d *Destination) nl.NetlinkRequestData { cmdAttr := nl.NewRtAttr(ipvsCmdAttrDest, nil) nl.NewRtAttrChild(cmdAttr, ipvsDestAttrAddress, rawIPData(d.Address)) // Port needs to be in network byte order. portBuf := new(bytes.Buffer) binary.Write(portBuf, binary.BigEndian, d.Port) nl.NewRtAttrChild(cmdAttr, ipvsDestAttrPort, portBuf.Bytes()) nl.NewRtAttrChild(cmdAttr, ipvsDestAttrForwardingMethod, nl.Uint32Attr(d.ConnectionFlags&amp;ConnectionFlagFwdMask)) nl.NewRtAttrChild(cmdAttr, ipvsDestAttrWeight, nl.Uint32Attr(uint32(d.Weight))) nl.NewRtAttrChild(cmdAttr, ipvsDestAttrUpperThreshold, nl.Uint32Attr(d.UpperThreshold)) nl.NewRtAttrChild(cmdAttr, ipvsDestAttrLowerThreshold, nl.Uint32Attr(d.LowerThreshold)) return cmdAttr } </code></pre> </div>

wpa_supplicant报nl80211 generic netlink not found

![图片说明](https://img-ask.csdn.net/upload/201510/05/1444017128_739750.jpg)![图片说明](https://img-ask.csdn.net/upload/201510/05/1444017201_506679.jpg) 使用iwconfig命令时是显示有我的usb网卡,使用iwlist scannning命令也是可以搜索出附近wifi连接的,就是在使用 ``` wpa_supplicant ``` 命令时报 nl80211 generic netlink not found的错误,我使用的是cf-wu755p无线网卡,驱动装了8188eu.ok.是不是少装了什么模块?还是之前有什么模块没装好?帮帮忙,先谢了~

哪个字段对应于netlink中的“ dev”(设备)参数?

<div class="post-text" itemprop="text"> <p>I'm trying to add a new route using the <a href="http://godoc.org/github.com/krhubert/netlink#Route" rel="nofollow">netlink</a> package. The equivalent I need is <code>ip route add $P1_NET dev $IF1 src $IP1 table $T1</code>. The issue is that I don't know what field corresponds to the <code>dev</code> parameter. Is there a mapping somewhere or can I use the interface index instead its name ("dev")?</p> </div>

liunx系统ubuntu 16.04.3安装Busybox过程中make失败求解决,错误代码如下。

root@liunx-virtual-machine:/mnt/hgfs/linux共享/busybox-1.17.3# make CC networking/ifplugd.o In file included from /usr/include/linux/kernel.h:4:0, from /usr/include/linux/netlink.h:4, from networking/ifplugd.c:16: /usr/include/linux/sysinfo.h:7:8: error: redefinition of ‘struct sysinfo’ struct sysinfo { ^ In file included from networking/ifplugd.c:9:0: include/libbb.h:108:8: note: originally defined here struct sysinfo { ^ scripts/Makefile.build:197: recipe for target 'networking/ifplugd.o' failed make[1]: *** [networking/ifplugd.o] Error 1 Makefile:740: recipe for target 'networking' failed make: *** [networking] Error 2

如何使用Go语言的RTNETLINK套接字监视IP地址更改

<div class="post-text" itemprop="text"> <p>I have following code, which should monitor network changes using RTNETLINK socket. However when I am setting new IP address for interface "New Addr" or "Del Addr" does not showing. What can be possible problem.</p> <pre><code>package main import ( "fmt" "syscall" ) func main() { l, _ := ListenNetlink() for { msgs, err := l.ReadMsgs() if err != nil { fmt.Println("Could not read netlink: %s", err) } for _, m := range msgs { if IsNewAddr(&amp;m) { fmt.Println("New Addr") } if IsDelAddr(&amp;m) { fmt.Println("Del Addr") } } } } type NetlinkListener struct { fd int sa *syscall.SockaddrNetlink } func ListenNetlink() (*NetlinkListener, error) { groups := syscall.RTNLGRP_LINK | syscall.RTNLGRP_IPV4_IFADDR | syscall.RTNLGRP_IPV6_IFADDR s, err := syscall.Socket(syscall.AF_NETLINK, syscall.SOCK_DGRAM, syscall.NETLINK_ROUTE) if err != nil { return nil, fmt.Errorf("socket: %s", err) } saddr := &amp;syscall.SockaddrNetlink{ Family: syscall.AF_NETLINK, Pid: uint32(0), Groups: uint32(groups), } err = syscall.Bind(s, saddr) if err != nil { return nil, fmt.Errorf("bind: %s", err) } return &amp;NetlinkListener{fd: s, sa: saddr}, nil } func (l *NetlinkListener) ReadMsgs() ([]syscall.NetlinkMessage, error) { defer func() { recover() }() pkt := make([]byte, 2048) n, err := syscall.Read(l.fd, pkt) if err != nil { return nil, fmt.Errorf("read: %s", err) } msgs, err := syscall.ParseNetlinkMessage(pkt[:n]) if err != nil { return nil, fmt.Errorf("parse: %s", err) } return msgs, nil } func IsNewAddr(msg *syscall.NetlinkMessage) bool { if msg.Header.Type == syscall.RTM_NEWADDR { return true } return false } func IsDelAddr(msg *syscall.NetlinkMessage) bool { if msg.Header.Type == syscall.RTM_DELADDR { return true } return false } func IsRelevant(msg *syscall.IfAddrmsg) bool { if msg.Scope == syscall.RT_SCOPE_UNIVERSE || msg.Scope == syscall.RT_SCOPE_SITE { return true } return false } </code></pre> </div>

由于定制构建内核,在libcontainer的编译/安装过程中出现错误

<div class="post-text" itemprop="text"> <p>I did a git clone of master at libcontainer and then followed through the CONTRIBUTING.md guide.</p> <pre><code>./update-vendor.sh go get -d ./... make direct-build # Run the tests make direct-test-short | egrep --color 'FAIL|$' # Run all the test make direct-test | egrep --color 'FAIL|$' </code></pre> <p>THe output of "make direct-build" gives:</p> <pre><code> go build -v . ./apparmor ./cgroups ./cgroups/fs ./cgroups/systemd ./configs ./configs/validate ./criurpc ./devices ./integration ./label ./netlink ./nsenter ./nsinit ./seccomp ./selinux ./stacktrace ./system ./user ./utils ./xattr github.com/docker/libcontainer/cgroups/systemd &lt;xxxxx&gt; # github.com/docker/libcontainer/cgroups/systemd /sda10/gopath/src/github.com/docker/libcontainer/cgroups/systemd/apply_systemd.go:87: not enough arguments in call to theConn.StartTransientUnit /sda10/gopath/src/github.com/docker/libcontainer/cgroups/systemd/apply_systemd.go:102: not enough arguments in call to theConn.StopUnit /sda10/gopath/src/github.com/docker/libcontainer/cgroups/systemd/apply_systemd.go:121: not enough arguments in call to theConn.StartTransientUnit /sda10/gopath/src/github.com/docker/libcontainer/cgroups/systemd/apply_systemd.go:130: not enough arguments in call to theConn.StopUnit /sda10/gopath/src/github.com/docker/libcontainer/cgroups/systemd/apply_systemd.go:201: not enough arguments in call to theConn.StartTransientUnit /sda10/gopath/src/github.com/docker/libcontainer/cgroups/systemd/apply_systemd.go:272: not enough arguments in call to theConn.StopUnit _/home/tthtlc/libcontainer/label # _/home/tthtlc/libcontainer/cgroups/systemd cgroups/systemd/apply_systemd.go:87: not enough arguments in call to theConn.StartTransientUnit cgroups/systemd/apply_systemd.go:102: not enough arguments in call to theConn.StopUnit cgroups/systemd/apply_systemd.go:121: not enough arguments in call to theConn.StartTransientUnit cgroups/systemd/apply_systemd.go:130: not enough arguments in call to theConn.StopUnit cgroups/systemd/apply_systemd.go:201: not enough arguments in call to theConn.StartTransientUnit cgroups/systemd/apply_systemd.go:272: not enough arguments in call to theConn.StopUnit make: *** [direct-build] Error 2 </code></pre> <p>I tried this:</p> <pre><code>go get github.com/tools/godep go get -d github.com/google/cadvisor </code></pre> <p>All returned without errors. Likely cause is "docker -d" daemon not starting up.</p> <p>More details:</p> <pre><code>docker version Client version: 1.7.0-dev Client API version: 1.19 Go version (client): go1.4.2 Git commit (client): 5e06332 OS/Arch (client): linux/amd64 FATA[0000] Get http:///var/run/docker.sock/v1.19/version: dial unix /var/run/docker.sock: permission denied. Are you trying to connect to a TLS-enabled daemon without TLS? </code></pre> <p>"docker -d" is not able to succeed because my linux kernel is custom build (4.2.0-rc4+, and CONFIG_AUFS_FS is completely absent from my config tree option as it has been deprecated and removed).</p> <p>Any ideas on how to proceed?</p> </div>

使用go build CGO_ENABLED交叉编译-警告:未找到libudev.so.1

<div class="post-text" itemprop="text"> <p>I am trying to cross-compile a Golang application for a Raspberry Pi with <code>CGO_ENABLED=1</code> due to a <code>libusb</code> dependency</p> <p>During compilation I get the error:</p> <pre><code>arm-linux-gnueabihf/bin/ld: warning: libudev.so.1, needed by /usr/lib/arm-linux-gnueabihf/libusb-1.0.so, not found (try using -rpath or -rpath-link) </code></pre> <p>I have tried multiple variations of the command below with no luck:</p> <pre><code>CGO_ENABLED=1 GOARCH=arm GOARM=7 PKG_CONFIG_LIBDIR=/usr/lib/arm-linux-gnueabihf/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ go build -x -ldflags '-extld=arm-linux-gnueabihf-gcc -rpath=/usr/lib/arm-linux-gnueabihf -L/usr/lib/arm-linux-gnueabihf -ludev' </code></pre> <p>When I run the build with the <code>-x</code> flag I get the verbose output, and it kinda looks like its failing whilst building the <code>src/net</code> package:</p> <pre><code>cd /usr/local/go/src/net /usr/local/go/pkg/tool/linux_amd64/cgo -dynpackage net -dynimport $WORK/net/_obj/_cgo_.o -dynout $WORK/net/_obj/_cgo_import.go arm-linux-gnueabihf-gcc -I . -fPIC -marm -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -o $WORK/net/_obj/_all.o $WORK/net/_obj/_cgo_export.o $WORK/net/_obj/cgo_linux.cgo2.o $WORK/net/_obj/cgo_resnew.cgo2.o $WORK/net/_obj/cgo_socknew.cgo2.o $WORK/net/_obj/cgo_unix.cgo2.o -g -O2 -Wl,-r -nostdlib -Wl,--build-id=none /usr/local/go/pkg/tool/linux_amd64/compile -o $WORK/net.a -trimpath $WORK -p net -buildid 9e58c94d1ddeba63666a35ecee9409056baf5d3c -D _/usr/local/go/src/net -I $WORK -pack ./addrselect.go ./conf.go ./dial.go ./dnsclient.go ./dnsclient_unix.go ./dnsconfig_unix.go ./dnsmsg.go ./fd_mutex.go ./fd_poll_runtime.go ./fd_posix.go ./fd_unix.go ./file.go ./file_unix.go ./hook.go ./hook_cloexec.go ./hook_unix.go ./hosts.go ./interface.go ./interface_linux.go ./ip.go ./iprawsock.go ./iprawsock_posix.go ./ipsock.go ./ipsock_posix.go ./lookup.go ./lookup_unix.go ./mac.go ./net.go ./nss.go ./parse.go ./pipe.go ./port.go ./port_unix.go ./sendfile_linux.go ./sock_cloexec.go ./sock_linux.go ./sock_posix.go ./sockopt_linux.go ./sockopt_posix.go ./sockoptip_linux.go ./sockoptip_posix.go ./tcpsock.go ./tcpsock_posix.go ./tcpsockopt_posix.go ./tcpsockopt_unix.go ./udpsock.go ./udpsock_posix.go ./unixsock.go ./unixsock_posix.go ./writev_unix.go $WORK/net/_obj/_cgo_gotypes.go $WORK/net/_obj/cgo_linux.cgo1.go $WORK/net/_obj/cgo_resnew.cgo1.go $WORK/net/_obj/cgo_socknew.cgo1.go $WORK/net/_obj/cgo_unix.cgo1.go $WORK/net/_obj/_cgo_import.go # github.com/resin-io/edge-node-manager/vendor/github.com/kylelemons/gousb/usb /tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: warning: libudev.so.1, needed by /usr/lib/arm-linux-gnueabihf/libusb-1.0.so, not found (try using -rpath or -rpath-link) /usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `udev_monitor_filter_add_match_subsystem_devtype@LIBUDEV_183' /usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `udev_monitor_enable_receiving@LIBUDEV_183' /usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `udev_enumerate_scan_devices@LIBUDEV_183' /usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `udev_new@LIBUDEV_183' /usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `udev_device_get_devnode@LIBUDEV_183' /usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `udev_enumerate_new@LIBUDEV_183' /usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `udev_list_entry_get_name@LIBUDEV_183' /usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `udev_enumerate_add_match_subsystem@LIBUDEV_183' /usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `udev_device_get_sysname@LIBUDEV_183' /usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `udev_enumerate_get_list_entry@LIBUDEV_183' /usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `udev_device_new_from_syspath@LIBUDEV_183' /usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `udev_monitor_new_from_netlink@LIBUDEV_183' /usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `udev_monitor_receive_device@LIBUDEV_183' /usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `udev_device_unref@LIBUDEV_183' /usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `udev_enumerate_unref@LIBUDEV_183' /usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `udev_monitor_get_fd@LIBUDEV_183' /usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `udev_list_entry_get_next@LIBUDEV_183' /usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `udev_monitor_unref@LIBUDEV_183' /usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `clock_gettime@GLIBC_2.17' /usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `udev_unref@LIBUDEV_183' /usr/lib/arm-linux-gnueabihf/libusb-1.0.so: undefined reference to `udev_device_get_action@LIBUDEV_183' collect2: error: ld returned 1 exit status </code></pre> <p>The strange thing is that the compiler can find <code>/usr/lib/arm-linux-gnueabihf/libusb-1.0.so</code> and if I do <code>ls -al</code> in that directory <code>libudev.so</code> is also present. Both files linking back to <code>/lib/arm-linux-gnueabihf/</code></p> <pre><code>lrwxrwxrwx 1 root root 41 Jan 7 04:14 libudev.so -&gt; /lib/arm-linux-gnueabihf/libudev.so.1.5.0 -rw-r--r-- 1 root root 105464 Jun 16 2014 libusb-1.0.a lrwxrwxrwx 1 root root 44 Jun 16 2014 libusb-1.0.so -&gt; /lib/arm-linux-gnueabihf/libusb-1.0.so.0.1.0 drwxr-xr-x 2 root root 4096 Mar 15 14:48 pkgconfig </code></pre> <p><code>/usr/lib/arm-linux-gnueabihf/pkgconfig</code> contains:</p> <pre><code>-rw-r--r-- 1 root root 513 Jan 7 04:13 libudev.pc -rw-r--r-- 1 root root 332 Jun 16 2014 libusb-1.0.pc </code></pre> <p>Finally, running <code>file</code> shows both <code>libusb</code> and <code>libudev</code> to be the correct architecture:</p> <pre><code>/lib/arm-linux-gnueabihf/libusb-1.0.so.0.1.0: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=7d7b487c91042c1f254b39516b4aeabedfb828fc, stripped /lib/arm-linux-gnueabihf/libudev.so.1.5.0: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=334f4f0d8b1222a324ccd0827c1613fdd1e2ec15, stripped </code></pre> </div>

在我的例子里,Linux的kernel与user space如何进行通信才好?

我的例子大概如下: 我想做一个简单的分布式文件系统。在client端,当某个用户态应用程序open()一个远程文件时,VFS会去通知另一个专用的用户态应用程序,然后这个专用的用户态应用程序会去server端把远程文件缓存到本地,然后通知VFS这个缓存文件的路径。然后VFS会去打开这个缓存文件,再把文件的描述符返回给最开始的用户态应用程序。 在这里,我要进行kernel和user space的通信。一方面,在kernel里的VFS要告诉专用的用户态应用程序,我要打开的远程文件的路径是什么;另一方面,专用的用户态应用程序要告诉VFS,缓存下来的文件的路径是什么。 我目前是使用netlink socket来实现这个功能。这是没有问题的。但是由于我对Linux kernel并不熟悉,所以我不知道是不是还有其它更加有效的方式来解决这个问题。 比如,我之前在想,能不能用mmap()的方式实现kernel和user space之间的通信。但是我在了解了一下之后发现,在我的这个例子里,好像我必须要写一个驱动程序,才能提供一个设备文件作为mmap()的后盾。这在用法上就有点像命名管道或者命名socket(或者叫Unix domain socket?),感觉没什么意思,而且似乎也不太容易整合进VFS去。 然后,我又在想,能不能让VFS和这个专用的用户态应用程序somehow约定一个user space的缓冲区地址,然后VFS直接copy_to_user()(专用的用户态应用程序就直接写这个缓冲区)。但是我又不知道要怎样约定这个缓冲区的地址才好,以及怎么通知对方说我写了新的数据进去。 所以在这里求教。有没有什么好的办法在我的这个例子里实现kernel与user space的通信?以及我对mmap()、命名管道、命名socket或者copy_to_user()的理解有没有问题?感谢。

网络链接序列号乱序

<div class="post-text" itemprop="text"> <p>I'm using the <a href="https://github.com/mdlayher/netlink" rel="nofollow noreferrer"><code>netlink</code></a> and <a href="https://github.com/mdlayher/genetlink" rel="nofollow noreferrer"><code>genetlink</code></a> Go packages to write a utility to interact with the <code>MAC80211_HWSIM</code> netlink family functions. It's working well ... almost.</p> <p>I'm finding that if I do a <code>GET_RADIO</code> call, the next call into the family fails to validate because the sequence number of the response doesn't match that of the request. Specifically, the pattern I see is</p> <pre><code>GET_RADIO request: seq=655 GET_RADIO response: seq=655 DEL_RADIO request: seq=656 DEL_RADIO response: seq=655 </code></pre> <p>It doesn't matter which command I issue after <code>GET_RADIO</code>, this same pattern shows up. If <code>GET_RADIO</code> isn't in the mix, then the sequence numbers are exactly as expected.</p> <p>There's an existing command written in C, using <code>libnl</code> and <code>libgenl</code>, which I modified to run more than one command. As best I can tell, that implementation does a very similar thing, but doesn't have the issue with the sequence numbers, so I'm disinclined to think the problem lies with the kernel module. But strace clearly shows that the kernel is responding with an out-of-sequence number (please forgive the excessive side-scrolling):</p> <pre><code>socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC) = 3 bind(3, {sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, 12) = 0 getsockname(3, {sa_family=AF_NETLINK, nl_pid=18357, nl_groups=00000000}, [112-&gt;12]) = 0 sendmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=12, msg_iov=[{iov_base={{len=40, type=0x10 /* NLMSG_??? */, flags=NLM_F_REQUEST, seq=2596996163, pid=18357}, "\3\1\0\0\23\0\2\0MAC80211_HWSIM\0\0"}, iov_len=40}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 40 recvmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=112-&gt;12, msg_iov=[{iov_base=[{{len=224, type=0x10 /* NLMSG_??? */, flags=0, seq=2596996163, pid=18357}, "\1\2\0\0\23\0\2\0MAC80211_HWSIM\0\0\6\0\1\0\31\0\0\0"...}, {{len=0, type=0 /* NLMSG_??? */, flags=0, seq=0, pid=0}}], iov_len=4096}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, MSG_PEEK) = 224 recvmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=112-&gt;12, msg_iov=[{iov_base=[{{len=224, type=0x10 /* NLMSG_??? */, flags=0, seq=2596996163, pid=18357}, "\1\2\0\0\23\0\2\0MAC80211_HWSIM\0\0\6\0\1\0\31\0\0\0"...}, {{len=0, type=0 /* NLMSG_??? */, flags=0, seq=0, pid=0}}], iov_len=4096}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 224 sendmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=12, msg_iov=[{iov_base={{len=28, type=0x19 /* NLMSG_??? */, flags=NLM_F_REQUEST|NLM_F_ACK, seq=2596996164, pid=18357}, "\6\1\0\0\10\0 \0T\0\0\0"}, iov_len=28}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 28 recvmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=112-&gt;12, msg_iov=[{iov_base=[{{len=48, type=0x19 /* NLMSG_??? */, flags=0, seq=2596996164, pid=18357}, "\6\1\0\0\10\0 \0T\0\0\0\10\0\t\0\1\0\0\0\t\0\21\0phy84\0\0\0"}, {{len=0, type=0 /* NLMSG_??? */, flags=0, seq=0, pid=0}}], iov_len=4096}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, MSG_PEEK) = 48 recvmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=112-&gt;12, msg_iov=[{iov_base=[{{len=48, type=0x19 /* NLMSG_??? */, flags=0, seq=2596996164, pid=18357}, "\6\1\0\0\10\0 \0T\0\0\0\10\0\t\0\1\0\0\0\t\0\21\0phy84\0\0\0"}, {{len=0, type=0 /* NLMSG_??? */, flags=0, seq=0, pid=0}}], iov_len=4096}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 48 sendmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=12, msg_iov=[{iov_base={{len=28, type=0x19 /* NLMSG_??? */, flags=NLM_F_REQUEST|NLM_F_ACK, seq=2596996165, pid=18357}, "\5\1\0\0\10\0 \0T\0\0\0"}, iov_len=28}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 28 recvmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=112-&gt;12, msg_iov=[{iov_base=[{{len=36, type=NLMSG_ERROR, flags=0, seq=2596996164, pid=18357}, "\0\0\0\0\34\0\0\0\31\0\5\0D\4\313\232\265G\0\0"}, {{len=0, type=0 /* NLMSG_??? */, flags=0, seq=0, pid=0}}], iov_len=4096}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, MSG_PEEK) = 36 recvmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=112-&gt;12, msg_iov=[{iov_base=[{{len=36, type=NLMSG_ERROR, flags=0, seq=2596996164, pid=18357}, "\0\0\0\0\34\0\0\0\31\0\5\0D\4\313\232\265G\0\0"}, {{len=0, type=0 /* NLMSG_??? */, flags=0, seq=0, pid=0}}], iov_len=4096}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 36 close(3) = 0 +++ exited with 0 +++ </code></pre> <p>Note that there are two <code>recvmsg()</code> calls for each <code>sendmsg()</code> because the first one simply does a <code>MSG_PEEK</code> to see if an answer is available. Of the three sets of requests and responses, the first (sequence ...163) is simply getting the family information. The second (sequence 164) is doing the <code>GET_RADIO</code> (<code>\6</code>) call, and the third is the one with the out-of-sequence response: this <code>DEL_RADIO</code> (<code>\5</code>) call sends a message with a ...165 sequence number, but the response that comes back, otherwise well-formed, has a sequence number matching the previous command: ...164.</p> <p>Because this is Go, there are multiple threads active at once, but all the calls in the strace output above are from the same thread. The only calls missing from the trace are those to <code>futex()</code>.</p> <p>The C version, because it uses the callback mechanisms provided by <code>libnl</code> and <code>libgenl</code>, does process the response in a different thread than the request came from. The request trace:</p> <pre><code>socket(AF_NETLINK, SOCK_RAW|SOCK_CLOEXEC, NETLINK_GENERIC) = 3 setsockopt(3, SOL_SOCKET, SO_SNDBUF, [32768], 4) = 0 setsockopt(3, SOL_SOCKET, SO_RCVBUF, [32768], 4) = 0 getpid() = 21338 bind(3, {sa_family=AF_NETLINK, nl_pid=-1300212902, nl_groups=00000000}, 12) = 0 getsockname(3, {sa_family=AF_NETLINK, nl_pid=-1300212902, nl_groups=00000000}, [12]) = 0 sendmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=12, msg_iov=[{iov_base={{len=20, type=0x10 /* NLMSG_??? */, flags=NLM_F_REQUEST|NLM_F_ACK|0x300, seq=1530817156, pid=2994754394}, "\3\1\0\0"}, iov_len=20}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 20 recvmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=12, msg_iov=[{iov_base=[{{len=116, type=0x10 /* NLMSG_??? */, flags=NLM_F_MULTI, seq=1530817156, pid=2994754394}, "\1\2\0\0\v\0\2\0nlctrl\0\0\6\0\1\0\20\0\0\0\10\0\3\0\2\0\0\0"...}, {{len=96, type=0x10 /* NLMSG_??? */, flags=NLM_F_MULTI, seq=1530817156, pid=2994754394}, "\1\2\0\0\16\0\2\0VFS_DQUOT\0\0\0\6\0\1\0\21\0\0\0\10\0\3\0"...}, {{len=104, type=0x10 /* NLMSG_??? */, flags=NLM_F_MULTI, seq=1530817156, pid=2994754394}, "\1\2\0\0\17\0\2\0acpi_event\0\0\6\0\1\0\23\0\0\0\10\0\3\0"...}, {{len=108, type=0x10 /* NLMSG_??? */, flags=NLM_F_MULTI, seq=1530817156, pid=2994754394}, "\1\2\0\0\22\0\2\0thermal_event\0\0\0\6\0\1\0\24\0\0\0"...}, {{len=112, type=0x10 /* NLMSG_??? */, flags=NLM_F_MULTI, seq=1530817156, pid=2994754394}, "\1\2\0\0\20\0\2\0tcp_metrics\0\6\0\1\0\25\0\0\0\10\0\3\0"...}, {{len=112, type=0x10 /* NLMSG_??? */, flags=NLM_F_MULTI, seq=1530817156, pid=2994754394}, "\1\2\0\0\16\0\2\0TASKSTATS\0\0\0\6\0\1\0\26\0\0\0\10\0\3\0"...}, {{len=2076, type=0x10 /* NLMSG_??? */, flags=NLM_F_MULTI, seq=1530817156, pid=2994754394}, "\1\2\0\0\f\0\2\0nl80211\0\6\0\1\0\30\0\0\0\10\0\3\0\1\0\0\0"...}, {{len=224, type=0x10 /* NLMSG_??? */, flags=NLM_F_MULTI, seq=1530817156, pid=2994754394}, "\1\2\0\0\23\0\2\0MAC80211_HWSIM\0\0\6\0\1\0\31\0\0\0"...}, {{len=0, type=0 /* NLMSG_??? */, flags=0, seq=0, pid=0}}], iov_len=16384}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 2948 recvmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=12, msg_iov=[{iov_base=[{{len=20, type=NLMSG_DONE, flags=NLM_F_MULTI, seq=1530817156, pid=2994754394}, "\0\0\0\0"}, {{len=0, type=0 /* NLMSG_??? */, flags=0, seq=0, pid=65542}}], iov_len=16384}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 20 mmap(NULL, 8392704, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7fdb752ce000 mprotect(0x7fdb752ce000, 4096, PROT_NONE) = 0 clone(child_stack=0x7fdb75acdff0, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7fdb75ace9d0, tls=0x7fdb75ace700, child_tidptr=0x7fdb75ace9d0) = 21339 sendmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=12, msg_iov=[{iov_base={{len=28, type=0x19 /* NLMSG_??? */, flags=NLM_F_REQUEST|NLM_F_ACK, seq=1530817157, pid=2994754394}, "\6\1\0\0\10\0 \0_\0\0\0"}, iov_len=28}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 28 nanosleep({tv_sec=2, tv_nsec=0}, 0x7ffff64ac200) = 0 write(1, "Deleting radio with id '95'... ", 31) = 31 sendmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=12, msg_iov=[{iov_base={{len=28, type=0x19 /* NLMSG_??? */, flags=NLM_F_REQUEST|NLM_F_ACK, seq=1530817158, pid=2994754394}, "\5\1\0\0\10\0 \0_\0\0\0"}, iov_len=28}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 28 nanosleep({tv_sec=2, tv_nsec=0}, &lt;unfinished ...&gt;) = ? +++ exited with 0 +++ </code></pre> <p>and the response trace:</p> <pre><code>recvmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=12, msg_iov=[{iov_base=[{{len=48, type=0x19 /* NLMSG_??? */, flags=0, seq=1530817157, pid=2994754394}, "\6\1\0\0\10\0 \0_\0\0\0\10\0\t\0\1\0\0\0\t\0\21\0phy95\0\0\0"}, {{len=0, type=0 /* NLMSG_??? */, flags=0, seq=0, pid=0}}], iov_len=16384}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 48 epoll_wait(4, [{EPOLLIN, {u32=3, u64=3}}], 32, -1) = 1 recvmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=12, msg_iov=[{iov_base=[{{len=36, type=NLMSG_ERROR, flags=0, seq=1530817157, pid=2994754394}, "\0\0\0\0\34\0\0\0\31\0\5\0\205j&gt;[ZS\200\262"}, {{len=1114121, type=0x6870 /* NLMSG_??? */, flags=NLM_F_REQUEST|NLM_F_ECHO|NLM_F_DUMP_INTR|NLM_F_DUMP_FILTERED|0x3940, seq=53, pid=0}, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"...}], iov_len=16384}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 36 fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0 write(1, "new SSID defined to interface 95"..., 33) = 33 epoll_wait(4, [{EPOLLIN, {u32=3, u64=3}}], 32, -1) = 1 recvmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=12, msg_iov=[{iov_base=[{{len=36, type=NLMSG_ERROR, flags=0, seq=1530817158, pid=2994754394}, "\0\0\0\0\34\0\0\0\31\0\5\0\206j&gt;[ZS\200\262"}, {{len=1114121, type=0x6870 /* NLMSG_??? */, flags=NLM_F_REQUEST|NLM_F_ECHO|NLM_F_DUMP_INTR|NLM_F_DUMP_FILTERED|0x3940, seq=53, pid=0}, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"...}], iov_len=16384}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 36 write(1, "Successfully deleted device with"..., 39) = 39 exit_group(0) = ? +++ exited with 0 +++ </code></pre> <p>The only thing that seems relevant to me (other than the threading structure) is that it uses different flags (<code>NLM_F_DUMP_INTR|NLM_F_DUMP_FILTERED</code> in the C code, <code>0</code> in the Go code).</p> <p>I'm not sure what other tools I can bring to bear on this, since I don't know how those sequence numbers are constructed. There didn't seem to me to be anything unusually wrong with the code in the kernel module, in the Go packages, or in my Go code, but there could always be a mismatch between the way an interface was supposed to be used and the way it actually was. Does this problem seem familiar to anyone, or does anyone have any thoughts on how to make progress on this?</p> </div>

如何从strace输出中解码此信息

<div class="post-text" itemprop="text"> <p>I wrote a small go script and traced it using strace though this script, I am trying to fetch audit messages from kernel using netlink protocol, just like like auditd. </p> <p>Following is the strace output on my go script- <a href="http://paste.ubuntu.com/8272760/" rel="noreferrer">http://paste.ubuntu.com/8272760/</a></p> <p>I am trying to find the argument that auditd provide to the sendto function. When I run strace on auditd I get following output</p> <pre><code>sendto(3, "\20\0\0\0\350\3\5\0\1\0\0\0\0\0\0\0", 16, 0, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 16 </code></pre> <p>And when I strace my go file I get the following output. I am looking to decode the second argument of this statement</p> <pre><code>sendto(3, "\21\0\0\0\350\3\5\0\1\0\0\0\0\0\0\0\t", 17, 0, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 17 </code></pre> <p>To be specific</p> <pre><code>"\21\0\0\0\350\3\5\0\1\0\0\0\0\0\0\0\t" </code></pre> <p>Now I want to convert this to string or bytes array, is there any way to convert this to string or byte array? </p> <p>In my actual go code this argument is a byte array. </p> <p><a href="https://github.com/mozilla/Audit-Go/blob/testing/netlink_old.go#L58" rel="noreferrer">https://github.com/mozilla/Audit-Go/blob/testing/netlink_old.go#L58</a></p> </div>

在导入包中定义struct时如何使用go接收器

<div class="post-text" itemprop="text"> <p>currently working with the <code>vishvananda/netns</code> package trying to extract routes from a specific network namespace. </p> <p>There is a defined <code>Handle</code> struct which is returned when I request a 'handle' for a specific network namespace. As such:</p> <p><code>func NewHandleAt(ns netns.NsHandle, nlFamilies ...int) (*Handle, error)</code></p> <p>This is then a receiver argument (?) to a function that requires that handle,</p> <p><code>func (h *Handle) LinkList() ([]Link, error)</code> </p> <p>I'm new to go and not sure how to tie these together. I'm stuck with:</p> <pre><code>func (h *Handle) showInts() { int, err := h.netlink.LinkList() if err != nil { log.Fatal(err) } for i, r := range int { log.Printf("%d: %s", i, r.Attrs().Name) } } func main() { ints, err := netlink.LinkList() if err != nil { log.Fatal(err) } for i, r := range ints { log.Printf("%d: %s", i, r.Attrs().Name) } pid, err := netns.GetFromPid(9097) if err != nil { log.Fatal(err) } netlink.NewHandleAt(pid) showInts() } </code></pre> </div>

openssl交叉编译,hostapd移植出错,求帮助

hostapd编译的错误信息: CC ../src/drivers/driver_common.c /usr/bin/ld: /opt/wifi/tool/openssl/lib/libcrypto.a(ex_data.o): Relocations in generic ELF (EM: 40) /usr/bin/ld: /opt/wifi/tool/openssl/lib/libcrypto.a(ex_data.o): Relocations in generic ELF (EM: 40) /opt/wifi/tool/openssl/lib/libcrypto.a: could not read symbols: File in wrong format collect2: ld 返回 1 make: *** [hostapd] 错误 1 我的移植是参考 http://blog.csdn.net/hinyunsin/article/details/6029749 文章来做的,移植openssl时我的步骤是: $./config no-asm shared --prefix=/opt/wifi/tool/openssl/ makefile修改如下: 12 ##CC= gcc 13 CC= arm-none-linux-gnueabi-gcc 14 #CFLAG= -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -Wall 15 CFLAG= -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DOPENSSL_NO_KRB5 -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -Wall 16 DEPFLAG= -DOPENSSL_NO_CAMELLIA -DOPENSSL_NO_GMP -DOPENSSL_NO_MDC2 -DOPENSSL_NO_RC5 -DOPENSSL_NO_RFC3779 -DOPENSSL_NO_SEED -DOPENSSL_NO_TLSEXT 17 PEX_LIBS= 18 EX_LIBS= -ldl 19 EXE_EXT= 20 ARFLAGS= 21 AR=arm-none-linux-gnueabi-ar $(ARFLAGS) r 22 RANLIB= arm-none-linux-gnueabi-ranlib 23 PERL= /usr/bin/perl 24 TAR= tar 25 TARFLAGS= --no-recursion 26 MAKEDEPPROG= gcc $make ,$make install成功 在hostapd目录我makefile添加: 3 ##CC=gcc 4 CC=arm-none-linux-gnueabi-gcc #################################################add CFLAGS += -I/opt/wifi/tool/libnl/include/ CFLAGS += -I/opt/wifi/tool/openssl/include/ ####################################add LIBS += -L/opt/wifi/tool/libnl/lib/ LIBS += -L/opt/wifi/tool/openssl/lib/libssl.a /opt/wifi/tool/openssl/lib/libcrypto.a make产生如下错误 错误信息 CC ../src/drivers/driver_common.c /usr/bin/ld: /opt/wifi/tool/openssl/lib/libcrypto.a(ex_data.o): Relocations in generic ELF (EM: 40) /usr/bin/ld: /opt/wifi/tool/openssl/lib/libcrypto.a(ex_data.o): Relocations in generic ELF (EM: 40) /opt/wifi/tool/openssl/lib/libcrypto.a: could not read symbols: File in wrong format collect2: ld 返回 1 make: *** [hostapd] 错误 1 试过make clean -w ;make -w仍然不行 求助

大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了

大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

你以为这样写Java代码很6,但我看不懂

为了提高 Java 编程的技艺,我最近在 GitHub 上学习一些高手编写的代码。下面这一行代码(出自大牛之手)据说可以征服你的朋友,让他们觉得你写的代码很 6,来欣赏一下吧。 IntStream.range(1, 5).boxed().map(i -&gt; { System.out.print("Happy Birthday "); if (i == 3) return "dear NAME"...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

程序员写出这样的代码,能不挨骂吗?

当你换槽填坑时,面对一个新的环境。能够快速熟练,上手实现业务需求是关键。但是,哪些因素会影响你快速上手呢?是原有代码写的不够好?还是注释写的不够好?昨夜...

带了6个月的徒弟当了面试官,而身为高级工程师的我天天修Bug......

即将毕业的应届毕业生一枚,现在只拿到了两家offer,但最近听到一些消息,其中一个offer,我这个组据说客户很少,很有可能整组被裁掉。 想问大家: 如果我刚入职这个组就被裁了怎么办呢? 大家都是什么时候知道自己要被裁了的? 面试软技能指导: BQ/Project/Resume 试听内容: 除了刷题,还有哪些技能是拿到offer不可或缺的要素 如何提升面试软实力:简历, 行为面试,沟通能...

优雅的替换if-else语句

场景 日常开发,if-else语句写的不少吧??当逻辑分支非常多的时候,if-else套了一层又一层,虽然业务功能倒是实现了,但是看起来是真的很不优雅,尤其是对于我这种有强迫症的程序"猿",看到这么多if-else,脑袋瓜子就嗡嗡的,总想着解锁新姿势:干掉过多的if-else!!!本文将介绍三板斧手段: 优先判断条件,条件不满足的,逻辑及时中断返回; 采用策略模式+工厂模式; 结合注解,锦...

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

2020阿里全球数学大赛:3万名高手、4道题、2天2夜未交卷

阿里巴巴全球数学竞赛( Alibaba Global Mathematics Competition)由马云发起,由中国科学技术协会、阿里巴巴基金会、阿里巴巴达摩院共同举办。大赛不设报名门槛,全世界爱好数学的人都可参与,不论是否出身数学专业、是否投身数学研究。 2020年阿里巴巴达摩院邀请北京大学、剑桥大学、浙江大学等高校的顶尖数学教师组建了出题组。中科院院士、美国艺术与科学院院士、北京国际数学...

为什么你不想学习?只想玩?人是如何一步一步废掉的

不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

程序员为什么千万不要瞎努力?

本文作者用对比非常鲜明的两个开发团队的故事,讲解了敏捷开发之道 —— 如果你的团队缺乏统一标准的环境,那么即使勤劳努力,不仅会极其耗时而且成果甚微,使用...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

Python爬虫,高清美图我全都要(彼岸桌面壁纸)

爬取彼岸桌面网站较为简单,用到了requests、lxml、Beautiful Soup4

无代码时代来临,程序员如何保住饭碗?

编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

Java岗开发3年,公司临时抽查算法,离职后这几题我记一辈子

前几天我们公司做了一件蠢事,非常非常愚蠢的事情。我原以为从学校出来之后,除了找工作有测试外,不会有任何与考试有关的事儿。 但是,天有不测风云,公司技术总监、人事总监两位大佬突然降临到我们事业线,叫上我老大,给我们组织了一场别开生面的“考试”。 那是一个风和日丽的下午,我翘着二郎腿,左手端着一杯卡布奇诺,右手抓着我的罗技鼠标,滚动着轮轴,穿梭在头条热点之间。 “淡黄的长裙~蓬松的头发...

大牛都会用的IDEA调试技巧!!!

导读 前天面试了一个985高校的实习生,问了他平时用什么开发工具,他想也没想的说IDEA,于是我抛砖引玉的问了一下IDEA的调试用过吧,你说说怎么设置断点...

面试官:你连SSO都不懂,就别来面试了

大厂竟然要考我SSO,卧槽。

立即提问
相关内容推荐