[zebra:linux] netlink buffer size tweaking only needed on receive socket
2008-08-16 Stephen Hemminger <stephen.hemminger@vyatta.com>
* rt_netlink.c: (netlink_recvbuf) consolidate recvbuf setting
(netlink_socket) no need to set receive buffer on netlink sockets
generally
(kernel_init) set recvbuffer on the listen socket
Signed-off-by: Paul Jakma <paul@quagga.net>
diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c
index fe55d43..a0dad99 100644
--- a/zebra/rt_netlink.c
+++ b/zebra/rt_netlink.c
@@ -112,6 +112,45 @@
ifp->ifindex = ifi_index;
}
+static int
+netlink_recvbuf (struct nlsock *nl, uint32_t newsize)
+{
+ u_int32_t oldsize;
+ socklen_t newlen = sizeof(newsize);
+ socklen_t oldlen = sizeof(oldsize);
+ int ret;
+
+ ret = getsockopt(nl->sock, SOL_SOCKET, SO_RCVBUF, &oldsize, &oldlen);
+ if (ret < 0)
+ {
+ zlog (NULL, LOG_ERR, "Can't get %s receive buffer size: %s", nl->name,
+ safe_strerror (errno));
+ return -1;
+ }
+
+ ret = setsockopt(nl->sock, SOL_SOCKET, SO_RCVBUF, &nl_rcvbufsize,
+ sizeof(nl_rcvbufsize));
+ if (ret < 0)
+ {
+ zlog (NULL, LOG_ERR, "Can't set %s receive buffer size: %s", nl->name,
+ safe_strerror (errno));
+ return -1;
+ }
+
+ ret = getsockopt(nl->sock, SOL_SOCKET, SO_RCVBUF, &newsize, &newlen);
+ if (ret < 0)
+ {
+ zlog (NULL, LOG_ERR, "Can't get %s receive buffer size: %s", nl->name,
+ safe_strerror (errno));
+ return -1;
+ }
+
+ zlog (NULL, LOG_INFO,
+ "Setting netlink socket receive buffer size: %u -> %u",
+ oldsize, newsize);
+ return 0;
+}
+
/* Make socket for Linux netlink interface. */
static int
netlink_socket (struct nlsock *nl, unsigned long groups)
@@ -130,49 +169,6 @@
return -1;
}
-
- /* Set receive buffer size if it's set from command line */
- if (nl_rcvbufsize)
- {
- u_int32_t oldsize, oldlen;
- u_int32_t newsize, newlen;
-
- oldlen = sizeof(oldsize);
- newlen = sizeof(newsize);
-
- ret = getsockopt(sock, SOL_SOCKET, SO_RCVBUF, &oldsize, &oldlen);
- if (ret < 0)
- {
- zlog (NULL, LOG_ERR, "Can't get %s receive buffer size: %s", nl->name,
- safe_strerror (errno));
- close (sock);
- return -1;
- }
-
- ret = setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &nl_rcvbufsize,
- sizeof(nl_rcvbufsize));
- if (ret < 0)
- {
- zlog (NULL, LOG_ERR, "Can't set %s receive buffer size: %s", nl->name,
- safe_strerror (errno));
- close (sock);
- return -1;
- }
-
- ret = getsockopt(sock, SOL_SOCKET, SO_RCVBUF, &newsize, &newlen);
- if (ret < 0)
- {
- zlog (NULL, LOG_ERR, "Can't get %s receive buffer size: %s", nl->name,
- safe_strerror (errno));
- close (sock);
- return -1;
- }
-
- zlog (NULL, LOG_INFO,
- "Setting netlink socket receive buffer size: %u -> %u",
- oldsize, newsize);
- }
-
memset (&snl, 0, sizeof snl);
snl.nl_family = AF_NETLINK;
snl.nl_groups = groups;
@@ -1898,6 +1894,10 @@
zlog (NULL, LOG_ERR, "Can't set %s socket flags: %s", netlink.name,
safe_strerror (errno));
+ /* Set receive buffer size if it's set from command line */
+ if (nl_rcvbufsize)
+ netlink_recvbuf (&netlink, nl_rcvbufsize);
+
netlink_install_filter (netlink.sock, netlink_cmd.snl.nl_pid);
thread_add_read (zebrad.master, kernel_read, NULL, netlink.sock);
}