Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'fib-merge-nl-policies'

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.
====================

Link: https://lore.kernel.org/r/20211216120507.3299-1-fw@strlen.de
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+23 -49
-21
include/net/fib_rules.h
··· 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; ··· 101 102 struct fib_notifier_info info; /* must be first */ 102 103 struct fib_rule *rule; 103 104 }; 104 - 105 - #define FRA_GENERIC_POLICY \ 106 - [FRA_UNSPEC] = { .strict_start_type = FRA_DPORT_RANGE + 1 }, \ 107 - [FRA_IIFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \ 108 - [FRA_OIFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \ 109 - [FRA_PRIORITY] = { .type = NLA_U32 }, \ 110 - [FRA_FWMARK] = { .type = NLA_U32 }, \ 111 - [FRA_TUN_ID] = { .type = NLA_U64 }, \ 112 - [FRA_FWMASK] = { .type = NLA_U32 }, \ 113 - [FRA_TABLE] = { .type = NLA_U32 }, \ 114 - [FRA_SUPPRESS_PREFIXLEN] = { .type = NLA_U32 }, \ 115 - [FRA_SUPPRESS_IFGROUP] = { .type = NLA_U32 }, \ 116 - [FRA_GOTO] = { .type = NLA_U32 }, \ 117 - [FRA_L3MDEV] = { .type = NLA_U8 }, \ 118 - [FRA_UID_RANGE] = { .len = sizeof(struct fib_rule_uid_range) }, \ 119 - [FRA_PROTOCOL] = { .type = NLA_U8 }, \ 120 - [FRA_IP_PROTO] = { .type = NLA_U8 }, \ 121 - [FRA_SPORT_RANGE] = { .len = sizeof(struct fib_rule_port_range) }, \ 122 - [FRA_DPORT_RANGE] = { .len = sizeof(struct fib_rule_port_range) } 123 - 124 105 125 106 static inline void fib_rule_get(struct fib_rule *rule) 126 107 {
+23 -2
net/core/fib_rules.c
··· 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 { ··· 795 774 } 796 775 797 776 err = nlmsg_parse_deprecated(nlh, sizeof(*frh), tb, FRA_MAX, 798 - ops->policy, extack); 777 + fib_rule_policy, extack); 799 778 if (err < 0) { 800 779 NL_SET_ERR_MSG(extack, "Error parsing msg"); 801 780 goto errout; ··· 903 882 } 904 883 905 884 err = nlmsg_parse_deprecated(nlh, sizeof(*frh), tb, FRA_MAX, 906 - ops->policy, extack); 885 + fib_rule_policy, extack); 907 886 if (err < 0) { 908 887 NL_SET_ERR_MSG(extack, "Error parsing msg"); 909 888 goto errout;
-5
net/decnet/dn_rules.c
··· 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; ··· 231 235 .fill = dn_fib_rule_fill, 232 236 .flush_cache = dn_fib_rule_flush_cache, 233 237 .nlgroup = RTNLGRP_DECnet_RULE, 234 - .policy = dn_fib_rule_policy, 235 238 .owner = THIS_MODULE, 236 239 .fro_net = &init_net, 237 240 };
-6
net/ipv4/fib_rules.c
··· 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, ··· 381 386 .nlmsg_payload = fib4_rule_nlmsg_payload, 382 387 .flush_cache = fib4_rule_flush_cache, 383 388 .nlgroup = RTNLGRP_IPV4_RULE, 384 - .policy = fib4_rule_policy, 385 389 .owner = THIS_MODULE, 386 390 }; 387 391
-5
net/ipv4/ipmr.c
··· 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) ··· 227 231 .compare = ipmr_rule_compare, 228 232 .fill = ipmr_rule_fill, 229 233 .nlgroup = RTNLGRP_IPV4_RULE, 230 - .policy = ipmr_rule_policy, 231 234 .owner = THIS_MODULE, 232 235 }; 233 236
-5
net/ipv6/fib6_rules.c
··· 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, ··· 455 459 .fill = fib6_rule_fill, 456 460 .nlmsg_payload = fib6_rule_nlmsg_payload, 457 461 .nlgroup = RTNLGRP_IPV6_RULE, 458 - .policy = fib6_rule_policy, 459 462 .owner = THIS_MODULE, 460 463 .fro_net = &init_net, 461 464 };
-5
net/ipv6/ip6mr.c
··· 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) ··· 214 218 .compare = ip6mr_rule_compare, 215 219 .fill = ip6mr_rule_fill, 216 220 .nlgroup = RTNLGRP_IPV6_RULE, 217 - .policy = ip6mr_rule_policy, 218 221 .owner = THIS_MODULE, 219 222 }; 220 223