From 80776aec8147d643ca8aaa99f7320c7f22a70677 Mon Sep 17 00:00:00 2001 From: Mark Stapp Date: Wed, 14 Nov 2018 14:45:30 -0500 Subject: [PATCH] zebra: add dataplane routing socket To avoid conflicts between the zebra main pthread and the dataplane pthread, use a separate routing socket (on non-netlink platforms) for dataplane route updates to the OS. Signed-off-by: Mark Stapp --- zebra/kernel_socket.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index ff739ae79b..dcc22d2162 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -278,6 +278,11 @@ static const struct message rtm_flag_str[] = {{RTF_UP, "UP"}, /* Kernel routing update socket. */ int routing_sock = -1; +/* Kernel dataplane routing update socket, used in the dataplane pthread + * context. + */ +int dplane_routing_sock = -1; + /* Yes I'm checking ugly routing socket behavior. */ /* #define DEBUG */ @@ -1136,7 +1141,7 @@ int rtm_write(int message, union sockunion *dest, union sockunion *mask, char buf[512]; } msg; - if (routing_sock < 0) + if (dplane_routing_sock < 0) return ZEBRA_ERR_EPERM; /* Clear and set rt_msghdr values */ @@ -1243,7 +1248,7 @@ int rtm_write(int message, union sockunion *dest, union sockunion *mask, msg.rtm.rtm_msglen = pnt - (caddr_t)&msg; - ret = write(routing_sock, &msg, msg.rtm.rtm_msglen); + ret = write(dplane_routing_sock, &msg, msg.rtm.rtm_msglen); if (ret != msg.rtm.rtm_msglen) { if (errno == EEXIST) @@ -1390,6 +1395,9 @@ static void routing_socket(struct zebra_ns *zns) { frr_elevate_privs(&zserv_privs) { routing_sock = ns_socket(AF_ROUTE, SOCK_RAW, 0, zns->ns_id); + + dplane_routing_sock = + ns_socket(AF_ROUTE, SOCK_RAW, 0, zns->ns_id); } if (routing_sock < 0) { @@ -1397,6 +1405,12 @@ static void routing_socket(struct zebra_ns *zns) return; } + if (dplane_routing_sock < 0) { + flog_err_sys(EC_LIB_SOCKET, + "Can't init kernel dataplane routing socket"); + return; + } + /* XXX: Socket should be NONBLOCK, however as we currently * discard failed writes, this will lead to inconsistencies. * For now, socket must be blocking. -- 2.39.5