Questions tagged [netlink]

Netlink is a socket based inter process communication protocol for Linux systems. It is currently the preferred way, as of 2.6, of communicating with user space from the kernel.

337 questions
0
votes
2 answers

How to discover the network namespace an (RT)NETLINK socket connects to?

While playing around with the code below I noticed that a network namespace can be kept alive without neither a process attached to it nor any "direct" reference by an open file descriptor to the nsfs inode. How can I discover the network namespace…
TheDiveO
  • 2,183
  • 2
  • 19
  • 38
0
votes
0 answers

python: print a TLV value from packet as a string

I'm reading data over netlink socket. One of the TLVs contain IPv4 address as a sequence of 4 bytes, e.g. 0x01 0x02 0x03 0x0b for address 1.2.3.11 : import socket ... s = socket.socket(socket.AF_NETLINK, socket.SOCK_RAW,…
Mark
  • 6,052
  • 8
  • 61
  • 129
0
votes
0 answers

python: print a netlink message in hex

import os import socket import struct ... s = socket.socket(socket.AF_NETLINK, socket.SOCK_RAW, socket.NETLINK_ROUTE) s.bind((os.getpid(), RTMGRP_IPV4_IFADDR)) while True: data = s.recv(65535) msg_len, msg_type, flags, seq, pid =…
Mark
  • 6,052
  • 8
  • 61
  • 129
0
votes
0 answers

Rewrite attribute in - struct nl_msg - message (netlink, libnl)

The libnl library provides functions like nla_put_...(...) for adding attributes to a netlink message. Can I somehow rewrite certain attribute without recreating the whole message? Didn't found any interface function in libnl fot doing this. Thanks.
0
votes
1 answer

How can I receive RTM_NEWTFILTER, RTM_DELTFILTER messages via netlink?

I'm trying to get netlink notifications RTM_NEWTFILTER, RTM_DELTFILTER with next code: #include #include #include #include #include #include #include…
stanislav888
  • 374
  • 2
  • 9
0
votes
0 answers

Can the NETLINK/SOCK_DIAG interface be used to listen for `listen()` and `close()` events of said socket?

I've been gleaning information about the NETLINK socket which allows us to listen on what is happening in socket land. It seems to very partially work, but I'm wondering whether I missed something. I'm using C++, although of course all the NETLINK…
Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
0
votes
2 answers

why cant get the message response from kernel module when using netlink socket to communicate with python user

I'm using netlink socket to communicate user python code with linux kernel, i can send message properly from user to kernel but i cant get the response back from kernel. it shows: "Error while sending bak to user.." in my peice of kernel code I…
Meri
  • 1
0
votes
0 answers

How to Monitor for Input Device Addition and Removal with a Linux Netlink Socket

I want to be able to monitor for device removal and addition of input devices using linux netlink sockets. Scouring the web, I have found source code that reads a netlink socket message but does no parsing on its type or content and just prints a…
0
votes
0 answers

tcpdump triggers netlink IFF_RUNNING/link change

I have these 3 function to handle netlink events of interface up/down (init, receive_msg and handle_msg) When I do ifconfig eth0 down/up I see that the IFF_RUNNING flag is set/unset correctly ifconfig eth0 down: IFF_BROADCAST IFF_MULTICAST Link…
0
votes
1 answer

Where is the structure for payload of netlink message defined for NETLINK_XFRM socket

I am running strongswan daemon to perform IKEv2 messaging. I wrote some python code to be notified everytime any xfrm change happens. The socket is created like so: my_socket = socket.socket(socketAF_NETLINK, socket.SOCK_RAW, socket.NETLINK_XFRM) I…
Surajit
  • 5
  • 1
  • 6
0
votes
0 answers

Can't remove netlink kernel module while a userspace app is connected to it

I have a kernel module that communicates with userspace using Netlink, it looks like that Kernel Module #define NETLINK_USER 31 struct sock *nl_sk = NULL; int init_module() { struct netlink_kernel_cfg cfg = { .input = nl_recv_msg, }; …
Khaled Hamed
  • 85
  • 1
  • 3
  • 10
0
votes
1 answer

How to pickle/ serialize a swigpyobject?

I'm working on a application which connects with kernel module. for this communication i'm using netlink libnl3.5.0 in python which wraps "c" into py using swig. Problem is when I try do multiprocessing and trying to share the msg queue to different…
nopro
  • 7
  • 4
0
votes
1 answer

recvmsg with select on NETLINK socket

I am writing NETLINK xfrm socket programming to create association and policies for ESP communication. To send the data to kernel sockfd = socket(AF_NETLINK, SOCK_RAW|SOCK_CLOEXEC, NETLINK_XFRM); setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &sckbuff,…
soni
  • 77
  • 1
  • 9
0
votes
1 answer

Python3: how can we close netlink socket blocking recv?

I have the raw socket in Python as below to receive netlink messages from linux kernel. socket.socket(socket.AF_NETLINK, socket.SOCK_RAW, socket.NETLINK_ROUTE) I am doing blocking recv on this socket and want to close it from another Python thread.…
leopoodle
  • 2,110
  • 7
  • 24
  • 36
0
votes
1 answer

libnl: segfault when setting interface IPv6 address

I'm trying to set the IPv6 address of an interface, using libnl. Going through the documentation and other resources, this is basically what I'm trying to do: static int set_ipv6(const char *if_name, const char *ipv6) { struct rtnl_link *link =…