]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/kernel_socket.c
zebra: dup addr detect clear cmd non-zero return
[mirror_frr.git] / zebra / kernel_socket.c
index 5f4158e35ad46bd49404468732b17d74597c4f3f..dcc22d2162ff67cc28afe2577f2ef1b486e40514 100644 (file)
@@ -48,6 +48,7 @@
 #include "zebra/kernel_socket.h"
 #include "zebra/rib.h"
 #include "zebra/zebra_errors.h"
+#include "zebra/zebra_ptm.h"
 
 extern struct zebra_privs_t zserv_privs;
 
@@ -277,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 */
 
@@ -326,7 +332,7 @@ static int ifan_read(struct if_announcemsghdr *ifan)
                                __func__, ifan->ifan_index, ifan->ifan_name);
 
                /* Create Interface */
-               ifp = if_get_by_name(ifan->ifan_name, VRF_DEFAULT, 0);
+               ifp = if_get_by_name(ifan->ifan_name, VRF_DEFAULT);
                if_set_index(ifp, ifan->ifan_index);
 
                if_get_metric(ifp);
@@ -409,9 +415,9 @@ int ifm_read(struct if_msghdr *ifm)
 
        /* paranoia: sanity check structure */
        if (ifm->ifm_msglen < sizeof(struct if_msghdr)) {
-               flog_err(ZEBRA_ERR_NETLINK_LENGTH_ERROR,
-                         "ifm_read: ifm->ifm_msglen %d too short\n",
-                         ifm->ifm_msglen);
+               flog_err(EC_ZEBRA_NETLINK_LENGTH_ERROR,
+                        "ifm_read: ifm->ifm_msglen %d too short\n",
+                        ifm->ifm_msglen);
                return -1;
        }
 
@@ -469,7 +475,7 @@ int ifm_read(struct if_msghdr *ifm)
                if (ifnlen && (strncmp(ifp->name, ifname, IFNAMSIZ) != 0)) {
                        if (IS_ZEBRA_DEBUG_KERNEL)
                                zlog_debug(
-                                       "%s: ifp name %s doesnt match sdl name %s",
+                                       "%s: ifp name %s doesn't match sdl name %s",
                                        __func__, ifp->name, ifname);
                        ifp = NULL;
                }
@@ -728,7 +734,7 @@ int ifam_read(struct ifa_msghdr *ifam)
        ifam_read_mesg(ifam, &addr, &mask, &brd, ifname, &ifnlen);
 
        if ((ifp = if_lookup_by_index(ifam->ifam_index, VRF_DEFAULT)) == NULL) {
-               flog_warn(ZEBRA_ERR_UNKNOWN_INTERFACE,
+               flog_warn(EC_ZEBRA_UNKNOWN_INTERFACE,
                          "%s: no interface for ifname %s, index %d", __func__,
                          ifname, ifam->ifam_index);
                return -1;
@@ -823,7 +829,7 @@ static int rtm_read_mesg(struct rt_msghdr *rtm, union sockunion *dest,
 
        /* rt_msghdr version check. */
        if (rtm->rtm_version != RTM_VERSION)
-               flog_warn(ZEBRA_ERR_RTM_VERSION_MISMATCH,
+               flog_warn(EC_ZEBRA_RTM_VERSION_MISMATCH,
                          "Routing message version different %d should be %d."
                          "This may cause problem\n",
                          rtm->rtm_version, RTM_VERSION);
@@ -1135,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 */
@@ -1184,7 +1190,7 @@ int rtm_write(int message, union sockunion *dest, union sockunion *mask,
                                inet_ntop(AF_INET, &mask->sin.sin_addr,
                                          mask_buf, INET_ADDRSTRLEN);
                        flog_warn(
-                               ZEBRA_ERR_RTM_NO_GATEWAY,
+                               EC_ZEBRA_RTM_NO_GATEWAY,
                                "%s: %s/%s: gate == NULL and no gateway found for ifindex %d",
                                __func__, dest_buf, mask_buf, index);
                        return -1;
@@ -1242,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)
@@ -1252,7 +1258,7 @@ int rtm_write(int message, union sockunion *dest, union sockunion *mask,
                if (errno == ESRCH)
                        return ZEBRA_ERR_RTNOEXIST;
 
-               flog_err_sys(LIB_ERR_SOCKET, "%s: write : %s (%d)", __func__,
+               flog_err_sys(EC_LIB_SOCKET, "%s: write : %s (%d)", __func__,
                             safe_strerror(errno), errno);
                return ZEBRA_ERR_KERNEL;
        }
@@ -1335,7 +1341,7 @@ static int kernel_read(struct thread *thread)
 
        if (nbytes <= 0) {
                if (nbytes < 0 && errno != EWOULDBLOCK && errno != EAGAIN)
-                       flog_err_sys(LIB_ERR_SOCKET, "routing socket error: %s",
+                       flog_err_sys(EC_LIB_SOCKET, "routing socket error: %s",
                                     safe_strerror(errno));
                return 0;
        }
@@ -1389,11 +1395,19 @@ 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) {
-               flog_err_sys(LIB_ERR_SOCKET,
-                            "Can't init kernel routing socket");
+               flog_err_sys(EC_LIB_SOCKET, "Can't init kernel routing socket");
+               return;
+       }
+
+       if (dplane_routing_sock < 0) {
+               flog_err_sys(EC_LIB_SOCKET,
+                            "Can't init kernel dataplane routing socket");
                return;
        }
 
@@ -1415,7 +1429,7 @@ void kernel_init(struct zebra_ns *zns)
        routing_socket(zns);
 }
 
-void kernel_terminate(struct zebra_ns *zns)
+void kernel_terminate(struct zebra_ns *zns, bool complete)
 {
        return;
 }