Erlang: Create a netlink socket, bind to it, send a multicast message and receive a response

Papa Tana papa.tana101@REDACTED
Thu Aug 27 10:12:54 CEST 2020


Hi All,

I'm still trying to speak netlink with the linux GTP Module using Erlang:

Here is my scenario:

%% load the gtp.ko module manually
> modprobe gtp

%% at userspace, create a netlink socket, and bind to it

> {ok, Fd} = procket:open(0, [{family, netlink}, {protocol, 0}, {type,
dgram}]).
> Port = erlang:open_port({fd, Fd, Fd}, [binary]).

%% Now, I assume that I need to send a multicast message and receive some
response
%% I assume it would be something like this:

erlang:port_command(Port, <<some_binary_format>>).
flush().

%% Of course, I don't get any response because I'm sending bad message.
I have debug some successful library written in C how he did it.

Exemple of strace of libgtpnl to Linux GTP module:

> strace -s 100 -f -o out -x ./gtp-link add gtp1

> bind(5, {sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, 12) = 0
> getsockname(5, {sa_family=AF_NETLINK, nl_pid=2966, nl_groups=00000000},
[12]) = 0
> sendto(5, {{len=80, type=0x10 /* NLMSG_??? */,
flags=NLM_F_REQUEST|NLM_F_ACK|0x600, seq=1598219164, pid=0},
"\x02\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x08\x00\x03\x00\x67\x74\x70\x31\x28\x00\x12\x80\x07\x00\x01\x00\x67\x74\x70\x00\x1c\x00\x02\x80\x08\x00\x01\x00\x03\x00\x00\x00\x08\x00\x02\x00\x04\x00\x00\x00\x08\x00\x03\x00\x00\x00\x02\x00"},
80, 0, {sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, 12) = 80
> recvmsg(5, {msg_name={sa_family=AF_NETLINK, nl_pid=0,
nl_groups=00000000}, msg_namelen=12, msg_iov=[{iov_base=[{{len=36,
type=NLMSG_SUCCESS, flags=0, seq=1598219164, pid=2966},
"\x00\x00\x00\x00\x50\x00\x00\x00\x10\x00\x05\x06\x9c\xe3\x42\x5f\x00\x00\x00\x00"},
{{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(5)                                = 0
> write(2, "WARNING: attaching dummy socket...

As per my understanding:

    - Header would be: Length=80, type=16, flags=1536, sequence
number=1598219164, pid=0
    - nl_pid = 0, nl_groups = 0

Well, but I'm stuck:

    1/ Do anyone know how to send such a message using Erlang?
    2/ I have tried https://github.com/msantos/procket, my netlink socket
seems ok as above, but the next step, I'm lagging
    3/ I have take a look at https://github.com/travelping/gen_netlink as
well, but first, when I tried to install tetrapak (make, make install), I
got a lot of error so I cannot even install tetrapak on my machine.
    And even if tetrapak would be installed, it will be the same as 2/, I
don't find any working example even in https://learnyousomeerlang.com/ on
how to successfully speak netlink using Erlang.

Any hint?
Best Regards,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20200827/4d24bb23/attachment.htm>


More information about the erlang-questions mailing list