Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

this time really increase netlink socket buffer size (refs: #1011)

and handle enobufs UDP errors

The problem was that gen_udp did reset the bufsize to 8k,
so by first passing the FDs to gen_udp and the setting
the bufsize we can work arround that.
  • Loading branch information...
commit 86eb68b3c1abc31e419b2f758040fd6f9dfc0859 1 parent ce0b96a
@RoadRunnr RoadRunnr authored
Showing with 9 additions and 5 deletions.
  1. +9 −5 src/netlink.erl
View
14 src/netlink.erl
@@ -1255,6 +1255,9 @@ init(_Args) ->
{ok, CtNl} = gen_socket:socket(netlink, raw, ?NETLINK_NETFILTER),
ok = gen_socket:bind(CtNl, sockaddr_nl(netlink, 0, -1)),
+ %% UDP is close enough (connection less, datagram oriented), so we can use the driver from it
+ {ok, Ct} = gen_udp:open(0, [binary, {fd, CtNl}, {read_packets, 16 * 1024}]),
+
ok = gen_socket:setsockoption(CtNl, sol_socket, so_sndbuf, 32768),
ok = rcvbufsiz(CtNl, 128 * 1024),
@@ -1265,12 +1268,12 @@ init(_Args) ->
ok = setsockoption(CtNl, sol_netlink, netlink_add_membership, nfnlgrp_conntrack_exp_update),
ok = setsockoption(CtNl, sol_netlink, netlink_add_membership, nfnlgrp_conntrack_exp_destroy),
- %% UDP is close enough (connection less, datagram oriented), so we can use the driver from it
- {ok, Ct} = gen_udp:open(0, [binary, {fd, CtNl}, {read_packets, 1024}]),
-
{ok, RtNl} = gen_socket:socket(netlink, raw, ?NETLINK_ROUTE),
ok = gen_socket:bind(RtNl, sockaddr_nl(netlink, 0, -1)),
+ %% UDP is close enough (connection less, datagram oriented), so we can use the driver from it
+ {ok, Rt} = gen_udp:open(0, [binary, {fd, RtNl}, {read_packets, 16 * 1024}]),
+
ok = gen_socket:setsockoption(RtNl, sol_socket, so_sndbuf, 32768),
ok = rcvbufsiz(RtNl, 128 * 1024),
@@ -1279,8 +1282,6 @@ init(_Args) ->
ok = setsockoption(RtNl, sol_netlink, netlink_add_membership, rtnlgrp_ipv4_ifaddr),
ok = setsockoption(RtNl, sol_netlink, netlink_add_membership, rtnlgrp_ipv4_route),
- %% UDP is close enough (connection less, datagram oriented), so we can use the driver from it
- {ok, Rt} = gen_udp:open(0, [binary, {fd, RtNl}, {read_packets, 1024}]),
{ok, #state{
ct = Ct, rt = Rt,
@@ -1365,6 +1366,9 @@ handle_info({udp, S, _IP, _Port, _Data}, #state{subscribers = Sub} = State) ->
spawn(?MODULE, notify, [s, Subs, S]),
{noreply, State};
+handle_info({udp_error, _, enobufs}, State) ->
+ {noreply, State};
+
handle_info({'DOWN', _Ref, process, Pid, _Reason}, #state{subscribers = Sub} = State) ->
io:format("~p:Unsubscribe ~p~n", [?MODULE, Pid]),
{noreply, State#state{subscribers = lists:delete(Pid, Sub)}};
Please sign in to comment.
Something went wrong with that request. Please try again.