~ [ 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 ] ~

Diff markup

Differences between /net/l3mdev/l3mdev.c (Version linux-4.18.20) and /net/l3mdev/l3mdev.c (Version linux-5.7.19)


                                                   >>   1 // SPDX-License-Identifier: GPL-2.0-or-later
  1 /*                                                  2 /*
  2  * net/l3mdev/l3mdev.c - L3 master device impl      3  * net/l3mdev/l3mdev.c - L3 master device implementation
  3  * Copyright (c) 2015 Cumulus Networks              4  * Copyright (c) 2015 Cumulus Networks
  4  * Copyright (c) 2015 David Ahern <dsa@cumulus      5  * Copyright (c) 2015 David Ahern <dsa@cumulusnetworks.com>
  5  *                                             << 
  6  * This program is free software; you can redi << 
  7  * it under the terms of the GNU General Publi << 
  8  * the Free Software Foundation; either versio << 
  9  * (at your option) any later version.         << 
 10  */                                                 6  */
 11                                                     7 
 12 #include <linux/netdevice.h>                        8 #include <linux/netdevice.h>
 13 #include <net/fib_rules.h>                          9 #include <net/fib_rules.h>
 14 #include <net/l3mdev.h>                            10 #include <net/l3mdev.h>
 15                                                    11 
 16 /**                                                12 /**
 17  *      l3mdev_master_ifindex - get index of L     13  *      l3mdev_master_ifindex - get index of L3 master device
 18  *      @dev: targeted interface                   14  *      @dev: targeted interface
 19  */                                                15  */
 20                                                    16 
 21 int l3mdev_master_ifindex_rcu(const struct net     17 int l3mdev_master_ifindex_rcu(const struct net_device *dev)
 22 {                                                  18 {
 23         int ifindex = 0;                           19         int ifindex = 0;
 24                                                    20 
 25         if (!dev)                                  21         if (!dev)
 26                 return 0;                          22                 return 0;
 27                                                    23 
 28         if (netif_is_l3_master(dev)) {             24         if (netif_is_l3_master(dev)) {
 29                 ifindex = dev->ifindex;            25                 ifindex = dev->ifindex;
 30         } else if (netif_is_l3_slave(dev)) {       26         } else if (netif_is_l3_slave(dev)) {
 31                 struct net_device *master;         27                 struct net_device *master;
 32                 struct net_device *_dev = (str     28                 struct net_device *_dev = (struct net_device *)dev;
 33                                                    29 
 34                 /* netdev_master_upper_dev_get     30                 /* netdev_master_upper_dev_get_rcu calls
 35                  * list_first_or_null_rcu to w     31                  * list_first_or_null_rcu to walk the upper dev list.
 36                  * list_first_or_null_rcu does     32                  * list_first_or_null_rcu does not handle a const arg. We aren't
 37                  * making changes, just want t     33                  * making changes, just want the master device from that list so
 38                  * typecast to remove the cons     34                  * typecast to remove the const
 39                  */                                35                  */
 40                 master = netdev_master_upper_d     36                 master = netdev_master_upper_dev_get_rcu(_dev);
 41                 if (master)                        37                 if (master)
 42                         ifindex = master->ifin     38                         ifindex = master->ifindex;
 43         }                                          39         }
 44                                                    40 
 45         return ifindex;                            41         return ifindex;
 46 }                                                  42 }
 47 EXPORT_SYMBOL_GPL(l3mdev_master_ifindex_rcu);      43 EXPORT_SYMBOL_GPL(l3mdev_master_ifindex_rcu);
 48                                                    44 
 49 /**                                                45 /**
                                                   >>  46  *      l3mdev_master_upper_ifindex_by_index - get index of upper l3 master
                                                   >>  47  *                                             device
                                                   >>  48  *      @net: network namespace for device index lookup
                                                   >>  49  *      @ifindex: targeted interface
                                                   >>  50  */
                                                   >>  51 int l3mdev_master_upper_ifindex_by_index_rcu(struct net *net, int ifindex)
                                                   >>  52 {
                                                   >>  53         struct net_device *dev;
                                                   >>  54 
                                                   >>  55         dev = dev_get_by_index_rcu(net, ifindex);
                                                   >>  56         while (dev && !netif_is_l3_master(dev))
                                                   >>  57                 dev = netdev_master_upper_dev_get(dev);
                                                   >>  58 
                                                   >>  59         return dev ? dev->ifindex : 0;
                                                   >>  60 }
                                                   >>  61 EXPORT_SYMBOL_GPL(l3mdev_master_upper_ifindex_by_index_rcu);
                                                   >>  62 
                                                   >>  63 /**
 50  *      l3mdev_fib_table - get FIB table id as     64  *      l3mdev_fib_table - get FIB table id associated with an L3
 51  *                             master interfac     65  *                             master interface
 52  *      @dev: targeted interface                   66  *      @dev: targeted interface
 53  */                                                67  */
 54                                                    68 
 55 u32 l3mdev_fib_table_rcu(const struct net_devi     69 u32 l3mdev_fib_table_rcu(const struct net_device *dev)
 56 {                                                  70 {
 57         u32 tb_id = 0;                             71         u32 tb_id = 0;
 58                                                    72 
 59         if (!dev)                                  73         if (!dev)
 60                 return 0;                          74                 return 0;
 61                                                    75 
 62         if (netif_is_l3_master(dev)) {             76         if (netif_is_l3_master(dev)) {
 63                 if (dev->l3mdev_ops->l3mdev_fi     77                 if (dev->l3mdev_ops->l3mdev_fib_table)
 64                         tb_id = dev->l3mdev_op     78                         tb_id = dev->l3mdev_ops->l3mdev_fib_table(dev);
 65         } else if (netif_is_l3_slave(dev)) {       79         } else if (netif_is_l3_slave(dev)) {
 66                 /* Users of netdev_master_uppe     80                 /* Users of netdev_master_upper_dev_get_rcu need non-const,
 67                  * but current inet_*type func     81                  * but current inet_*type functions take a const
 68                  */                                82                  */
 69                 struct net_device *_dev = (str     83                 struct net_device *_dev = (struct net_device *) dev;
 70                 const struct net_device *maste     84                 const struct net_device *master;
 71                                                    85 
 72                 master = netdev_master_upper_d     86                 master = netdev_master_upper_dev_get_rcu(_dev);
 73                 if (master &&                      87                 if (master &&
 74                     master->l3mdev_ops->l3mdev     88                     master->l3mdev_ops->l3mdev_fib_table)
 75                         tb_id = master->l3mdev     89                         tb_id = master->l3mdev_ops->l3mdev_fib_table(master);
 76         }                                          90         }
 77                                                    91 
 78         return tb_id;                              92         return tb_id;
 79 }                                                  93 }
 80 EXPORT_SYMBOL_GPL(l3mdev_fib_table_rcu);           94 EXPORT_SYMBOL_GPL(l3mdev_fib_table_rcu);
 81                                                    95 
 82 u32 l3mdev_fib_table_by_index(struct net *net,     96 u32 l3mdev_fib_table_by_index(struct net *net, int ifindex)
 83 {                                                  97 {
 84         struct net_device *dev;                    98         struct net_device *dev;
 85         u32 tb_id = 0;                             99         u32 tb_id = 0;
 86                                                   100 
 87         if (!ifindex)                             101         if (!ifindex)
 88                 return 0;                         102                 return 0;
 89                                                   103 
 90         rcu_read_lock();                          104         rcu_read_lock();
 91                                                   105 
 92         dev = dev_get_by_index_rcu(net, ifinde    106         dev = dev_get_by_index_rcu(net, ifindex);
 93         if (dev)                                  107         if (dev)
 94                 tb_id = l3mdev_fib_table_rcu(d    108                 tb_id = l3mdev_fib_table_rcu(dev);
 95                                                   109 
 96         rcu_read_unlock();                        110         rcu_read_unlock();
 97                                                   111 
 98         return tb_id;                             112         return tb_id;
 99 }                                                 113 }
100 EXPORT_SYMBOL_GPL(l3mdev_fib_table_by_index);     114 EXPORT_SYMBOL_GPL(l3mdev_fib_table_by_index);
101                                                   115 
102 /**                                               116 /**
103  *      l3mdev_link_scope_lookup - IPv6 route     117  *      l3mdev_link_scope_lookup - IPv6 route lookup based on flow for link
104  *                           local and multica    118  *                           local and multicast addresses
105  *      @net: network namespace for device ind    119  *      @net: network namespace for device index lookup
106  *      @fl6: IPv6 flow struct for lookup         120  *      @fl6: IPv6 flow struct for lookup
                                                   >> 121  *      This function does not hold refcnt on the returned dst.
                                                   >> 122  *      Caller must hold rcu_read_lock().
107  */                                               123  */
108                                                   124 
109 struct dst_entry *l3mdev_link_scope_lookup(str    125 struct dst_entry *l3mdev_link_scope_lookup(struct net *net,
110                                            str    126                                            struct flowi6 *fl6)
111 {                                                 127 {
112         struct dst_entry *dst = NULL;             128         struct dst_entry *dst = NULL;
113         struct net_device *dev;                   129         struct net_device *dev;
114                                                   130 
                                                   >> 131         WARN_ON_ONCE(!rcu_read_lock_held());
115         if (fl6->flowi6_oif) {                    132         if (fl6->flowi6_oif) {
116                 rcu_read_lock();               << 
117                                                << 
118                 dev = dev_get_by_index_rcu(net    133                 dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
119                 if (dev && netif_is_l3_slave(d    134                 if (dev && netif_is_l3_slave(dev))
120                         dev = netdev_master_up    135                         dev = netdev_master_upper_dev_get_rcu(dev);
121                                                   136 
122                 if (dev && netif_is_l3_master(    137                 if (dev && netif_is_l3_master(dev) &&
123                     dev->l3mdev_ops->l3mdev_li    138                     dev->l3mdev_ops->l3mdev_link_scope_lookup)
124                         dst = dev->l3mdev_ops-    139                         dst = dev->l3mdev_ops->l3mdev_link_scope_lookup(dev, fl6);
125                                                << 
126                 rcu_read_unlock();             << 
127         }                                         140         }
128                                                   141 
129         return dst;                               142         return dst;
130 }                                                 143 }
131 EXPORT_SYMBOL_GPL(l3mdev_link_scope_lookup);      144 EXPORT_SYMBOL_GPL(l3mdev_link_scope_lookup);
132                                                   145 
133 /**                                               146 /**
134  *      l3mdev_fib_rule_match - Determine if f    147  *      l3mdev_fib_rule_match - Determine if flowi references an
135  *                              L3 master devi    148  *                              L3 master device
136  *      @net: network namespace for device ind    149  *      @net: network namespace for device index lookup
137  *      @fl:  flow struct                         150  *      @fl:  flow struct
138  */                                               151  */
139                                                   152 
140 int l3mdev_fib_rule_match(struct net *net, str    153 int l3mdev_fib_rule_match(struct net *net, struct flowi *fl,
141                           struct fib_lookup_ar    154                           struct fib_lookup_arg *arg)
142 {                                                 155 {
143         struct net_device *dev;                   156         struct net_device *dev;
144         int rc = 0;                               157         int rc = 0;
145                                                   158 
146         rcu_read_lock();                          159         rcu_read_lock();
147                                                   160 
148         dev = dev_get_by_index_rcu(net, fl->fl    161         dev = dev_get_by_index_rcu(net, fl->flowi_oif);
149         if (dev && netif_is_l3_master(dev) &&     162         if (dev && netif_is_l3_master(dev) &&
150             dev->l3mdev_ops->l3mdev_fib_table)    163             dev->l3mdev_ops->l3mdev_fib_table) {
151                 arg->table = dev->l3mdev_ops->    164                 arg->table = dev->l3mdev_ops->l3mdev_fib_table(dev);
152                 rc = 1;                           165                 rc = 1;
153                 goto out;                         166                 goto out;
154         }                                         167         }
155                                                   168 
156         dev = dev_get_by_index_rcu(net, fl->fl    169         dev = dev_get_by_index_rcu(net, fl->flowi_iif);
157         if (dev && netif_is_l3_master(dev) &&     170         if (dev && netif_is_l3_master(dev) &&
158             dev->l3mdev_ops->l3mdev_fib_table)    171             dev->l3mdev_ops->l3mdev_fib_table) {
159                 arg->table = dev->l3mdev_ops->    172                 arg->table = dev->l3mdev_ops->l3mdev_fib_table(dev);
160                 rc = 1;                           173                 rc = 1;
161                 goto out;                         174                 goto out;
162         }                                         175         }
163                                                   176 
164 out:                                              177 out:
165         rcu_read_unlock();                        178         rcu_read_unlock();
166                                                   179 
167         return rc;                                180         return rc;
168 }                                                 181 }
169                                                   182 
170 void l3mdev_update_flow(struct net *net, struc    183 void l3mdev_update_flow(struct net *net, struct flowi *fl)
171 {                                                 184 {
172         struct net_device *dev;                   185         struct net_device *dev;
173         int ifindex;                              186         int ifindex;
174                                                   187 
175         rcu_read_lock();                          188         rcu_read_lock();
176                                                   189 
177         if (fl->flowi_oif) {                      190         if (fl->flowi_oif) {
178                 dev = dev_get_by_index_rcu(net    191                 dev = dev_get_by_index_rcu(net, fl->flowi_oif);
179                 if (dev) {                        192                 if (dev) {
180                         ifindex = l3mdev_maste    193                         ifindex = l3mdev_master_ifindex_rcu(dev);
181                         if (ifindex) {            194                         if (ifindex) {
182                                 fl->flowi_oif     195                                 fl->flowi_oif = ifindex;
183                                 fl->flowi_flag    196                                 fl->flowi_flags |= FLOWI_FLAG_SKIP_NH_OIF;
184                                 goto out;         197                                 goto out;
185                         }                         198                         }
186                 }                                 199                 }
187         }                                         200         }
188                                                   201 
189         if (fl->flowi_iif) {                      202         if (fl->flowi_iif) {
190                 dev = dev_get_by_index_rcu(net    203                 dev = dev_get_by_index_rcu(net, fl->flowi_iif);
191                 if (dev) {                        204                 if (dev) {
192                         ifindex = l3mdev_maste    205                         ifindex = l3mdev_master_ifindex_rcu(dev);
193                         if (ifindex) {            206                         if (ifindex) {
194                                 fl->flowi_iif     207                                 fl->flowi_iif = ifindex;
195                                 fl->flowi_flag    208                                 fl->flowi_flags |= FLOWI_FLAG_SKIP_NH_OIF;
196                         }                         209                         }
197                 }                                 210                 }
198         }                                         211         }
199                                                   212 
200 out:                                              213 out:
201         rcu_read_unlock();                        214         rcu_read_unlock();
202 }                                                 215 }
203 EXPORT_SYMBOL_GPL(l3mdev_update_flow);            216 EXPORT_SYMBOL_GPL(l3mdev_update_flow);
204                                                   217 

~ [ 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