* 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;
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);
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,
}
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
* 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);
}
/*
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];
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)
}
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);
}
/*
* 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)
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) \
* the user criteria may directly point to a table too.
*/
struct zebra_pbr_action {
- u_int32_t table;
+ uint32_t table;
};
/*
* 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;
};
* 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.
*/
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 */