/* * vrf.c: device driver to encapsulate a VRF space * * Copyright (c) 2015 Cumulus Networks. All rights reserved. * Copyright (c) 2015 Shrijeet Mukherjee <shm@cumulusnetworks.com> * Copyright (c) 2015 David Ahern <dsa@cumulusnetworks.com> * * Based on dummy, team and ipvlan drivers * * 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; either version 2 of the License, or * (at your option) any later version. */#include<linux/module.h>#include<linux/kernel.h>#include<linux/netdevice.h>#include<linux/etherdevice.h>#include<linux/ip.h>#include<linux/init.h>#include<linux/moduleparam.h>#include<linux/netfilter.h>#include<linux/rtnetlink.h>#include<net/rtnetlink.h>#include<linux/u64_stats_sync.h>#include<linux/hashtable.h>#include<linux/inetdevice.h>#include<net/arp.h>#include<net/ip.h>#include<net/ip_fib.h>#include<net/ip6_fib.h>#include<net/ip6_route.h>#include<net/route.h>#include<net/addrconf.h>#include<net/l3mdev.h>#include<net/fib_rules.h>#define DRV_NAME "vrf"#define DRV_VERSION "1.0"#define FIB_RULE_PREF 1000 /* default preference for FIB rules */staticbooladd_fib_rules=true;structnet_vrf{structrtable__rcu*rth;structrtable__rcu*rth_local;structrt6_info__rcu*rt6;structrt6_info__rcu*rt6_local;u32tb_id;};structpcpu_dstats{u64tx_pkts;u64tx_bytes;u64tx_drps;u64rx_pkts;u64rx_bytes;u64rx_drps;structu64_stats_syncsyncp;};staticvoidvrf_rx_stats(structnet_device*dev,intlen){structpcpu_dstats*dstats=this_cpu_ptr(dev->dstats);u64_stats_update_begin(&dstats->syncp);dstats->rx_pkts++;dstats->rx_bytes+=len;u64_stats_update_end(&dstats->syncp);}staticvoidvrf_tx_error(structnet_device*vrf_dev,structsk_buff*skb){vrf_dev->stats.tx_errors++;kfree_skb(skb);}staticvoid