Florian Westphal says: ==================== fib: merge nl policies v4: resend with fixed subject line. I preserved review tags from David Ahern. v3: drop first two patches, otherwise unchanged. This series merges the different (largely identical) nla policies. v2 also squashed the ->suppress() implementation, I've dropped this. Problem is that it needs ugly ifdef'ry to avoid build breakage with CONFIG_INET=n || IPV6=n. Given that even microbenchmark doesn't show any noticeable improvement when ->suppress is inlined (it uses INDIRECT_CALLABLE) i decided to toss the patch instead of adding more ifdefs. ====================
Unified · Split
| @@ -91,7 +91,6 @@ struct fib_rules_ops { · 90 unmodified lines | ||
| 91 | 91 | void (*flush_cache)(struct fib_rules_ops *ops); |
| 92 | 92 | |
| 93 | 93 | int nlgroup; |
| 94 | − const struct nla_policy *policy; | |
| 95 | 94 | struct list_head rules_list; |
| 96 | 95 | struct module *owner; |
| 97 | 96 | struct net *fro_net; |
| @@ -103,26 +102,6 @@ struct fib_rule_notifier_info { · 5 unmodified lines | ||
| 103 | 102 | struct fib_rule *rule; |
| 104 | 103 | }; |
| 105 | 104 | |
| 106 | −#define FRA_GENERIC_POLICY \ | |
| 107 | − [FRA_UNSPEC] = { .strict_start_type = FRA_DPORT_RANGE + 1 }, \ | |
| 108 | − [FRA_IIFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \ | |
| 109 | − [FRA_OIFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \ | |
| 110 | − [FRA_PRIORITY] = { .type = NLA_U32 }, \ | |
| 111 | − [FRA_FWMARK] = { .type = NLA_U32 }, \ | |
| 112 | − [FRA_TUN_ID] = { .type = NLA_U64 }, \ | |
| 113 | − [FRA_FWMASK] = { .type = NLA_U32 }, \ | |
| 114 | − [FRA_TABLE] = { .type = NLA_U32 }, \ | |
| 115 | − [FRA_SUPPRESS_PREFIXLEN] = { .type = NLA_U32 }, \ | |
| 116 | − [FRA_SUPPRESS_IFGROUP] = { .type = NLA_U32 }, \ | |
| 117 | − [FRA_GOTO] = { .type = NLA_U32 }, \ | |
| 118 | − [FRA_L3MDEV] = { .type = NLA_U8 }, \ | |
| 119 | − [FRA_UID_RANGE] = { .len = sizeof(struct fib_rule_uid_range) }, \ | |
| 120 | − [FRA_PROTOCOL] = { .type = NLA_U8 }, \ | |
| 121 | − [FRA_IP_PROTO] = { .type = NLA_U8 }, \ | |
| 122 | − [FRA_SPORT_RANGE] = { .len = sizeof(struct fib_rule_port_range) }, \ | |
| 123 | − [FRA_DPORT_RANGE] = { .len = sizeof(struct fib_rule_port_range) } | |
| 124 | − | |
| 125 | − | |
| 126 | 105 | static inline void fib_rule_get(struct fib_rule *rule) |
| 127 | 106 | { |
| 128 | 107 | refcount_inc(&rule->refcnt); |
| @@ -750,6 +750,27 @@ static int rule_exists(struct fib_rules_ops *ops, struct fib_rule_hdr *frh, · 749 unmodified lines | ||
| 750 | 750 | return 0; |
| 751 | 751 | } |
| 752 | 752 | |
| 753 | +static const struct nla_policy fib_rule_policy[FRA_MAX + 1] = { | |
| 754 | + [FRA_UNSPEC] = { .strict_start_type = FRA_DPORT_RANGE + 1 }, | |
| 755 | + [FRA_IIFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, | |
| 756 | + [FRA_OIFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, | |
| 757 | + [FRA_PRIORITY] = { .type = NLA_U32 }, | |
| 758 | + [FRA_FWMARK] = { .type = NLA_U32 }, | |
| 759 | + [FRA_FLOW] = { .type = NLA_U32 }, | |
| 760 | + [FRA_TUN_ID] = { .type = NLA_U64 }, | |
| 761 | + [FRA_FWMASK] = { .type = NLA_U32 }, | |
| 762 | + [FRA_TABLE] = { .type = NLA_U32 }, | |
| 763 | + [FRA_SUPPRESS_PREFIXLEN] = { .type = NLA_U32 }, | |
| 764 | + [FRA_SUPPRESS_IFGROUP] = { .type = NLA_U32 }, | |
| 765 | + [FRA_GOTO] = { .type = NLA_U32 }, | |
| 766 | + [FRA_L3MDEV] = { .type = NLA_U8 }, | |
| 767 | + [FRA_UID_RANGE] = { .len = sizeof(struct fib_rule_uid_range) }, | |
| 768 | + [FRA_PROTOCOL] = { .type = NLA_U8 }, | |
| 769 | + [FRA_IP_PROTO] = { .type = NLA_U8 }, | |
| 770 | + [FRA_SPORT_RANGE] = { .len = sizeof(struct fib_rule_port_range) }, | |
| 771 | + [FRA_DPORT_RANGE] = { .len = sizeof(struct fib_rule_port_range) } | |
| 772 | +}; | |
| 773 | + | |
| 753 | 774 | int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh, |
| 754 | 775 | struct netlink_ext_ack *extack) |
| 755 | 776 | { |
| @@ -774,7 +795,7 @@ int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh, · 18 unmodified lines | ||
| 774 | 795 | } |
| 775 | 796 | |
| 776 | 797 | err = nlmsg_parse_deprecated(nlh, sizeof(*frh), tb, FRA_MAX, |
| 777 | − ops->policy, extack); | |
| 798 | + fib_rule_policy, extack); | |
| 778 | 799 | if (err < 0) { |
| 779 | 800 | NL_SET_ERR_MSG(extack, "Error parsing msg"); |
| 780 | 801 | goto errout; |
| @@ -882,7 +903,7 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh, · 101 unmodified lines | ||
| 882 | 903 | } |
| 883 | 904 | |
| 884 | 905 | err = nlmsg_parse_deprecated(nlh, sizeof(*frh), tb, FRA_MAX, |
| 885 | − ops->policy, extack); | |
| 906 | + fib_rule_policy, extack); | |
| 886 | 907 | if (err < 0) { |
| 887 | 908 | NL_SET_ERR_MSG(extack, "Error parsing msg"); |
| 888 | 909 | goto errout; |
| @@ -101,10 +101,6 @@ errout: · 100 unmodified lines | ||
| 101 | 101 | return err; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | −static const struct nla_policy dn_fib_rule_policy[FRA_MAX+1] = { | |
| 105 | − FRA_GENERIC_POLICY, | |
| 106 | −}; | |
| 107 | − | |
| 108 | 104 | static int dn_fib_rule_match(struct fib_rule *rule, struct flowi *fl, int flags) |
| 109 | 105 | { |
| 110 | 106 | struct dn_fib_rule *r = (struct dn_fib_rule *)rule; |
| @@ -235,7 +231,6 @@ static const struct fib_rules_ops __net_initconst dn_fib_rules_ops_template = { · 124 unmodified lines | ||
| 235 | 231 | .fill = dn_fib_rule_fill, |
| 236 | 232 | .flush_cache = dn_fib_rule_flush_cache, |
| 237 | 233 | .nlgroup = RTNLGRP_DECnet_RULE, |
| 238 | − .policy = dn_fib_rule_policy, | |
| 239 | 234 | .owner = THIS_MODULE, |
| 240 | 235 | .fro_net = &init_net, |
| 241 | 236 | }; |
| @@ -216,11 +216,6 @@ static struct fib_table *fib_empty_table(struct net *net) · 215 unmodified lines | ||
| 216 | 216 | return NULL; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | −static const struct nla_policy fib4_rule_policy[FRA_MAX+1] = { | |
| 220 | − FRA_GENERIC_POLICY, | |
| 221 | − [FRA_FLOW] = { .type = NLA_U32 }, | |
| 222 | −}; | |
| 223 | − | |
| 224 | 219 | static int fib4_rule_configure(struct fib_rule *rule, struct sk_buff *skb, |
| 225 | 220 | struct fib_rule_hdr *frh, |
| 226 | 221 | struct nlattr **tb, |
| @@ -386,7 +381,6 @@ static const struct fib_rules_ops __net_initconst fib4_rules_ops_template = { · 159 unmodified lines | ||
| 386 | 381 | .nlmsg_payload = fib4_rule_nlmsg_payload, |
| 387 | 382 | .flush_cache = fib4_rule_flush_cache, |
| 388 | 383 | .nlgroup = RTNLGRP_IPV4_RULE, |
| 389 | − .policy = fib4_rule_policy, | |
| 390 | 384 | .owner = THIS_MODULE, |
| 391 | 385 | }; |
| 392 | 386 | |
| @@ -195,10 +195,6 @@ static int ipmr_rule_match(struct fib_rule *rule, struct flowi *fl, int flags) · 194 unmodified lines | ||
| 195 | 195 | return 1; |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | −static const struct nla_policy ipmr_rule_policy[FRA_MAX + 1] = { | |
| 199 | − FRA_GENERIC_POLICY, | |
| 200 | −}; | |
| 201 | − | |
| 202 | 198 | static int ipmr_rule_configure(struct fib_rule *rule, struct sk_buff *skb, |
| 203 | 199 | struct fib_rule_hdr *frh, struct nlattr **tb, |
| 204 | 200 | struct netlink_ext_ack *extack) |
| @@ -231,7 +227,6 @@ static const struct fib_rules_ops __net_initconst ipmr_rules_ops_template = { · 26 unmodified lines | ||
| 231 | 227 | .compare = ipmr_rule_compare, |
| 232 | 228 | .fill = ipmr_rule_fill, |
| 233 | 229 | .nlgroup = RTNLGRP_IPV4_RULE, |
| 234 | − .policy = ipmr_rule_policy, | |
| 235 | 230 | .owner = THIS_MODULE, |
| 236 | 231 | }; |
| 237 | 232 | |
| @@ -340,10 +340,6 @@ INDIRECT_CALLABLE_SCOPE int fib6_rule_match(struct fib_rule *rule, · 339 unmodified lines | ||
| 340 | 340 | return 1; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | −static const struct nla_policy fib6_rule_policy[FRA_MAX+1] = { | |
| 344 | − FRA_GENERIC_POLICY, | |
| 345 | −}; | |
| 346 | − | |
| 347 | 343 | static int fib6_rule_configure(struct fib_rule *rule, struct sk_buff *skb, |
| 348 | 344 | struct fib_rule_hdr *frh, |
| 349 | 345 | struct nlattr **tb, |
| @@ -459,7 +455,6 @@ static const struct fib_rules_ops __net_initconst fib6_rules_ops_template = { · 109 unmodified lines | ||
| 459 | 455 | .fill = fib6_rule_fill, |
| 460 | 456 | .nlmsg_payload = fib6_rule_nlmsg_payload, |
| 461 | 457 | .nlgroup = RTNLGRP_IPV6_RULE, |
| 462 | − .policy = fib6_rule_policy, | |
| 463 | 458 | .owner = THIS_MODULE, |
| 464 | 459 | .fro_net = &init_net, |
| 465 | 460 | }; |
| @@ -182,10 +182,6 @@ static int ip6mr_rule_match(struct fib_rule *rule, struct flowi *flp, int flags) · 181 unmodified lines | ||
| 182 | 182 | return 1; |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | −static const struct nla_policy ip6mr_rule_policy[FRA_MAX + 1] = { | |
| 186 | − FRA_GENERIC_POLICY, | |
| 187 | −}; | |
| 188 | − | |
| 189 | 185 | static int ip6mr_rule_configure(struct fib_rule *rule, struct sk_buff *skb, |
| 190 | 186 | struct fib_rule_hdr *frh, struct nlattr **tb, |
| 191 | 187 | struct netlink_ext_ack *extack) |
| @@ -218,7 +214,6 @@ static const struct fib_rules_ops __net_initconst ip6mr_rules_ops_template = { · 26 unmodified lines | ||
| 218 | 214 | .compare = ip6mr_rule_compare, |
| 219 | 215 | .fill = ip6mr_rule_fill, |
| 220 | 216 | .nlgroup = RTNLGRP_IPV6_RULE, |
| 221 | − .policy = ip6mr_rule_policy, | |
| 222 | 217 | .owner = THIS_MODULE, |
| 223 | 218 | }; |
| 224 | 219 | |