~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/l3mdev/l3mdev.c

Version: ~ [ linux-5.13-rc7 ] ~ [ linux-5.12.12 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.45 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.127 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.195 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.237 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.273 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.273 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * net/l3mdev/l3mdev.c - L3 master device implementation
  3  * Copyright (c) 2015 Cumulus Networks
  4  * Copyright (c) 2015 David Ahern <dsa@cumulusnetworks.com>
  5  *
  6  * This program is free software; you can redistribute it and/or modify
  7  * it under the terms of the GNU General Public License as published by
  8  * the Free Software Foundation; either version 2 of the License, or
  9  * (at your option) any later version.
 10  */
 11 
 12 #include <linux/netdevice.h>
 13 #include <net/l3mdev.h>
 14 
 15 /**
 16  *      l3mdev_master_ifindex - get index of L3 master device
 17  *      @dev: targeted interface
 18  */
 19 
 20 int l3mdev_master_ifindex_rcu(const struct net_device *dev)
 21 {
 22         int ifindex = 0;
 23 
 24         if (!dev)
 25                 return 0;
 26 
 27         if (netif_is_l3_master(dev)) {
 28                 ifindex = dev->ifindex;
 29         } else if (netif_is_l3_slave(dev)) {
 30                 struct net_device *master;
 31                 struct net_device *_dev = (struct net_device *)dev;
 32 
 33                 /* netdev_master_upper_dev_get_rcu calls
 34                  * list_first_or_null_rcu to walk the upper dev list.
 35                  * list_first_or_null_rcu does not handle a const arg. We aren't
 36                  * making changes, just want the master device from that list so
 37                  * typecast to remove the const
 38                  */
 39                 master = netdev_master_upper_dev_get_rcu(_dev);
 40                 if (master)
 41                         ifindex = master->ifindex;
 42         }
 43 
 44         return ifindex;
 45 }
 46 EXPORT_SYMBOL_GPL(l3mdev_master_ifindex_rcu);
 47 
 48 /**
 49  *      l3mdev_fib_table - get FIB table id associated with an L3
 50  *                             master interface
 51  *      @dev: targeted interface
 52  */
 53 
 54 u32 l3mdev_fib_table_rcu(const struct net_device *dev)
 55 {
 56         u32 tb_id = 0;
 57 
 58         if (!dev)
 59                 return 0;
 60 
 61         if (netif_is_l3_master(dev)) {
 62                 if (dev->l3mdev_ops->l3mdev_fib_table)
 63                         tb_id = dev->l3mdev_ops->l3mdev_fib_table(dev);
 64         } else if (netif_is_l3_slave(dev)) {
 65                 /* Users of netdev_master_upper_dev_get_rcu need non-const,
 66                  * but current inet_*type functions take a const
 67                  */
 68                 struct net_device *_dev = (struct net_device *) dev;
 69                 const struct net_device *master;
 70 
 71                 master = netdev_master_upper_dev_get_rcu(_dev);
 72                 if (master &&
 73                     master->l3mdev_ops->l3mdev_fib_table)
 74                         tb_id = master->l3mdev_ops->l3mdev_fib_table(master);
 75         }
 76 
 77         return tb_id;
 78 }
 79 EXPORT_SYMBOL_GPL(l3mdev_fib_table_rcu);
 80 
 81 u32 l3mdev_fib_table_by_index(struct net *net, int ifindex)
 82 {
 83         struct net_device *dev;
 84         u32 tb_id = 0;
 85 
 86         if (!ifindex)
 87                 return 0;
 88 
 89         rcu_read_lock();
 90 
 91         dev = dev_get_by_index_rcu(net, ifindex);
 92         if (dev)
 93                 tb_id = l3mdev_fib_table_rcu(dev);
 94 
 95         rcu_read_unlock();
 96 
 97         return tb_id;
 98 }
 99 EXPORT_SYMBOL_GPL(l3mdev_fib_table_by_index);
100 
101 /**
102  *      l3mdev_get_rt6_dst - IPv6 route lookup based on flow. Returns
103  *                           cached route for L3 master device if relevant
104  *                           to flow
105  *      @net: network namespace for device index lookup
106  *      @fl6: IPv6 flow struct for lookup
107  */
108 
109 struct dst_entry *l3mdev_get_rt6_dst(struct net *net,
110                                      const struct flowi6 *fl6)
111 {
112         struct dst_entry *dst = NULL;
113         struct net_device *dev;
114 
115         if (fl6->flowi6_oif) {
116                 rcu_read_lock();
117 
118                 dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
119                 if (dev && netif_is_l3_slave(dev))
120                         dev = netdev_master_upper_dev_get_rcu(dev);
121 
122                 if (dev && netif_is_l3_master(dev) &&
123                     dev->l3mdev_ops->l3mdev_get_rt6_dst)
124                         dst = dev->l3mdev_ops->l3mdev_get_rt6_dst(dev, fl6);
125 
126                 rcu_read_unlock();
127         }
128 
129         return dst;
130 }
131 EXPORT_SYMBOL_GPL(l3mdev_get_rt6_dst);
132 
133 /**
134  *      l3mdev_get_saddr - get source address for a flow based on an interface
135  *                         enslaved to an L3 master device
136  *      @net: network namespace for device index lookup
137  *      @ifindex: Interface index
138  *      @fl4: IPv4 flow struct
139  */
140 
141 int l3mdev_get_saddr(struct net *net, int ifindex, struct flowi4 *fl4)
142 {
143         struct net_device *dev;
144         int rc = 0;
145 
146         if (ifindex) {
147                 rcu_read_lock();
148 
149                 dev = dev_get_by_index_rcu(net, ifindex);
150                 if (dev && netif_is_l3_slave(dev))
151                         dev = netdev_master_upper_dev_get_rcu(dev);
152 
153                 if (dev && netif_is_l3_master(dev) &&
154                     dev->l3mdev_ops->l3mdev_get_saddr)
155                         rc = dev->l3mdev_ops->l3mdev_get_saddr(dev, fl4);
156 
157                 rcu_read_unlock();
158         }
159 
160         return rc;
161 }
162 EXPORT_SYMBOL_GPL(l3mdev_get_saddr);
163 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp