cregit-Linux how code gets into the kernel

Release 4.8 net/ipv6/fib6_rules.c

Directory: net/ipv6
/*
 * net/ipv6/fib6_rules.c        IPv6 Routing Policy Rules
 *
 * Copyright (C)2003-2006 Helsinki University of Technology
 * Copyright (C)2003-2006 USAGI/WIDE Project
 *
 *      This program is free software; you can redistribute it and/or
 *      modify it under the terms of the GNU General Public License as
 *      published by the Free Software Foundation, version 2.
 *
 * Authors
 *      Thomas Graf             <tgraf@suug.ch>
 *      Ville Nuorvala          <vnuorval@tcs.hut.fi>
 */

#include <linux/netdevice.h>
#include <linux/export.h>

#include <net/fib_rules.h>
#include <net/ipv6.h>
#include <net/addrconf.h>
#include <net/ip6_route.h>
#include <net/netlink.h>


struct fib6_rule {
	
struct fib_rule		common;
	
struct rt6key		src;
	
struct rt6key		dst;
	
u8			tclass;
};


struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi6 *fl6, int flags, pol_lookup_t lookup) { struct rt6_info *rt; struct fib_lookup_arg arg = { .lookup_ptr = lookup, .flags = FIB_LOOKUP_NOREF, }; fib_rules_lookup(net->ipv6.fib6_rules_ops, flowi6_to_flowi(fl6), flags, &arg); rt = arg.result; if (!rt) { dst_hold(&net->ipv6.ip6_null_entry->dst); return &net->ipv6.ip6_null_entry->dst; } if (rt->rt6i_flags & RTF_REJECT && rt->dst.error == -EAGAIN) { ip6_rt_put(rt); rt = net->ipv6.ip6_null_entry; dst_hold(&rt->dst); } return &rt->dst; }

Contributors

PersonTokensPropCommitsCommitProp
lucien xinlucien xin6041.67%111.11%
thomas grafthomas graf4027.78%111.11%
daniel lezcanodaniel lezcano1913.19%444.44%
ville nuorvalaville nuorvala149.72%111.11%
david s. millerdavid s. miller64.17%111.11%
eric dumazeteric dumazet53.47%111.11%
Total144100.00%9100.00%


static int fib6_rule_action(struct fib_rule *rule, struct flowi *flp, int flags, struct fib_lookup_arg *arg) { struct flowi6 *flp6 = &flp->u.ip6; struct rt6_info *rt = NULL; struct fib6_table *table; struct net *net = rule->fr_net; pol_lookup_t lookup = arg->lookup_ptr; int err = 0; u32 tb_id; switch (rule->action) { case FR_ACT_TO_TBL: break; case FR_ACT_UNREACHABLE: err = -ENETUNREACH; rt = net->ipv6.ip6_null_entry; goto discard_pkt; default: case FR_ACT_BLACKHOLE: err = -EINVAL; rt = net->ipv6.ip6_blk_hole_entry; goto discard_pkt; case FR_ACT_PROHIBIT: err = -EACCES; rt = net->ipv6.ip6_prohibit_entry; goto discard_pkt; } tb_id = fib_rule_get_table(rule, arg); table = fib6_get_table(net, tb_id); if (!table) { err = -EAGAIN; goto out; } rt = lookup(net, table, flp6, flags); if (rt != net->ipv6.ip6_null_entry) { struct fib6_rule *r = (struct fib6_rule *)rule; /* * If we need to find a source address for this traffic, * we check the result if it meets requirement of the rule. */ if ((rule->flags & FIB_RULE_FIND_SADDR) && r->src.plen && !(flags & RT6_LOOKUP_F_HAS_SADDR)) { struct in6_addr saddr; if (ipv6_dev_get_saddr(net, ip6_dst_idev(&rt->dst)->dev, &flp6->daddr, rt6_flags2srcprefs(flags), &saddr)) goto again; if (!ipv6_prefix_equal(&saddr, &r->src.addr, r->src.plen)) goto again; flp6->saddr = saddr; } err = rt->dst.error; goto out; } again: ip6_rt_put(rt); err = -EAGAIN; rt = NULL; goto out; discard_pkt: dst_hold(&rt->dst); out: arg->result = rt; return err; }

Contributors

PersonTokensPropCommitsCommitProp
thomas grafthomas graf13838.66%16.25%
hideaki yoshifujihideaki yoshifuji10328.85%425.00%
hannes frederic sowahannes frederic sowa3710.36%16.25%
daniel lezcanodaniel lezcano298.12%212.50%
david s. millerdavid s. miller174.76%16.25%
david aherndavid ahern133.64%16.25%
steven barthsteven barth82.24%16.25%
patrick mchardypatrick mchardy71.96%16.25%
brian haleybrian haley20.56%16.25%
adrian bunkadrian bunk10.28%16.25%
americo wangamerico wang10.28%16.25%
alexey dobriyanalexey dobriyan10.28%16.25%
Total357100.00%16100.00%


static bool fib6_rule_suppress(struct fib_rule *rule, struct fib_lookup_arg *arg) { struct rt6_info *rt = (struct rt6_info *) arg->result; struct net_device *dev = NULL; if (rt->rt6i_idev) dev = rt->rt6i_idev->dev; /* do not accept result if the route does * not meet the required prefix length */ if (rt->rt6i_dst.plen <= rule->suppress_prefixlen) goto suppress_route; /* do not accept result if the route uses a device * belonging to a forbidden interface group */ if (rule->suppress_ifgroup != -1 && dev && dev->group == rule->suppress_ifgroup) goto suppress_route; return false; suppress_route: ip6_rt_put(rt); return true; }

Contributors

PersonTokensPropCommitsCommitProp
stefan tomanekstefan tomanek103100.00%4100.00%
Total103100.00%4100.00%


static int fib6_rule_match(struct fib_rule *rule, struct flowi *fl, int flags) { struct fib6_rule *r = (struct fib6_rule *) rule; struct flowi6 *fl6 = &fl->u.ip6; if (r->dst.plen && !ipv6_prefix_equal(&fl6->daddr, &r->dst.addr, r->dst.plen)) return 0; /* * If FIB_RULE_FIND_SADDR is set and we do not have a * source address for the traffic, we defer check for * source address. */ if (r->src.plen) { if (flags & RT6_LOOKUP_F_HAS_SADDR) { if (!ipv6_prefix_equal(&fl6->saddr, &r->src.addr, r->src.plen)) return 0; } else if (!(r->common.flags & FIB_RULE_FIND_SADDR)) return 0; } if (r->tclass && r->tclass != ip6_tclass(fl6->flowlabel)) return 0; return 1; }

Contributors

PersonTokensPropCommitsCommitProp
thomas grafthomas graf10262.96%228.57%
hideaki yoshifujihideaki yoshifuji4125.31%342.86%
david s. millerdavid s. miller1811.11%114.29%
li rongqingli rongqing10.62%114.29%
Total162100.00%7100.00%

static const struct nla_policy fib6_rule_policy[FRA_MAX+1] = { FRA_GENERIC_POLICY, };
static int fib6_rule_configure(struct fib_rule *rule, struct sk_buff *skb, struct fib_rule_hdr *frh, struct nlattr **tb) { int err = -EINVAL; struct net *net = sock_net(skb->sk); struct fib6_rule *rule6 = (struct fib6_rule *) rule; if (rule->action == FR_ACT_TO_TBL && !rule->l3mdev) { if (rule->table == RT6_TABLE_UNSPEC) goto errout; if (fib6_new_table(net, rule->table) == NULL) { err = -ENOBUFS; goto errout; } } if (frh->src_len) rule6->src.addr = nla_get_in6_addr(tb[FRA_SRC]); if (frh->dst_len) rule6->dst.addr = nla_get_in6_addr(tb[FRA_DST]); rule6->src.plen = frh->src_len; rule6->dst.plen = frh->dst_len; rule6->tclass = frh->tos; err = 0; errout: return err; }

Contributors

PersonTokensPropCommitsCommitProp
thomas grafthomas graf15886.34%228.57%
daniel lezcanodaniel lezcano116.01%228.57%
jiri bencjiri benc63.28%114.29%
david aherndavid ahern52.73%114.29%
hideaki yoshifujihideaki yoshifuji31.64%114.29%
Total183100.00%7100.00%


static int fib6_rule_compare(struct fib_rule *rule, struct fib_rule_hdr *frh, struct nlattr **tb) { struct fib6_rule *rule6 = (struct fib6_rule *) rule; if (frh->src_len && (rule6->src.plen != frh->src_len)) return 0; if (frh->dst_len && (rule6->dst.plen != frh->dst_len)) return 0; if (frh->tos && (rule6->tclass != frh->tos)) return 0; if (frh->src_len && nla_memcmp(tb[FRA_SRC], &rule6->src.addr, sizeof(struct in6_addr))) return 0; if (frh->dst_len && nla_memcmp(tb[FRA_DST], &rule6->dst.addr, sizeof(struct in6_addr))) return 0; return 1; }

Contributors

PersonTokensPropCommitsCommitProp
thomas grafthomas graf158100.00%2100.00%
Total158100.00%2100.00%


static int fib6_rule_fill(struct fib_rule *rule, struct sk_buff *skb, struct fib_rule_hdr *frh) { struct fib6_rule *rule6 = (struct fib6_rule *) rule; frh->dst_len = rule6->dst.plen; frh->src_len = rule6->src.plen; frh->tos = rule6->tclass; if ((rule6->dst.plen && nla_put_in6_addr(skb, FRA_DST, &rule6->dst.addr)) || (rule6->src.plen && nla_put_in6_addr(skb, FRA_SRC, &rule6->src.addr))) goto nla_put_failure; return 0; nla_put_failure: return -ENOBUFS; }

Contributors

PersonTokensPropCommitsCommitProp
thomas grafthomas graf10689.08%133.33%
david s. millerdavid s. miller119.24%133.33%
jiri bencjiri benc21.68%133.33%
Total119100.00%3100.00%


static size_t fib6_rule_nlmsg_payload(struct fib_rule *rule) { return nla_total_size(16) /* dst */ + nla_total_size(16); /* src */ }

Contributors

PersonTokensPropCommitsCommitProp
thomas grafthomas graf24100.00%1100.00%
Total24100.00%1100.00%

static const struct fib_rules_ops __net_initconst fib6_rules_ops_template = { .family = AF_INET6, .rule_size = sizeof(struct fib6_rule), .addr_size = sizeof(struct in6_addr), .action = fib6_rule_action, .match = fib6_rule_match, .suppress = fib6_rule_suppress, .configure = fib6_rule_configure, .compare = fib6_rule_compare, .fill = fib6_rule_fill, .nlmsg_payload = fib6_rule_nlmsg_payload, .nlgroup = RTNLGRP_IPV6_RULE, .policy = fib6_rule_policy, .owner = THIS_MODULE, .fro_net = &init_net, };
static int __net_init fib6_rules_net_init(struct net *net) { struct fib_rules_ops *ops; int err = -ENOMEM; ops = fib_rules_register(&fib6_rules_ops_template, net); if (IS_ERR(ops)) return PTR_ERR(ops); err = fib_default_rule_add(ops, 0, RT6_TABLE_LOCAL, 0); if (err) goto out_fib6_rules_ops; err = fib_default_rule_add(ops, 0x7FFE, RT6_TABLE_MAIN, 0); if (err) goto out_fib6_rules_ops; net->ipv6.fib6_rules_ops = ops; out: return err; out_fib6_rules_ops: fib_rules_unregister(ops); goto out; }

Contributors

PersonTokensPropCommitsCommitProp
daniel lezcanodaniel lezcano3935.78%333.33%
denis v. lunevdenis v. lunev3128.44%111.11%
eric w. biedermaneric w. biederman1917.43%111.11%
americo wangamerico wang109.17%111.11%
thomas grafthomas graf87.34%111.11%
patrick mchardypatrick mchardy10.92%111.11%
alexey dobriyanalexey dobriyan10.92%111.11%
Total109100.00%9100.00%


static void __net_exit fib6_rules_net_exit(struct net *net) { rtnl_lock(); fib_rules_unregister(net->ipv6.fib6_rules_ops); rtnl_unlock(); }

Contributors

PersonTokensPropCommitsCommitProp
daniel lezcanodaniel lezcano1348.15%240.00%
thomas grafthomas graf725.93%120.00%
americo wangamerico wang622.22%120.00%
alexey dobriyanalexey dobriyan13.70%120.00%
Total27100.00%5100.00%

static struct pernet_operations fib6_rules_net_ops = { .init = fib6_rules_net_init, .exit = fib6_rules_net_exit, };
int __init fib6_rules_init(void) { return register_pernet_subsys(&fib6_rules_net_ops); }

Contributors

PersonTokensPropCommitsCommitProp
daniel lezcanodaniel lezcano15100.00%1100.00%
Total15100.00%1100.00%


void fib6_rules_cleanup(void) { unregister_pernet_subsys(&fib6_rules_net_ops); }

Contributors

PersonTokensPropCommitsCommitProp
daniel lezcanodaniel lezcano1292.31%150.00%
hideaki yoshifujihideaki yoshifuji17.69%150.00%
Total13100.00%2100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
thomas grafthomas graf86354.76%59.62%
daniel lezcanodaniel lezcano1569.90%611.54%
hideaki yoshifujihideaki yoshifuji1529.64%917.31%
stefan tomanekstefan tomanek1086.85%47.69%
lucien xinlucien xin603.81%11.92%
david s. millerdavid s. miller523.30%23.85%
denis v. lunevdenis v. lunev372.35%23.85%
hannes frederic sowahannes frederic sowa372.35%11.92%
eric w. biedermaneric w. biederman191.21%11.92%
david aherndavid ahern181.14%11.92%
americo wangamerico wang171.08%35.77%
ville nuorvalaville nuorvala140.89%11.92%
patrick mchardypatrick mchardy110.70%59.62%
steven barthsteven barth80.51%11.92%
jiri bencjiri benc80.51%23.85%
eric dumazeteric dumazet50.32%11.92%
paul gortmakerpaul gortmaker30.19%11.92%
alexey dobriyanalexey dobriyan30.19%23.85%
brian haleybrian haley20.13%11.92%
adrian bunkadrian bunk10.06%11.92%
li rongqingli rongqing10.06%11.92%
andi kleenandi kleen10.06%11.92%
Total1576100.00%52100.00%
Directory: net/ipv6
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.