Commit 0f87b1dd01b51dc3c789f7a212656a4a87eee1bd

Authored by Patrick McHardy
Committed by David S. Miller
1 parent 28bb17268b

net: fib_rules: decouple address families from real address families

Decouple the address family values used for fib_rules from the real
address families in socket.h. This allows to use fib_rules for
code that is not a real address family without increasing AF_MAX/NPROTO.

Values up to 127 are reserved for real address families and map directly
to the corresponding AF value, values starting from 128 are for other
uses. rtnetlink is changed to invoke the AF_UNSPEC dumpit/doit handlers
for these families.

Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 5 changed files with 20 additions and 8 deletions Side-by-side Diff

include/linux/fib_rules.h
... ... @@ -15,6 +15,13 @@
15 15 /* try to find source address in routing lookups */
16 16 #define FIB_RULE_FIND_SADDR 0x00010000
17 17  
  18 +/* fib_rules families. values up to 127 are reserved for real address
  19 + * families, values above 128 may be used arbitrarily.
  20 + */
  21 +#define FIB_RULES_IPV4 AF_INET
  22 +#define FIB_RULES_IPV6 AF_INET6
  23 +#define FIB_RULES_DECNET AF_DECnet
  24 +
18 25 struct fib_rule_hdr {
19 26 __u8 family;
20 27 __u8 dst_len;
net/core/rtnetlink.c
... ... @@ -118,7 +118,11 @@
118 118 {
119 119 struct rtnl_link *tab;
120 120  
121   - tab = rtnl_msg_handlers[protocol];
  121 + if (protocol < NPROTO)
  122 + tab = rtnl_msg_handlers[protocol];
  123 + else
  124 + tab = NULL;
  125 +
122 126 if (tab == NULL || tab[msgindex].doit == NULL)
123 127 tab = rtnl_msg_handlers[PF_UNSPEC];
124 128  
... ... @@ -129,7 +133,11 @@
129 133 {
130 134 struct rtnl_link *tab;
131 135  
132   - tab = rtnl_msg_handlers[protocol];
  136 + if (protocol < NPROTO)
  137 + tab = rtnl_msg_handlers[protocol];
  138 + else
  139 + tab = NULL;
  140 +
133 141 if (tab == NULL || tab[msgindex].dumpit == NULL)
134 142 tab = rtnl_msg_handlers[PF_UNSPEC];
135 143  
... ... @@ -1444,9 +1452,6 @@
1444 1452 return 0;
1445 1453  
1446 1454 family = ((struct rtgenmsg *)NLMSG_DATA(nlh))->rtgen_family;
1447   - if (family >= NPROTO)
1448   - return -EAFNOSUPPORT;
1449   -
1450 1455 sz_idx = type>>2;
1451 1456 kind = type&3;
1452 1457  
net/decnet/dn_rules.c
... ... @@ -217,7 +217,7 @@
217 217 }
218 218  
219 219 static struct fib_rules_ops dn_fib_rules_ops_template = {
220   - .family = AF_DECnet,
  220 + .family = FIB_RULES_DECNET,
221 221 .rule_size = sizeof(struct dn_fib_rule),
222 222 .addr_size = sizeof(u16),
223 223 .action = dn_fib_rule_action,
net/ipv4/fib_rules.c
... ... @@ -246,7 +246,7 @@
246 246 }
247 247  
248 248 static struct fib_rules_ops fib4_rules_ops_template = {
249   - .family = AF_INET,
  249 + .family = FIB_RULES_IPV4,
250 250 .rule_size = sizeof(struct fib4_rule),
251 251 .addr_size = sizeof(u32),
252 252 .action = fib4_rule_action,
net/ipv6/fib6_rules.c
... ... @@ -238,7 +238,7 @@
238 238 }
239 239  
240 240 static struct fib_rules_ops fib6_rules_ops_template = {
241   - .family = AF_INET6,
  241 + .family = FIB_RULES_IPV6,
242 242 .rule_size = sizeof(struct fib6_rule),
243 243 .addr_size = sizeof(struct in6_addr),
244 244 .action = fib6_rule_action,