]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/kernel_netlink.c
pimd: Add missing yang callbacks for route-maps
[mirror_frr.git] / zebra / kernel_netlink.c
index 4971994346432f8131d7dbad65c4cbee04d1bf1f..90d3aeb482d9c4fe8b912380acf911b916c7ed10 100644 (file)
@@ -99,6 +99,9 @@ static const struct message nlmsg_str[] = {{RTM_NEWROUTE, "RTM_NEWROUTE"},
                                           {RTM_NEWRULE, "RTM_NEWRULE"},
                                           {RTM_DELRULE, "RTM_DELRULE"},
                                           {RTM_GETRULE, "RTM_GETRULE"},
+                                          {RTM_NEWNEXTHOP, "RTM_NEWNEXTHOP"},
+                                          {RTM_DELNEXTHOP, "RTM_DELNEXTHOP"},
+                                          {RTM_GETNEXTHOP, "RTM_GETNEXTHOP"},
                                           {0}};
 
 static const struct message rtproto_str[] = {
@@ -129,8 +132,18 @@ static const struct message family_str[] = {{AF_INET, "ipv4"},
                                            {RTNL_FAMILY_IP6MR, "ipv6MR"},
                                            {0}};
 
-static const struct message rttype_str[] = {{RTN_UNICAST, "unicast"},
+static const struct message rttype_str[] = {{RTN_UNSPEC, "none"},
+                                           {RTN_UNICAST, "unicast"},
+                                           {RTN_LOCAL, "local"},
+                                           {RTN_BROADCAST, "broadcast"},
+                                           {RTN_ANYCAST, "anycast"},
                                            {RTN_MULTICAST, "multicast"},
+                                           {RTN_BLACKHOLE, "blackhole"},
+                                           {RTN_UNREACHABLE, "unreachable"},
+                                           {RTN_PROHIBIT, "prohibited"},
+                                           {RTN_THROW, "throw"},
+                                           {RTN_NAT, "nat"},
+                                           {RTN_XRESOLVE, "resolver"},
                                            {0}};
 
 extern struct thread_master *master;
@@ -173,7 +186,7 @@ static int netlink_recvbuf(struct nlsock *nl, uint32_t newsize)
        }
 
        /* Try force option (linux >= 2.6.14) and fall back to normal set */
-       frr_elevate_privs(&zserv_privs) {
+       frr_with_privs(&zserv_privs) {
                ret = setsockopt(nl->sock, SOL_SOCKET, SO_RCVBUFFORCE,
                                 &nl_rcvbufsize,
                                 sizeof(nl_rcvbufsize));
@@ -210,7 +223,7 @@ static int netlink_socket(struct nlsock *nl, unsigned long groups,
        int sock;
        int namelen;
 
-       frr_elevate_privs(&zserv_privs) {
+       frr_with_privs(&zserv_privs) {
                sock = ns_socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE, ns_id);
                if (sock < 0) {
                        zlog_err("Can't open %s socket: %s", nl->name,
@@ -277,10 +290,26 @@ static int netlink_information_fetch(struct nlmsghdr *h, ns_id_t ns_id,
                return netlink_neigh_change(h, ns_id);
        case RTM_DELNEIGH:
                return netlink_neigh_change(h, ns_id);
+       case RTM_GETNEIGH:
+               /*
+                * Kernel in some situations when it expects
+                * user space to resolve arp entries, we will
+                * receive this notification.  As we don't
+                * need this notification and as that
+                * we don't want to spam the log file with
+                * below messages, just ignore.
+                */
+               if (IS_ZEBRA_DEBUG_KERNEL)
+                       zlog_debug("Received RTM_GETNEIGH, ignoring");
+               break;
        case RTM_NEWRULE:
                return netlink_rule_change(h, ns_id, startup);
        case RTM_DELRULE:
                return netlink_rule_change(h, ns_id, startup);
+       case RTM_NEWNEXTHOP:
+               return netlink_nexthop_change(h, ns_id, startup);
+       case RTM_DELNEXTHOP:
+               return netlink_nexthop_change(h, ns_id, startup);
        default:
                /*
                 * If we have received this message then
@@ -342,7 +371,7 @@ static void netlink_write_incoming(const char *buf, const unsigned int size,
        FILE *f;
 
        snprintf(fname, MAXPATHLEN, "%s/%s_%u", frr_vtydir, "netlink", counter);
-       frr_elevate_privs(&zserv_privs) {
+       frr_with_privs(&zserv_privs) {
                f = fopen(fname, "w");
        }
        if (f) {
@@ -363,7 +392,7 @@ static long netlink_read_file(char *buf, const char *fname)
        FILE *f;
        long file_bytes = -1;
 
-       frr_elevate_privs(&zserv_privs) {
+       frr_with_privs(&zserv_privs) {
                f = fopen(fname, "r");
        }
        if (f) {
@@ -563,6 +592,7 @@ struct rtattr *addattr_nest(struct nlmsghdr *n, int maxlen, int type)
        struct rtattr *nest = NLMSG_TAIL(n);
 
        addattr_l(n, maxlen, type, NULL, 0);
+       nest->rta_type |= NLA_F_NESTED;
        return nest;
 }
 
@@ -577,6 +607,7 @@ struct rtattr *rta_nest(struct rtattr *rta, int maxlen, int type)
        struct rtattr *nest = RTA_TAIL(rta);
 
        rta_addattr_l(rta, maxlen, type, NULL, 0);
+       nest->rta_type |= NLA_F_NESTED;
        return nest;
 }
 
@@ -874,15 +905,20 @@ int netlink_parse_info(int (*filter)(struct nlmsghdr *, ns_id_t, int),
                                                        msg_type,
                                                        err->msg.nlmsg_seq,
                                                        err->msg.nlmsg_pid);
-                               } else
-                                       flog_err(
-                                               EC_ZEBRA_UNEXPECTED_MESSAGE,
-                                               "%s error: %s, type=%s(%u), seq=%u, pid=%u",
-                                               nl->name,
-                                               safe_strerror(-errnum),
-                                               nl_msg_type_to_str(msg_type),
-                                               msg_type, err->msg.nlmsg_seq,
-                                               err->msg.nlmsg_pid);
+                               } else {
+                                       if ((msg_type != RTM_GETNEXTHOP)
+                                           || !startup)
+                                               flog_err(
+                                                       EC_ZEBRA_UNEXPECTED_MESSAGE,
+                                                       "%s error: %s, type=%s(%u), seq=%u, pid=%u",
+                                                       nl->name,
+                                                       safe_strerror(-errnum),
+                                                       nl_msg_type_to_str(
+                                                               msg_type),
+                                                       msg_type,
+                                                       err->msg.nlmsg_seq,
+                                                       err->msg.nlmsg_pid);
+                               }
 
                                return -1;
                        }
@@ -979,7 +1015,7 @@ int netlink_talk_info(int (*filter)(struct nlmsghdr *, ns_id_t, int startup),
                        n->nlmsg_flags);
 
        /* Send message to netlink interface. */
-       frr_elevate_privs(&zserv_privs) {
+       frr_with_privs(&zserv_privs) {
                status = sendmsg(nl->sock, &msg, 0);
                save_errno = errno;
        }
@@ -1046,7 +1082,7 @@ int netlink_request(struct nlsock *nl, struct nlmsghdr *n)
        snl.nl_family = AF_NETLINK;
 
        /* Raise capabilities and send message, then lower capabilities. */
-       frr_elevate_privs(&zserv_privs) {
+       frr_with_privs(&zserv_privs) {
                ret = sendto(nl->sock, (void *)n, n->nlmsg_len, 0,
                             (struct sockaddr *)&snl, sizeof snl);
        }
@@ -1064,7 +1100,7 @@ int netlink_request(struct nlsock *nl, struct nlmsghdr *n)
    netlink_socket (). */
 void kernel_init(struct zebra_ns *zns)
 {
-       unsigned long groups;
+       uint32_t groups;
 #if defined SOL_NETLINK
        int one, ret;
 #endif
@@ -1085,8 +1121,9 @@ void kernel_init(struct zebra_ns *zns)
                RTMGRP_IPV6_IFADDR             |
                RTMGRP_IPV4_MROUTE             |
                RTMGRP_NEIGH                   |
-               (1 << (RTNLGRP_IPV4_RULE - 1)) |
-               (1 << (RTNLGRP_IPV6_RULE - 1));
+               ((uint32_t) 1 << (RTNLGRP_IPV4_RULE - 1)) |
+               ((uint32_t) 1 << (RTNLGRP_IPV6_RULE - 1)) |
+               ((uint32_t) 1 << (RTNLGRP_NEXTHOP - 1));
 
        snprintf(zns->netlink.name, sizeof(zns->netlink.name),
                 "netlink-listen (NS %u)", zns->ns_id);