fib_rules.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. /*
  2. * net/core/fib_rules.c Generic Routing Rules
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation, version 2.
  7. *
  8. * Authors: Thomas Graf <tgraf@suug.ch>
  9. */
  10. #include <linux/types.h>
  11. #include <linux/kernel.h>
  12. #include <linux/list.h>
  13. #include <net/net_namespace.h>
  14. #include <net/sock.h>
  15. #include <net/fib_rules.h>
  16. int fib_default_rule_add(struct fib_rules_ops *ops,
  17. u32 pref, u32 table, u32 flags)
  18. {
  19. struct fib_rule *r;
  20. r = kzalloc(ops->rule_size, GFP_KERNEL);
  21. if (r == NULL)
  22. return -ENOMEM;
  23. atomic_set(&r->refcnt, 1);
  24. r->action = FR_ACT_TO_TBL;
  25. r->pref = pref;
  26. r->table = table;
  27. r->flags = flags;
  28. r->fr_net = hold_net(ops->fro_net);
  29. /* The lock is not required here, the list in unreacheable
  30. * at the moment this function is called */
  31. list_add_tail(&r->list, &ops->rules_list);
  32. return 0;
  33. }
  34. EXPORT_SYMBOL(fib_default_rule_add);
  35. static void notify_rule_change(int event, struct fib_rule *rule,
  36. struct fib_rules_ops *ops, struct nlmsghdr *nlh,
  37. u32 pid);
  38. static struct fib_rules_ops *lookup_rules_ops(struct net *net, int family)
  39. {
  40. struct fib_rules_ops *ops;
  41. rcu_read_lock();
  42. list_for_each_entry_rcu(ops, &net->rules_ops, list) {
  43. if (ops->family == family) {
  44. if (!try_module_get(ops->owner))
  45. ops = NULL;
  46. rcu_read_unlock();
  47. return ops;
  48. }
  49. }
  50. rcu_read_unlock();
  51. return NULL;
  52. }
  53. static void rules_ops_put(struct fib_rules_ops *ops)
  54. {
  55. if (ops)
  56. module_put(ops->owner);
  57. }
  58. static void flush_route_cache(struct fib_rules_ops *ops)
  59. {
  60. if (ops->flush_cache)
  61. ops->flush_cache(ops);
  62. }
  63. int fib_rules_register(struct fib_rules_ops *ops)
  64. {
  65. int err = -EEXIST;
  66. struct fib_rules_ops *o;
  67. struct net *net;
  68. net = ops->fro_net;
  69. if (ops->rule_size < sizeof(struct fib_rule))
  70. return -EINVAL;
  71. if (ops->match == NULL || ops->configure == NULL ||
  72. ops->compare == NULL || ops->fill == NULL ||
  73. ops->action == NULL)
  74. return -EINVAL;
  75. spin_lock(&net->rules_mod_lock);
  76. list_for_each_entry(o, &net->rules_ops, list)
  77. if (ops->family == o->family)
  78. goto errout;
  79. hold_net(net);
  80. list_add_tail_rcu(&ops->list, &net->rules_ops);
  81. err = 0;
  82. errout:
  83. spin_unlock(&net->rules_mod_lock);
  84. return err;
  85. }
  86. EXPORT_SYMBOL_GPL(fib_rules_register);
  87. void fib_rules_cleanup_ops(struct fib_rules_ops *ops)
  88. {
  89. struct fib_rule *rule, *tmp;
  90. list_for_each_entry_safe(rule, tmp, &ops->rules_list, list) {
  91. list_del_rcu(&rule->list);
  92. fib_rule_put(rule);
  93. }
  94. }
  95. EXPORT_SYMBOL_GPL(fib_rules_cleanup_ops);
  96. void fib_rules_unregister(struct fib_rules_ops *ops)
  97. {
  98. struct net *net = ops->fro_net;
  99. spin_lock(&net->rules_mod_lock);
  100. list_del_rcu(&ops->list);
  101. fib_rules_cleanup_ops(ops);
  102. spin_unlock(&net->rules_mod_lock);
  103. synchronize_rcu();
  104. release_net(net);
  105. }
  106. EXPORT_SYMBOL_GPL(fib_rules_unregister);
  107. static int fib_rule_match(struct fib_rule *rule, struct fib_rules_ops *ops,
  108. struct flowi *fl, int flags)
  109. {
  110. int ret = 0;
  111. if (rule->iifindex && (rule->iifindex != fl->iif))
  112. goto out;
  113. if (rule->oifindex && (rule->oifindex != fl->oif))
  114. goto out;
  115. if ((rule->mark ^ fl->mark) & rule->mark_mask)
  116. goto out;
  117. ret = ops->match(rule, fl, flags);
  118. out:
  119. return (rule->flags & FIB_RULE_INVERT) ? !ret : ret;
  120. }
  121. int fib_rules_lookup(struct fib_rules_ops *ops, struct flowi *fl,
  122. int flags, struct fib_lookup_arg *arg)
  123. {
  124. struct fib_rule *rule;
  125. int err;
  126. rcu_read_lock();
  127. list_for_each_entry_rcu(rule, &ops->rules_list, list) {
  128. jumped:
  129. if (!fib_rule_match(rule, ops, fl, flags))
  130. continue;
  131. if (rule->action == FR_ACT_GOTO) {
  132. struct fib_rule *target;
  133. target = rcu_dereference(rule->ctarget);
  134. if (target == NULL) {
  135. continue;
  136. } else {
  137. rule = target;
  138. goto jumped;
  139. }
  140. } else if (rule->action == FR_ACT_NOP)
  141. continue;
  142. else
  143. err = ops->action(rule, fl, flags, arg);
  144. if (err != -EAGAIN) {
  145. fib_rule_get(rule);
  146. arg->rule = rule;
  147. goto out;
  148. }
  149. }
  150. err = -ESRCH;
  151. out:
  152. rcu_read_unlock();
  153. return err;
  154. }
  155. EXPORT_SYMBOL_GPL(fib_rules_lookup);
  156. static int validate_rulemsg(struct fib_rule_hdr *frh, struct nlattr **tb,
  157. struct fib_rules_ops *ops)
  158. {
  159. int err = -EINVAL;
  160. if (frh->src_len)
  161. if (tb[FRA_SRC] == NULL ||
  162. frh->src_len > (ops->addr_size * 8) ||
  163. nla_len(tb[FRA_SRC]) != ops->addr_size)
  164. goto errout;
  165. if (frh->dst_len)
  166. if (tb[FRA_DST] == NULL ||
  167. frh->dst_len > (ops->addr_size * 8) ||
  168. nla_len(tb[FRA_DST]) != ops->addr_size)
  169. goto errout;
  170. err = 0;
  171. errout:
  172. return err;
  173. }
  174. static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
  175. {
  176. struct net *net = sock_net(skb->sk);
  177. struct fib_rule_hdr *frh = nlmsg_data(nlh);
  178. struct fib_rules_ops *ops = NULL;
  179. struct fib_rule *rule, *r, *last = NULL;
  180. struct nlattr *tb[FRA_MAX+1];
  181. int err = -EINVAL, unresolved = 0;
  182. if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*frh)))
  183. goto errout;
  184. ops = lookup_rules_ops(net, frh->family);
  185. if (ops == NULL) {
  186. err = -EAFNOSUPPORT;
  187. goto errout;
  188. }
  189. err = nlmsg_parse(nlh, sizeof(*frh), tb, FRA_MAX, ops->policy);
  190. if (err < 0)
  191. goto errout;
  192. err = validate_rulemsg(frh, tb, ops);
  193. if (err < 0)
  194. goto errout;
  195. rule = kzalloc(ops->rule_size, GFP_KERNEL);
  196. if (rule == NULL) {
  197. err = -ENOMEM;
  198. goto errout;
  199. }
  200. rule->fr_net = hold_net(net);
  201. if (tb[FRA_PRIORITY])
  202. rule->pref = nla_get_u32(tb[FRA_PRIORITY]);
  203. if (tb[FRA_IIFNAME]) {
  204. struct net_device *dev;
  205. rule->iifindex = -1;
  206. nla_strlcpy(rule->iifname, tb[FRA_IIFNAME], IFNAMSIZ);
  207. dev = __dev_get_by_name(net, rule->iifname);
  208. if (dev)
  209. rule->iifindex = dev->ifindex;
  210. }
  211. if (tb[FRA_OIFNAME]) {
  212. struct net_device *dev;
  213. rule->oifindex = -1;
  214. nla_strlcpy(rule->oifname, tb[FRA_OIFNAME], IFNAMSIZ);
  215. dev = __dev_get_by_name(net, rule->oifname);
  216. if (dev)
  217. rule->oifindex = dev->ifindex;
  218. }
  219. if (tb[FRA_FWMARK]) {
  220. rule->mark = nla_get_u32(tb[FRA_FWMARK]);
  221. if (rule->mark)
  222. /* compatibility: if the mark value is non-zero all bits
  223. * are compared unless a mask is explicitly specified.
  224. */
  225. rule->mark_mask = 0xFFFFFFFF;
  226. }
  227. if (tb[FRA_FWMASK])
  228. rule->mark_mask = nla_get_u32(tb[FRA_FWMASK]);
  229. rule->action = frh->action;
  230. rule->flags = frh->flags;
  231. rule->table = frh_get_table(frh, tb);
  232. if (!rule->pref && ops->default_pref)
  233. rule->pref = ops->default_pref(ops);
  234. err = -EINVAL;
  235. if (tb[FRA_GOTO]) {
  236. if (rule->action != FR_ACT_GOTO)
  237. goto errout_free;
  238. rule->target = nla_get_u32(tb[FRA_GOTO]);
  239. /* Backward jumps are prohibited to avoid endless loops */
  240. if (rule->target <= rule->pref)
  241. goto errout_free;
  242. list_for_each_entry(r, &ops->rules_list, list) {
  243. if (r->pref == rule->target) {
  244. rule->ctarget = r;
  245. break;
  246. }
  247. }
  248. if (rule->ctarget == NULL)
  249. unresolved = 1;
  250. } else if (rule->action == FR_ACT_GOTO)
  251. goto errout_free;
  252. err = ops->configure(rule, skb, frh, tb);
  253. if (err < 0)
  254. goto errout_free;
  255. list_for_each_entry(r, &ops->rules_list, list) {
  256. if (r->pref > rule->pref)
  257. break;
  258. last = r;
  259. }
  260. fib_rule_get(rule);
  261. if (ops->unresolved_rules) {
  262. /*
  263. * There are unresolved goto rules in the list, check if
  264. * any of them are pointing to this new rule.
  265. */
  266. list_for_each_entry(r, &ops->rules_list, list) {
  267. if (r->action == FR_ACT_GOTO &&
  268. r->target == rule->pref) {
  269. BUG_ON(r->ctarget != NULL);
  270. rcu_assign_pointer(r->ctarget, rule);
  271. if (--ops->unresolved_rules == 0)
  272. break;
  273. }
  274. }
  275. }
  276. if (rule->action == FR_ACT_GOTO)
  277. ops->nr_goto_rules++;
  278. if (unresolved)
  279. ops->unresolved_rules++;
  280. if (last)
  281. list_add_rcu(&rule->list, &last->list);
  282. else
  283. list_add_rcu(&rule->list, &ops->rules_list);
  284. notify_rule_change(RTM_NEWRULE, rule, ops, nlh, NETLINK_CB(skb).pid);
  285. flush_route_cache(ops);
  286. rules_ops_put(ops);
  287. return 0;
  288. errout_free:
  289. release_net(rule->fr_net);
  290. kfree(rule);
  291. errout:
  292. rules_ops_put(ops);
  293. return err;
  294. }
  295. static int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
  296. {
  297. struct net *net = sock_net(skb->sk);
  298. struct fib_rule_hdr *frh = nlmsg_data(nlh);
  299. struct fib_rules_ops *ops = NULL;
  300. struct fib_rule *rule, *tmp;
  301. struct nlattr *tb[FRA_MAX+1];
  302. int err = -EINVAL;
  303. if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*frh)))
  304. goto errout;
  305. ops = lookup_rules_ops(net, frh->family);
  306. if (ops == NULL) {
  307. err = -EAFNOSUPPORT;
  308. goto errout;
  309. }
  310. err = nlmsg_parse(nlh, sizeof(*frh), tb, FRA_MAX, ops->policy);
  311. if (err < 0)
  312. goto errout;
  313. err = validate_rulemsg(frh, tb, ops);
  314. if (err < 0)
  315. goto errout;
  316. list_for_each_entry(rule, &ops->rules_list, list) {
  317. if (frh->action && (frh->action != rule->action))
  318. continue;
  319. if (frh->table && (frh_get_table(frh, tb) != rule->table))
  320. continue;
  321. if (tb[FRA_PRIORITY] &&
  322. (rule->pref != nla_get_u32(tb[FRA_PRIORITY])))
  323. continue;
  324. if (tb[FRA_IIFNAME] &&
  325. nla_strcmp(tb[FRA_IIFNAME], rule->iifname))
  326. continue;
  327. if (tb[FRA_OIFNAME] &&
  328. nla_strcmp(tb[FRA_OIFNAME], rule->oifname))
  329. continue;
  330. if (tb[FRA_FWMARK] &&
  331. (rule->mark != nla_get_u32(tb[FRA_FWMARK])))
  332. continue;
  333. if (tb[FRA_FWMASK] &&
  334. (rule->mark_mask != nla_get_u32(tb[FRA_FWMASK])))
  335. continue;
  336. if (!ops->compare(rule, frh, tb))
  337. continue;
  338. if (rule->flags & FIB_RULE_PERMANENT) {
  339. err = -EPERM;
  340. goto errout;
  341. }
  342. list_del_rcu(&rule->list);
  343. if (rule->action == FR_ACT_GOTO)
  344. ops->nr_goto_rules--;
  345. /*
  346. * Check if this rule is a target to any of them. If so,
  347. * disable them. As this operation is eventually very
  348. * expensive, it is only performed if goto rules have
  349. * actually been added.
  350. */
  351. if (ops->nr_goto_rules > 0) {
  352. list_for_each_entry(tmp, &ops->rules_list, list) {
  353. if (tmp->ctarget == rule) {
  354. rcu_assign_pointer(tmp->ctarget, NULL);
  355. ops->unresolved_rules++;
  356. }
  357. }
  358. }
  359. synchronize_rcu();
  360. notify_rule_change(RTM_DELRULE, rule, ops, nlh,
  361. NETLINK_CB(skb).pid);
  362. fib_rule_put(rule);
  363. flush_route_cache(ops);
  364. rules_ops_put(ops);
  365. return 0;
  366. }
  367. err = -ENOENT;
  368. errout:
  369. rules_ops_put(ops);
  370. return err;
  371. }
  372. static inline size_t fib_rule_nlmsg_size(struct fib_rules_ops *ops,
  373. struct fib_rule *rule)
  374. {
  375. size_t payload = NLMSG_ALIGN(sizeof(struct fib_rule_hdr))
  376. + nla_total_size(IFNAMSIZ) /* FRA_IIFNAME */
  377. + nla_total_size(IFNAMSIZ) /* FRA_OIFNAME */
  378. + nla_total_size(4) /* FRA_PRIORITY */
  379. + nla_total_size(4) /* FRA_TABLE */
  380. + nla_total_size(4) /* FRA_FWMARK */
  381. + nla_total_size(4); /* FRA_FWMASK */
  382. if (ops->nlmsg_payload)
  383. payload += ops->nlmsg_payload(rule);
  384. return payload;
  385. }
  386. static int fib_nl_fill_rule(struct sk_buff *skb, struct fib_rule *rule,
  387. u32 pid, u32 seq, int type, int flags,
  388. struct fib_rules_ops *ops)
  389. {
  390. struct nlmsghdr *nlh;
  391. struct fib_rule_hdr *frh;
  392. nlh = nlmsg_put(skb, pid, seq, type, sizeof(*frh), flags);
  393. if (nlh == NULL)
  394. return -EMSGSIZE;
  395. frh = nlmsg_data(nlh);
  396. frh->table = rule->table;
  397. NLA_PUT_U32(skb, FRA_TABLE, rule->table);
  398. frh->res1 = 0;
  399. frh->res2 = 0;
  400. frh->action = rule->action;
  401. frh->flags = rule->flags;
  402. if (rule->action == FR_ACT_GOTO && rule->ctarget == NULL)
  403. frh->flags |= FIB_RULE_UNRESOLVED;
  404. if (rule->iifname[0]) {
  405. NLA_PUT_STRING(skb, FRA_IIFNAME, rule->iifname);
  406. if (rule->iifindex == -1)
  407. frh->flags |= FIB_RULE_IIF_DETACHED;
  408. }
  409. if (rule->oifname[0]) {
  410. NLA_PUT_STRING(skb, FRA_OIFNAME, rule->oifname);
  411. if (rule->oifindex == -1)
  412. frh->flags |= FIB_RULE_OIF_DETACHED;
  413. }
  414. if (rule->pref)
  415. NLA_PUT_U32(skb, FRA_PRIORITY, rule->pref);
  416. if (rule->mark)
  417. NLA_PUT_U32(skb, FRA_FWMARK, rule->mark);
  418. if (rule->mark_mask || rule->mark)
  419. NLA_PUT_U32(skb, FRA_FWMASK, rule->mark_mask);
  420. if (rule->target)
  421. NLA_PUT_U32(skb, FRA_GOTO, rule->target);
  422. if (ops->fill(rule, skb, frh) < 0)
  423. goto nla_put_failure;
  424. return nlmsg_end(skb, nlh);
  425. nla_put_failure:
  426. nlmsg_cancel(skb, nlh);
  427. return -EMSGSIZE;
  428. }
  429. static int dump_rules(struct sk_buff *skb, struct netlink_callback *cb,
  430. struct fib_rules_ops *ops)
  431. {
  432. int idx = 0;
  433. struct fib_rule *rule;
  434. list_for_each_entry(rule, &ops->rules_list, list) {
  435. if (idx < cb->args[1])
  436. goto skip;
  437. if (fib_nl_fill_rule(skb, rule, NETLINK_CB(cb->skb).pid,
  438. cb->nlh->nlmsg_seq, RTM_NEWRULE,
  439. NLM_F_MULTI, ops) < 0)
  440. break;
  441. skip:
  442. idx++;
  443. }
  444. cb->args[1] = idx;
  445. rules_ops_put(ops);
  446. return skb->len;
  447. }
  448. static int fib_nl_dumprule(struct sk_buff *skb, struct netlink_callback *cb)
  449. {
  450. struct net *net = sock_net(skb->sk);
  451. struct fib_rules_ops *ops;
  452. int idx = 0, family;
  453. family = rtnl_msg_family(cb->nlh);
  454. if (family != AF_UNSPEC) {
  455. /* Protocol specific dump request */
  456. ops = lookup_rules_ops(net, family);
  457. if (ops == NULL)
  458. return -EAFNOSUPPORT;
  459. return dump_rules(skb, cb, ops);
  460. }
  461. rcu_read_lock();
  462. list_for_each_entry_rcu(ops, &net->rules_ops, list) {
  463. if (idx < cb->args[0] || !try_module_get(ops->owner))
  464. goto skip;
  465. if (dump_rules(skb, cb, ops) < 0)
  466. break;
  467. cb->args[1] = 0;
  468. skip:
  469. idx++;
  470. }
  471. rcu_read_unlock();
  472. cb->args[0] = idx;
  473. return skb->len;
  474. }
  475. static void notify_rule_change(int event, struct fib_rule *rule,
  476. struct fib_rules_ops *ops, struct nlmsghdr *nlh,
  477. u32 pid)
  478. {
  479. struct net *net;
  480. struct sk_buff *skb;
  481. int err = -ENOBUFS;
  482. net = ops->fro_net;
  483. skb = nlmsg_new(fib_rule_nlmsg_size(ops, rule), GFP_KERNEL);
  484. if (skb == NULL)
  485. goto errout;
  486. err = fib_nl_fill_rule(skb, rule, pid, nlh->nlmsg_seq, event, 0, ops);
  487. if (err < 0) {
  488. /* -EMSGSIZE implies BUG in fib_rule_nlmsg_size() */
  489. WARN_ON(err == -EMSGSIZE);
  490. kfree_skb(skb);
  491. goto errout;
  492. }
  493. rtnl_notify(skb, net, pid, ops->nlgroup, nlh, GFP_KERNEL);
  494. return;
  495. errout:
  496. if (err < 0)
  497. rtnl_set_sk_err(net, ops->nlgroup, err);
  498. }
  499. static void attach_rules(struct list_head *rules, struct net_device *dev)
  500. {
  501. struct fib_rule *rule;
  502. list_for_each_entry(rule, rules, list) {
  503. if (rule->iifindex == -1 &&
  504. strcmp(dev->name, rule->iifname) == 0)
  505. rule->iifindex = dev->ifindex;
  506. if (rule->oifindex == -1 &&
  507. strcmp(dev->name, rule->oifname) == 0)
  508. rule->oifindex = dev->ifindex;
  509. }
  510. }
  511. static void detach_rules(struct list_head *rules, struct net_device *dev)
  512. {
  513. struct fib_rule *rule;
  514. list_for_each_entry(rule, rules, list) {
  515. if (rule->iifindex == dev->ifindex)
  516. rule->iifindex = -1;
  517. if (rule->oifindex == dev->ifindex)
  518. rule->oifindex = -1;
  519. }
  520. }
  521. static int fib_rules_event(struct notifier_block *this, unsigned long event,
  522. void *ptr)
  523. {
  524. struct net_device *dev = ptr;
  525. struct net *net = dev_net(dev);
  526. struct fib_rules_ops *ops;
  527. ASSERT_RTNL();
  528. rcu_read_lock();
  529. switch (event) {
  530. case NETDEV_REGISTER:
  531. list_for_each_entry(ops, &net->rules_ops, list)
  532. attach_rules(&ops->rules_list, dev);
  533. break;
  534. case NETDEV_UNREGISTER:
  535. list_for_each_entry(ops, &net->rules_ops, list)
  536. detach_rules(&ops->rules_list, dev);
  537. break;
  538. }
  539. rcu_read_unlock();
  540. return NOTIFY_DONE;
  541. }
  542. static struct notifier_block fib_rules_notifier = {
  543. .notifier_call = fib_rules_event,
  544. };
  545. static int fib_rules_net_init(struct net *net)
  546. {
  547. INIT_LIST_HEAD(&net->rules_ops);
  548. spin_lock_init(&net->rules_mod_lock);
  549. return 0;
  550. }
  551. static struct pernet_operations fib_rules_net_ops = {
  552. .init = fib_rules_net_init,
  553. };
  554. static int __init fib_rules_init(void)
  555. {
  556. int err;
  557. rtnl_register(PF_UNSPEC, RTM_NEWRULE, fib_nl_newrule, NULL);
  558. rtnl_register(PF_UNSPEC, RTM_DELRULE, fib_nl_delrule, NULL);
  559. rtnl_register(PF_UNSPEC, RTM_GETRULE, NULL, fib_nl_dumprule);
  560. err = register_pernet_subsys(&fib_rules_net_ops);
  561. if (err < 0)
  562. goto fail;
  563. err = register_netdevice_notifier(&fib_rules_notifier);
  564. if (err < 0)
  565. goto fail_unregister;
  566. return 0;
  567. fail_unregister:
  568. unregister_pernet_subsys(&fib_rules_net_ops);
  569. fail:
  570. rtnl_unregister(PF_UNSPEC, RTM_NEWRULE);
  571. rtnl_unregister(PF_UNSPEC, RTM_DELRULE);
  572. rtnl_unregister(PF_UNSPEC, RTM_GETRULE);
  573. return err;
  574. }
  575. subsys_initcall(fib_rules_init);