Network connectors

I've worked with network programming before. But this is my first foray into netlink sockets.

I decided to look into the type of netconnect connectors. As with any kernel component, it also has a custom counterpart. There is a sample program in the linux kernel called ucon.c that can be used to create user-space programs based on the aforementioned socket sockets.

So, here I want to highlight the points of the program that I want to confirm with my understanding and parts of the program that I do not follow the logic. Stop talking. Like this. Please correct me wherever I go astray.

As far as I understood, network sockets are an IPC method used to connect processes on the same computer and hence the process ID is used as an ID. And since netlink messages can be perfectly multicast, another identifier that a network socket needs is a message group. All components that are associated with the same message group are actually associated. Thus, while in the case of IPv4 we use sockaddr_in instead of sockaddr, here we use sockaddr_nl, which contains the aforementioned IDs.

Now, since we are not going to use the core TCP / IP stack, in the case of netlink messages, netlink packets can be considered raw (please correct me here if I am wrong). Therefore, the only encapsulation a netlink packet goes through is the netlink message header, defined as nlmsghdr .

Now, starting our ucon program, it main()

will first create a NETLINK socket with a connector protocol. It then populates the above socketaddress netlink structure with the appropriate information. To be a little experimental here, I've added an entry in the connector.h file. Now here's my first question.

The connector message is of a specific type, defined in connector .h. Now this connector message structure is what is completely internal to netlink? As with netlink, this is just a payload. Right?

Moving around, what exactly does the nl-group field mean in the netlink message header structure? There is really no element of this name in the definition. So are we using overlay techniques to populate specific header fields of the netlink message? And if so, what is correspondence? I can't seem to find anything.

So after binding the socket address to the socket, it sends 10,000 unique pieces of data based on connectors, which is a pure payload as far as netlink is concerned. But what's strange is how concerned these messages are that they all have the same sequence number.

Moving on, we end up in the netlink_send subroutine to send these packets over the socket we linked to above. This subroutine uses various netlink macros to control the transmitted data. As we said above, the function main()

sends 10,000 chunks of data, each of which is zero in length and does not require confirmation, since the ack field is 0 (please correct me if I'm wrong here). Thus, each "packet" is nothing more than the header of the connecting message without anything in it. Right?

Now, surprisingly, the netlink_Send function uses the same sequence number as main (), since it is a global variable. However, after incrementing in main (), it is now "1". So basically our conversation with netlink starts with the serial number "1". This is normal?

By examining some of the helper macros defined in linux / netlink.h, I will try to summarize my understanding of those used directly or indirectly in this program.

#define NLMSG_LENGTH(len) ((len)+NLMSG_ALIGN(NLMSG_HDRLEN))

      

So this macro first flattens the length of the netlink message header and then adds the payload length to it. For our case, the netlink payload is a connector header without any payload. In our case, this micro is used like this

nlh->nlmsg_len = NLMSG_LENGTH(size - sizeof(*nlh));

      

Here what I don't understand is the actual payload of the netlink post. In the above case, it is the size of the connector message header (since the connecting text itself does not contain any payload) minus the pointer (which points to the first byte of the netlink message and hence the header of the netlink message). And this pointer (like any other pointer variable) is equal to the machine word size, which in my case is 4 bytes. Why are we subtracting this from the header of the connector message?

After that, we send the message over this network socket in the same way as any other IPv4 socket. I hope to hear from you, comrades, on the above questions. Including some suggestions before the real question helps as my post is quite long. But I hope that it will be useful for people more than for myself.

Sincerely.

+3


source to share





All Articles