netlink

Netlink sockets and libnl - nl_recvmsgs_default returning -16 (EBUSY)

一世执手 提交于 2019-12-11 02:48:01
问题 I'm trying to code some basic kernel module - userspace program communication using netlink sockets (libnl on user side). Userspace program sends a message to kernel and expects a reply. Unfortunately, receiving reply fails with return value -16 (EBUSY). Interestingly enough, when I receive data from netlink socket directly, using standard system call recv on nl_socket_get_fd(sock) , everything works fine! Does anyone have an idea why this is happening? Here is the userspace code (parse_cb is

Linux carrier detection notification

笑着哭i 提交于 2019-12-10 23:19:50
问题 Is there an interface in Linux to get notification of a network interface carrier change? I know its possible to poll an interface with SIOCETHTOOL, but was wondering if there was any way to get notified or any blocking calls that would return on carrier detection changes? 回答1: Do you need carrier transition or interface state change? For the interface state you could listen to the NETLINK_ROUTE netlink socket and wait for RTM_NEWLINK and RTM_DELLINK messages 来源: https://stackoverflow.com

Listening for netlink broadcasts in a kernel module

℡╲_俬逩灬. 提交于 2019-12-10 17:47:58
问题 The SELinux module sends out a netlink broadcast to any listening sockets. I'm wondering if it's possible to listen for netlink broadcast from within another kernel module? From SELinux netlink code: netlink_broadcast(selnl, skb, 0, SELNLGRP_AVC, GFP_USER); 回答1: I found that you can listen for netlink data through the use of regular sockets. And, yes, it's possible in kernel-space. You basically need to create and bind to a socket: struct sock *sock = NULL; struct sockaddr_nl addr = { 0 }; /*

Netlink implementation for the Android NDK

╄→尐↘猪︶ㄣ 提交于 2019-12-10 11:36:28
问题 I have a requirement for similar task as mentioned in this link.. Passive monitoring of sockets in Android. One way is parsing the /proc/net/{tcp,udp,...} tables. But we have to keep on reading continuously for keep on monitoring; which is not efficient way. As it will be a mobile device app, it will eat up the battery as it requires CPU Time for keep on monitoring for time interval (say 1 sec). But, I am looking for an event based approach. As I googled about the same, I ended with NETLINK

kernel-space user-space communication with netlink

大城市里の小女人 提交于 2019-12-08 05:31:57
问题 My objective is to have an array or list in kernel memory at all times, so that it is always accessible from kernel-space. To do this, I am using netlink sockets as recommended here. I follow this example, which shows how to send a string. I am not sure as to how to send an array of struct or list of structs in sockets. typedef struct { int fiveDollarBills; int denDollarBills; } Bills; Is it possible to send a list or array using netlink? 回答1: NetLink itself doesn't care whether the data is a

Get all link and address information when listenning to a PF_NETLINK socket

青春壹個敷衍的年華 提交于 2019-12-07 10:40:43
问题 I've written a peace of code that notifies me whenever relevant (to me) networking information changes (mainly listenning to RTM_NEWADDR, RTM_DELADDR, RTM_NEWLINK and RTM_DELLINK. this works pretty fine, each time I unplug, change ip or whatsoever I get notified. only problem, is the first time I launch my code, I would like it to give me the whole current status (RTM_GETLINK and RTM_GETADDR). I am able to request either RTM_GETLINK or RTM_GETADDR: memset(&req, 0, sizeof(req)); req.nlmsghdr

How to decode this information from strace output

我是研究僧i 提交于 2019-12-07 01:47:22
问题 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. Following is the strace output on my go script- http://paste.ubuntu.com/8272760/ I am trying to find the argument that auditd provide to the sendto function. When I run strace on auditd I get following output 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 And

Generic Netlink

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 16:47:47
Netlink主要是基于linux 内核接口提供的网络接口操作。Netlink是一种内核与用户空间通信的IPC机制,主要是网络相关操作提供相应的接口。本文主要介绍如何使用Generic Netlink接口,Generic Netlink是netlink的一个扩展版本。 来源: https://www.cnblogs.com/rykang/p/11934349.html

Get all link and address information when listenning to a PF_NETLINK socket

淺唱寂寞╮ 提交于 2019-12-05 12:36:10
I've written a peace of code that notifies me whenever relevant (to me) networking information changes (mainly listenning to RTM_NEWADDR, RTM_DELADDR, RTM_NEWLINK and RTM_DELLINK. this works pretty fine, each time I unplug, change ip or whatsoever I get notified. only problem, is the first time I launch my code, I would like it to give me the whole current status (RTM_GETLINK and RTM_GETADDR). I am able to request either RTM_GETLINK or RTM_GETADDR: memset(&req, 0, sizeof(req)); req.nlmsghdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtgenmsg)); req.nlmsghdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP

How to decode this information from strace output

随声附和 提交于 2019-12-05 06:21:38
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. Following is the strace output on my go script- http://paste.ubuntu.com/8272760/ I am trying to find the argument that auditd provide to the sendto function. When I run strace on auditd I get following output 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 And when I strace my go file I get the following output. I am looking to decode the second argument of this