summaryrefslogtreecommitdiff
path: root/zebra/rt_netlink.c
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2008-08-16 18:25:47 +0100
committerPaul Jakma <paul@quagga.net>2008-08-22 19:56:25 +0100
commit30afea3b584515ba19b38fcde6f562a550c1fcab (patch)
treef39773af1c2c29518fbbc222f2dd4948be2484ef /zebra/rt_netlink.c
parentcadfb2cd81528fc6f85af24dbf0ff3fd0ff63e6b (diff)
[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>
Diffstat (limited to 'zebra/rt_netlink.c')
-rw-r--r--zebra/rt_netlink.c86
1 files changed, 43 insertions, 43 deletions
diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c
index fe55d43e..a0dad997 100644
--- a/zebra/rt_netlink.c
+++ b/zebra/rt_netlink.c
@@ -112,6 +112,45 @@ set_ifindex(struct interface *ifp, unsigned int ifi_index)
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 @@ netlink_socket (struct nlsock *nl, unsigned long groups)
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 @@ kernel_init (void)
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);
}