]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: Cleanup a couple of api issues
authorDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 16 Feb 2018 00:55:56 +0000 (19:55 -0500)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 9 Mar 2018 16:07:41 +0000 (11:07 -0500)
1) use uint32_t instead of u_int32_t as we are supposed to
2) Consolidate priority into the rule.
3) Cleanup the api from this.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
zebra/rule_netlink.c
zebra/rule_netlink.h
zebra/zebra_pbr.c
zebra/zebra_pbr.h
zebra/zserv.c

index 4b8791ee2fc9fad72eb015c3181d3f511636b101..3228d0e4bd535ed240faefaab5d240cac8825c9f 100644 (file)
@@ -52,7 +52,7 @@
  * waiting for netlink status.
  */
 static int netlink_rule_update(int cmd, struct zebra_pbr_rule *rule,
-                              struct interface *ifp, u_int32_t rule_pri)
+                              struct interface *ifp)
 {
        int family;
        int bytelen;
@@ -66,7 +66,7 @@ static int netlink_rule_update(int cmd, struct zebra_pbr_rule *rule,
        char buf1[PREFIX_STRLEN];
        char buf2[PREFIX_STRLEN];
 
-       memset(&req, 0, sizeof req - NL_PKT_BUF_SIZE);
+       memset(&req, 0, sizeof(req) - NL_PKT_BUF_SIZE);
        family = PREFIX_FAMILY(&rule->filter.src_ip);
        bytelen = (family == AF_INET ? 4 : 16);
 
@@ -82,7 +82,7 @@ static int netlink_rule_update(int cmd, struct zebra_pbr_rule *rule,
                req.n.nlmsg_flags |= NLM_F_CREATE | NLM_F_EXCL;
 
        /* rule's pref # */
-       addattr32(&req.n, sizeof(req), FRA_PRIORITY, rule_pri);
+       addattr32(&req.n, sizeof(req), FRA_PRIORITY, rule->priority);
 
        /* interface on which applied */
        addattr_l(&req.n, sizeof(req), FRA_IFNAME, ifp->name,
@@ -111,14 +111,13 @@ static int netlink_rule_update(int cmd, struct zebra_pbr_rule *rule,
        }
 
        if (IS_ZEBRA_DEBUG_KERNEL)
-               zlog_debug("Tx %s family %s IF %s(%u) Pref %u Src %s "
-                          "Dst %s Table %u",
-                          nl_msg_type_to_str(cmd),
-                          nl_family_to_str(family),
-                          ifp->name, ifp->ifindex, rule_pri,
-                          prefix2str(&rule->filter.src_ip, buf1, sizeof(buf1)),
-                          prefix2str(&rule->filter.dst_ip, buf2, sizeof(buf2)),
-                          rule->action.table);
+               zlog_debug(
+                       "Tx %s family %s IF %s(%u) Pref %u Src %s Dst %s Table %u",
+                       nl_msg_type_to_str(cmd), nl_family_to_str(family),
+                       ifp->name, ifp->ifindex, rule->priority,
+                       prefix2str(&rule->filter.src_ip, buf1, sizeof(buf1)),
+                       prefix2str(&rule->filter.dst_ip, buf2, sizeof(buf2)),
+                       rule->action.table);
 
        /* Ship off the message.
         * Note: Currently, netlink_talk() is a blocking call which returns
@@ -137,31 +136,27 @@ static int netlink_rule_update(int cmd, struct zebra_pbr_rule *rule,
  * goes in the rule to denote relative ordering; it may or may not be the
  * same as the rule's user-defined sequence number.
  */
-void kernel_add_pbr_rule(struct zebra_pbr_rule *rule,
-                        struct interface *ifp, u_int32_t rule_pri)
+void kernel_add_pbr_rule(struct zebra_pbr_rule *rule, struct interface *ifp)
 {
        int ret = 0;
 
-       ret = netlink_rule_update(RTM_NEWRULE, rule, ifp, rule_pri);
-       kernel_pbr_rule_add_del_status(rule, ifp, rule_pri,
-                                      (!ret) ?
-                                      SOUTHBOUND_INSTALL_SUCCESS :
-                                      SOUTHBOUND_INSTALL_FAILURE);
+       ret = netlink_rule_update(RTM_NEWRULE, rule, ifp);
+       kernel_pbr_rule_add_del_status(rule, ifp,
+                                      (!ret) ? SOUTHBOUND_INSTALL_SUCCESS
+                                             : SOUTHBOUND_INSTALL_FAILURE);
 }
 
 /*
  * Uninstall specified rule for a specific interface.
  */
-void kernel_del_pbr_rule(struct zebra_pbr_rule *rule,
-                        struct interface *ifp, u_int32_t rule_pri)
+void kernel_del_pbr_rule(struct zebra_pbr_rule *rule, struct interface *ifp)
 {
        int ret = 0;
 
-       ret = netlink_rule_update(RTM_DELRULE, rule, ifp, rule_pri);
-       kernel_pbr_rule_add_del_status(rule, ifp, rule_pri,
-                                      (!ret) ?
-                                      SOUTHBOUND_DELETE_SUCCESS :
-                                      SOUTHBOUND_DELETE_FAILURE);
+       ret = netlink_rule_update(RTM_DELRULE, rule, ifp);
+       kernel_pbr_rule_add_del_status(rule, ifp,
+                                      (!ret) ? SOUTHBOUND_DELETE_SUCCESS
+                                             : SOUTHBOUND_DELETE_FAILURE);
 }
 
 /*
@@ -180,7 +175,6 @@ int netlink_rule_change(struct sockaddr_nl *snl, struct nlmsghdr *h,
        int len;
        char *ifname;
        struct interface *ifp;
-       u_int32_t rule_pri = 0;
        struct zebra_pbr_rule rule;
        char buf1[PREFIX_STRLEN];
        char buf2[PREFIX_STRLEN];
@@ -219,7 +213,7 @@ int netlink_rule_change(struct sockaddr_nl *snl, struct nlmsghdr *h,
 
        memset(&rule, 0, sizeof(rule));
        if (tb[FRA_PRIORITY])
-               rule_pri = *(u_int32_t *)RTA_DATA(tb[FRA_PRIORITY]);
+               rule.priority = *(uint32_t *)RTA_DATA(tb[FRA_PRIORITY]);
 
        if (tb[FRA_SRC]) {
                if (frh->family == AF_INET)
@@ -244,21 +238,21 @@ int netlink_rule_change(struct sockaddr_nl *snl, struct nlmsghdr *h,
        }
 
        if (tb[FRA_TABLE])
-               rule.action.table = *(u_int32_t *)RTA_DATA(tb[FRA_TABLE]);
+               rule.action.table = *(uint32_t *)RTA_DATA(tb[FRA_TABLE]);
        else
                rule.action.table = frh->table;
 
        if (IS_ZEBRA_DEBUG_KERNEL)
-               zlog_debug("Rx %s family %s IF %s(%u) Pref %u Src %s "
-                          "Dst %s Table %u",
-                          nl_msg_type_to_str(h->nlmsg_type),
-                          nl_family_to_str(frh->family),
-                          ifp->name, ifp->ifindex, rule_pri,
-                          prefix2str(&rule.filter.src_ip, buf1, sizeof(buf1)),
-                          prefix2str(&rule.filter.dst_ip, buf2, sizeof(buf2)),
-                          rule.action.table);
-
-       return kernel_pbr_rule_del(&rule, ifp, rule_pri);
+               zlog_debug(
+                       "Rx %s family %s IF %s(%u) Pref %u Src %s Dst %s Table %u",
+                       nl_msg_type_to_str(h->nlmsg_type),
+                       nl_family_to_str(frh->family), ifp->name, ifp->ifindex,
+                       rule.priority,
+                       prefix2str(&rule.filter.src_ip, buf1, sizeof(buf1)),
+                       prefix2str(&rule.filter.dst_ip, buf2, sizeof(buf2)),
+                       rule.action.table);
+
+       return kernel_pbr_rule_del(&rule, ifp);
 }
 
 /*
index 034068b8995b8ddec3d06185c895acaf09dbceec..3a9b51309e9ea55925050e6e0be91b7a710b6d19 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  * Zebra Policy Based Routing (PBR) interaction with the kernel using
  * netlink - public definitions and function declarations.
  * Copyright (C) 2018 Cumulus Networks, Inc.
index 6e521be39eaef1f965bb58dcaaf2706f5635f8d5..827005b3a14006eca75741248bf7f5a302ef5f7f 100644 (file)
@@ -36,7 +36,6 @@
  */
 void kernel_pbr_rule_add_del_status(struct zebra_pbr_rule *rule,
                                    struct interface *ifp,
-                                   u_int32_t rule_pri,
                                    enum southbound_results res)
 {
 }
@@ -44,9 +43,7 @@ void kernel_pbr_rule_add_del_status(struct zebra_pbr_rule *rule,
 /*
  * Handle rule delete notification from kernel.
  */
-int kernel_pbr_rule_del(struct zebra_pbr_rule *rule,
-                       struct interface *ifp,
-                       u_int32_t rule_pri)
+int kernel_pbr_rule_del(struct zebra_pbr_rule *rule, struct interface *ifp)
 {
        return 0;
 }
index 2e80aeb8a359007d84322475a941a2d7c97d210b..b87388afc5a9e9ded728a1088cb52e1521e78322 100644 (file)
@@ -39,7 +39,7 @@
  * specified.
  */
 struct zebra_pbr_filter {
-       u_int32_t filter_bm;
+       uint32_t filter_bm;
 #define PBR_FILTER_SRC_IP     (1 << 0)
 #define PBR_FILTER_DST_IP     (1 << 1)
 #define PBR_FILTER_SRC_PORT   (1 << 2)
@@ -50,8 +50,8 @@ struct zebra_pbr_filter {
        struct prefix dst_ip;
 
        /* Source and Destination higher-layer (TCP/UDP) port numbers. */
-       u_int16_t src_port;
-       u_int16_t dst_port;
+       uint16_t src_port;
+       uint16_t dst_port;
 };
 
 #define IS_RULE_FILTERING_ON_SRC_IP(r) \
@@ -73,7 +73,7 @@ struct zebra_pbr_filter {
  * the user criteria may directly point to a table too.
  */
 struct zebra_pbr_action {
-       u_int32_t table;
+       uint32_t table;
 };
 
 /*
@@ -84,7 +84,8 @@ struct zebra_pbr_action {
  * order amongst rules.
  */
 struct zebra_pbr_rule {
-       u_int32_t seq;
+       uint32_t seq;
+       uint32_t priority;
        struct zebra_pbr_filter filter;
        struct zebra_pbr_action action;
 };
@@ -97,13 +98,13 @@ struct zebra_pbr_rule {
  * rule priority - maps to preference/FRA_PRIORITY on Linux.
  */
 extern void kernel_add_pbr_rule(struct zebra_pbr_rule *rule,
-                               struct interface *ifp, u_int32_t rule_pri);
+                               struct interface *ifp);
 
 /*
  * Uninstall specified rule for a specific interface.
  */
 extern void kernel_del_pbr_rule(struct zebra_pbr_rule *rule,
-                               struct interface *ifp, u_int32_t rule_pri);
+                               struct interface *ifp);
 
 /*
  * Get to know existing PBR rules in the kernel - typically called at startup.
@@ -115,14 +116,12 @@ extern void kernel_read_pbr_rules(struct zebra_ns *zns);
  */
 extern void kernel_pbr_rule_add_del_status(struct zebra_pbr_rule *rule,
                                           struct interface *ifp,
-                                          u_int32_t rule_pri,
                                           enum southbound_results res);
 
 /*
  * Handle rule delete notification from kernel.
  */
 extern int kernel_pbr_rule_del(struct zebra_pbr_rule *rule,
-                              struct interface *ifp,
-                              u_int32_t rule_pri);
+                              struct interface *ifp);
 
 #endif /* _ZEBRA_PBR_H */
index 13936e5366c8ee10555bf2d64ee4766454b9e064..007a02cedf84a019518e00a60fe7641c484a609d 100644 (file)
@@ -2595,7 +2595,6 @@ static inline void zread_rule(uint16_t command, struct zserv *client,
        struct interface *ifp;
        struct stream *s;
        uint32_t total, i;
-       uint32_t priority;
        ifindex_t ifindex;
 
        s = client->ibuf;
@@ -2605,7 +2604,7 @@ static inline void zread_rule(uint16_t command, struct zserv *client,
                memset(&zpr, 0, sizeof(zpr));
 
                STREAM_GETL(s, zpr.seq);
-               STREAM_GETL(s, priority);
+               STREAM_GETL(s, zpr.priority);
                STREAM_GETC(s, zpr.filter.src_ip.family);
                STREAM_GETC(s, zpr.filter.src_ip.prefixlen);
                STREAM_GET(&zpr.filter.src_ip.u.prefix, s,
@@ -2637,7 +2636,7 @@ static inline void zread_rule(uint16_t command, struct zserv *client,
                if (zpr.filter.dst_port)
                        zpr.filter.filter_bm |= PBR_FILTER_DST_PORT;
 
-               kernel_add_pbr_rule(&zpr, ifp, priority);
+               kernel_add_pbr_rule(&zpr, ifp);
        }
 
 stream_failure: