Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Murat Sezgin | ed9c1c6 | 2017-07-14 16:57:23 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2018 The Linux Foundation. All rights reserved. |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4 | * Permission to use, copy, modify, and/or distribute this software for |
| 5 | * any purpose with or without fee is hereby granted, provided that the |
| 6 | * above copyright notice and this permission notice appear in all copies. |
| 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 10 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 12 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 13 | * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 14 | ************************************************************************** |
| 15 | */ |
| 16 | |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 17 | #include <linux/version.h> |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 18 | #include <linux/types.h> |
| 19 | #include <linux/ip.h> |
| 20 | #include <linux/tcp.h> |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/skbuff.h> |
| 23 | #include <linux/icmp.h> |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 24 | #include <linux/kthread.h> |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 25 | #include <linux/pkt_sched.h> |
| 26 | #include <linux/string.h> |
| 27 | #include <net/ip6_route.h> |
| 28 | #include <net/ip6_fib.h> |
| 29 | #include <net/ipv6.h> |
| 30 | #include <net/route.h> |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 31 | #include <net/ip_fib.h> |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 32 | #include <net/ip.h> |
| 33 | #include <net/tcp.h> |
| 34 | #include <asm/unaligned.h> |
| 35 | #include <asm/uaccess.h> /* for put_user */ |
| 36 | #include <linux/inet.h> |
| 37 | #include <linux/in6.h> |
| 38 | #include <linux/in.h> |
| 39 | #include <linux/udp.h> |
| 40 | #include <linux/tcp.h> |
Murat Sezgin | a205b04 | 2016-07-19 14:18:14 -0700 | [diff] [blame] | 41 | #include <linux/kernel.h> |
| 42 | #include <linux/netlink.h> |
| 43 | #include <linux/rtnetlink.h> |
| 44 | #include <linux/socket.h> |
| 45 | #include <linux/wireless.h> |
| 46 | |
Murat Sezgin | 8c34582 | 2015-05-27 15:35:38 -0700 | [diff] [blame] | 47 | #if defined(ECM_DB_XREF_ENABLE) && defined(ECM_BAND_STEERING_ENABLE) |
ratheesh kannoth | 37e35b0 | 2015-03-26 11:25:02 +0530 | [diff] [blame] | 48 | #include <linux/if_bridge.h> |
Murat Sezgin | 8c34582 | 2015-05-27 15:35:38 -0700 | [diff] [blame] | 49 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 50 | #include <linux/inetdevice.h> |
Murat Sezgin | c140256 | 2015-03-12 12:32:20 -0700 | [diff] [blame] | 51 | #if defined(ECM_INTERFACE_TUNIPIP6_ENABLE) || defined(ECM_INTERFACE_SIT_ENABLE) |
Tushar Mathur | 39f63f6 | 2015-06-19 14:31:14 +0530 | [diff] [blame] | 52 | #if (LINUX_VERSION_CODE <= KERNEL_VERSION(3, 9, 0)) |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 53 | #include <net/ipip.h> |
Tushar Mathur | 39f63f6 | 2015-06-19 14:31:14 +0530 | [diff] [blame] | 54 | #else |
| 55 | #include <net/ip_tunnels.h> |
| 56 | #endif |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 57 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 58 | #include <net/ip6_tunnel.h> |
Gareth Williams | 43fc085 | 2014-05-26 19:10:00 +0100 | [diff] [blame] | 59 | #include <net/addrconf.h> |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 60 | #include <linux/if_arp.h> |
| 61 | #include <linux/netfilter_ipv4.h> |
| 62 | #include <linux/netfilter_bridge.h> |
| 63 | #include <linux/if_bridge.h> |
| 64 | #include <net/arp.h> |
| 65 | #include <net/netfilter/nf_conntrack.h> |
| 66 | #include <net/netfilter/nf_conntrack_acct.h> |
| 67 | #include <net/netfilter/nf_conntrack_helper.h> |
| 68 | #include <net/netfilter/nf_conntrack_l4proto.h> |
| 69 | #include <net/netfilter/nf_conntrack_l3proto.h> |
| 70 | #include <net/netfilter/nf_conntrack_zones.h> |
| 71 | #include <net/netfilter/nf_conntrack_core.h> |
ratheesh kannoth | a6d2595 | 2016-04-11 12:23:26 +0530 | [diff] [blame] | 72 | #include <linux/netfilter_ipv6/ip6_tables.h> |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 73 | #include <net/netfilter/ipv4/nf_conntrack_ipv4.h> |
| 74 | #include <net/netfilter/ipv4/nf_defrag_ipv4.h> |
Gareth Williams | 141d238 | 2014-11-25 11:35:19 -0800 | [diff] [blame] | 75 | #ifdef ECM_INTERFACE_VLAN_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 76 | #include <linux/../../net/8021q/vlan.h> |
| 77 | #include <linux/if_vlan.h> |
Gareth Williams | 141d238 | 2014-11-25 11:35:19 -0800 | [diff] [blame] | 78 | #endif |
Murat Sezgin | a683edd | 2015-01-20 10:48:30 -0800 | [diff] [blame] | 79 | #ifdef ECM_INTERFACE_PPP_ENABLE |
| 80 | #include <linux/if_pppox.h> |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 81 | #ifdef ECM_INTERFACE_L2TPV2_ENABLE |
ratheesh kannoth | 08b8e44 | 2015-10-02 00:24:55 +0530 | [diff] [blame] | 82 | #include <linux/if_pppol2tp.h> |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 83 | #endif |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 84 | #ifdef ECM_INTERFACE_PPTP_ENABLE |
| 85 | #include <linux/netfilter/nf_conntrack_proto_gre.h> |
| 86 | #endif |
Murat Sezgin | a683edd | 2015-01-20 10:48:30 -0800 | [diff] [blame] | 87 | #endif |
ratheesh kannoth | cfdcb33 | 2015-12-24 07:19:18 +0530 | [diff] [blame] | 88 | #ifdef ECM_INTERFACE_MAP_T_ENABLE |
| 89 | #include <nat46-core.h> |
| 90 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 91 | |
| 92 | /* |
| 93 | * Debug output levels |
| 94 | * 0 = OFF |
| 95 | * 1 = ASSERTS / ERRORS |
| 96 | * 2 = 1 + WARN |
| 97 | * 3 = 2 + INFO |
| 98 | * 4 = 3 + TRACE |
| 99 | */ |
| 100 | #define DEBUG_LEVEL ECM_INTERFACE_DEBUG_LEVEL |
| 101 | |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 102 | #ifdef ECM_MULTICAST_ENABLE |
| 103 | #include <mc_ecm.h> |
| 104 | #endif |
| 105 | |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 106 | #include "ecm_types.h" |
| 107 | #include "ecm_db_types.h" |
Gareth Williams | d5618a8 | 2015-05-20 11:13:32 +0100 | [diff] [blame] | 108 | #include "ecm_state.h" |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 109 | #include "ecm_tracker.h" |
| 110 | #include "ecm_classifier.h" |
| 111 | #include "ecm_front_end_types.h" |
| 112 | #include "ecm_tracker_datagram.h" |
| 113 | #include "ecm_tracker_udp.h" |
| 114 | #include "ecm_tracker_tcp.h" |
| 115 | #include "ecm_db.h" |
| 116 | #include "ecm_interface.h" |
| 117 | |
Murat Sezgin | a205b04 | 2016-07-19 14:18:14 -0700 | [diff] [blame] | 118 | /* |
| 119 | * Wifi event handler structure. |
| 120 | */ |
| 121 | struct ecm_interface_wifi_event { |
| 122 | struct task_struct *thread; |
| 123 | struct socket *sock; |
| 124 | }; |
| 125 | |
| 126 | static struct ecm_interface_wifi_event __ewn; |
| 127 | |
Gareth Williams | 8ac3429 | 2015-03-17 14:06:58 +0000 | [diff] [blame] | 128 | #ifdef ECM_IPV6_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 129 | /* |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 130 | * TODO: Remove once the Linux image and headers get propogated. |
| 131 | */ |
| 132 | struct net_device *ipv6_dev_find(struct net *net, struct in6_addr *addr, int strict); |
Murat Sezgin | 49465a4 | 2014-11-24 15:37:48 -0800 | [diff] [blame] | 133 | #endif |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 134 | |
| 135 | /* |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 136 | * Locking - concurrency control |
| 137 | */ |
Murat Sezgin | 908ecb3 | 2015-05-10 20:54:36 -0700 | [diff] [blame] | 138 | static DEFINE_SPINLOCK(ecm_interface_lock); /* Protect against SMP access between netfilter, events and private threaded function. */ |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 139 | |
| 140 | /* |
| 141 | * Management thread control |
| 142 | */ |
| 143 | static bool ecm_interface_terminate_pending = false; /* True when the user has signalled we should quit */ |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 144 | |
| 145 | /* |
Murat Sezgin | eebedb9 | 2017-11-17 17:14:32 -0800 | [diff] [blame] | 146 | * Source interface check flag. |
| 147 | * If it is enabled, the acceleration engine will check the flow's interface to see |
| 148 | * whether it matches with the rule's source interface or not. |
| 149 | */ |
| 150 | int ecm_interface_src_check; |
| 151 | |
| 152 | static struct ctl_table_header *ecm_interface_ctl_table_header; /* Sysctl table header */ |
| 153 | |
| 154 | /* |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 155 | * ecm_interface_get_and_hold_dev_master() |
| 156 | * Returns the master device of a net device if any. |
| 157 | */ |
| 158 | struct net_device *ecm_interface_get_and_hold_dev_master(struct net_device *dev) |
| 159 | { |
| 160 | struct net_device *master; |
| 161 | #if (LINUX_VERSION_CODE > KERNEL_VERSION(3,6,0)) |
| 162 | rcu_read_lock(); |
| 163 | master = netdev_master_upper_dev_get_rcu(dev); |
| 164 | if (!master) { |
| 165 | rcu_read_unlock(); |
| 166 | return NULL; |
| 167 | } |
| 168 | dev_hold(master); |
| 169 | rcu_read_unlock(); |
| 170 | #else |
| 171 | master = dev->master; |
| 172 | if (!master) { |
| 173 | return NULL; |
| 174 | } |
| 175 | dev_hold(master); |
| 176 | #endif |
| 177 | return master; |
| 178 | } |
| 179 | EXPORT_SYMBOL(ecm_interface_get_and_hold_dev_master); |
| 180 | |
| 181 | /* |
Shyam Sunder | 9db2085 | 2016-03-09 19:04:49 +0530 | [diff] [blame] | 182 | * ecm_interface_vlan_real_dev() |
| 183 | * Return immediate VLAN net device or Physical device pointer |
| 184 | */ |
| 185 | static inline struct net_device *ecm_interface_vlan_real_dev(struct net_device *vlan_dev) |
| 186 | { |
| 187 | #if (LINUX_VERSION_CODE > KERNEL_VERSION(3, 6, 0)) |
| 188 | return vlan_dev_next_dev(vlan_dev); |
| 189 | #else |
| 190 | return vlan_dev_real_dev(vlan_dev); |
| 191 | #endif |
| 192 | } |
| 193 | |
| 194 | /* |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 195 | * ecm_interface_dev_find_by_local_addr_ipv4() |
Shyam Sunder | 9db2085 | 2016-03-09 19:04:49 +0530 | [diff] [blame] | 196 | * Return a hold to the device for the given local IP address. Returns NULL on failure. |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 197 | */ |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 198 | static struct net_device *ecm_interface_dev_find_by_local_addr_ipv4(ip_addr_t addr) |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 199 | { |
| 200 | __be32 be_addr; |
| 201 | struct net_device *dev; |
| 202 | |
| 203 | ECM_IP_ADDR_TO_NIN4_ADDR(be_addr, addr); |
| 204 | dev = ip_dev_find(&init_net, be_addr); |
| 205 | return dev; |
| 206 | } |
| 207 | |
Gareth Williams | 8ac3429 | 2015-03-17 14:06:58 +0000 | [diff] [blame] | 208 | #ifdef ECM_IPV6_ENABLE |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 209 | /* |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 210 | * ecm_interface_dev_find_by_local_addr_ipv6() |
| 211 | * Return a hold to the device for the given local IP address. Returns NULL on failure. |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 212 | */ |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 213 | static struct net_device *ecm_interface_dev_find_by_local_addr_ipv6(ip_addr_t addr) |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 214 | { |
| 215 | struct in6_addr addr6; |
| 216 | struct net_device *dev; |
| 217 | |
| 218 | ECM_IP_ADDR_TO_NIN6_ADDR(addr6, addr); |
| 219 | dev = (struct net_device *)ipv6_dev_find(&init_net, &addr6, 1); |
| 220 | return dev; |
| 221 | } |
Murat Sezgin | 49465a4 | 2014-11-24 15:37:48 -0800 | [diff] [blame] | 222 | #endif |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 223 | |
| 224 | /* |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 225 | * ecm_interface_dev_find_by_local_addr() |
| 226 | * Return the device on which the local address resides. |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 227 | * |
| 228 | * Returns a hold to the device or NULL on failure. |
| 229 | */ |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 230 | struct net_device *ecm_interface_dev_find_by_local_addr(ip_addr_t addr) |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 231 | { |
| 232 | char __attribute__((unused)) addr_str[40]; |
| 233 | |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 234 | DEBUG_ECM_IP_ADDR_TO_STRING(addr_str, addr); |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 235 | DEBUG_TRACE("Locate dev for: %s\n", addr_str); |
| 236 | |
| 237 | if (ECM_IP_ADDR_IS_V4(addr)) { |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 238 | return ecm_interface_dev_find_by_local_addr_ipv4(addr); |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 239 | } |
| 240 | |
Gareth Williams | 8ac3429 | 2015-03-17 14:06:58 +0000 | [diff] [blame] | 241 | #ifdef ECM_IPV6_ENABLE |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 242 | return ecm_interface_dev_find_by_local_addr_ipv6(addr); |
Murat Sezgin | 49465a4 | 2014-11-24 15:37:48 -0800 | [diff] [blame] | 243 | #else |
| 244 | return NULL; |
| 245 | #endif |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 246 | } |
| 247 | EXPORT_SYMBOL(ecm_interface_dev_find_by_local_addr); |
| 248 | |
| 249 | /* |
| 250 | * ecm_interface_dev_find_by_addr() |
| 251 | * Return the net device on which the given IP address resides. Returns NULL on faiure. |
| 252 | * |
| 253 | * NOTE: The device may be the device upon which has a default gateway to reach the address. |
| 254 | * from_local_addr is true when the device was found by a local address search. |
| 255 | */ |
| 256 | struct net_device *ecm_interface_dev_find_by_addr(ip_addr_t addr, bool *from_local_addr) |
| 257 | { |
| 258 | char __attribute__((unused)) addr_str[40]; |
| 259 | struct ecm_interface_route ecm_rt; |
| 260 | struct net_device *dev; |
| 261 | struct dst_entry *dst; |
| 262 | |
| 263 | DEBUG_ECM_IP_ADDR_TO_STRING(addr_str, addr); |
| 264 | |
| 265 | /* |
| 266 | * Is the address a local IP? |
| 267 | */ |
| 268 | DEBUG_TRACE("find net device for address: %s\n", addr_str); |
| 269 | dev = ecm_interface_dev_find_by_local_addr(addr); |
| 270 | if (dev) { |
| 271 | *from_local_addr = true; |
| 272 | DEBUG_TRACE("addr: %s is local: %p (%s)\n", addr_str, dev, dev->name); |
| 273 | return dev; |
| 274 | } |
| 275 | |
| 276 | DEBUG_TRACE("addr: %s is not local\n", addr_str); |
| 277 | |
| 278 | /* |
| 279 | * Try a route to the address instead |
| 280 | * NOTE: This will locate a route entry in the route destination *cache*. |
| 281 | */ |
| 282 | if (!ecm_interface_find_route_by_addr(addr, &ecm_rt)) { |
| 283 | DEBUG_WARN("addr: %s - no dev locatable\n", addr_str); |
| 284 | return NULL; |
| 285 | } |
| 286 | |
| 287 | *from_local_addr = false; |
| 288 | dst = ecm_rt.dst; |
| 289 | dev = dst->dev; |
| 290 | dev_hold(dev); |
| 291 | ecm_interface_route_release(&ecm_rt); |
| 292 | DEBUG_TRACE("dest_addr: %s uses dev: %p(%s)\n", addr_str, dev, dev->name); |
| 293 | return dev; |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 294 | } |
| 295 | EXPORT_SYMBOL(ecm_interface_dev_find_by_addr); |
| 296 | |
Gareth Williams | 8ac3429 | 2015-03-17 14:06:58 +0000 | [diff] [blame] | 297 | #ifdef ECM_IPV6_ENABLE |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 298 | /* |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 299 | * ecm_interface_mac_addr_get_ipv6() |
| 300 | * Return mac for an IPv6 address |
| 301 | * |
| 302 | * GGG TODO Need to make sure this also works for local IP addresses too. |
| 303 | */ |
| 304 | static bool ecm_interface_mac_addr_get_ipv6(ip_addr_t addr, uint8_t *mac_addr, bool *on_link, ip_addr_t gw_addr) |
| 305 | { |
| 306 | struct in6_addr daddr; |
| 307 | struct ecm_interface_route ecm_rt; |
| 308 | struct neighbour *neigh; |
| 309 | struct rt6_info *rt; |
| 310 | struct dst_entry *dst; |
| 311 | |
| 312 | /* |
| 313 | * Get the MAC address that corresponds to IP address given. |
| 314 | * We look up the rt6_info entries and, from its neighbour structure, obtain the hardware address. |
| 315 | * This means we will also work if the neighbours are routers too. |
| 316 | */ |
| 317 | ECM_IP_ADDR_TO_NIN6_ADDR(daddr, addr); |
| 318 | if (!ecm_interface_find_route_by_addr(addr, &ecm_rt)) { |
Kiran Kumar C. S. K | 7d17822 | 2014-06-27 18:47:29 +0530 | [diff] [blame] | 319 | *on_link = false; |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 320 | return false; |
| 321 | } |
| 322 | DEBUG_ASSERT(!ecm_rt.v4_route, "Did not locate a v6 route!\n"); |
| 323 | |
| 324 | /* |
| 325 | * Is this destination on link or off-link via a gateway? |
| 326 | */ |
| 327 | rt = ecm_rt.rt.rtv6; |
| 328 | if (!ECM_IP_ADDR_MATCH(rt->rt6i_dst.addr.in6_u.u6_addr32, rt->rt6i_gateway.in6_u.u6_addr32) || (rt->rt6i_flags & RTF_GATEWAY)) { |
| 329 | *on_link = false; |
| 330 | ECM_NIN6_ADDR_TO_IP_ADDR(gw_addr, rt->rt6i_gateway) |
| 331 | } else { |
| 332 | *on_link = true; |
| 333 | } |
| 334 | |
| 335 | rcu_read_lock(); |
| 336 | dst = ecm_rt.dst; |
Murat Sezgin | e9b8458 | 2015-01-27 17:34:14 -0800 | [diff] [blame] | 337 | #if (LINUX_VERSION_CODE <= KERNEL_VERSION(3,6,0)) |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 338 | neigh = dst_get_neighbour_noref(dst); |
Murat Sezgin | dcbcdb5 | 2014-05-15 16:06:13 -0700 | [diff] [blame] | 339 | if (neigh) { |
| 340 | neigh_hold(neigh); |
Murat Sezgin | e9b8458 | 2015-01-27 17:34:14 -0800 | [diff] [blame] | 341 | } |
| 342 | #else |
| 343 | neigh = dst_neigh_lookup(dst, &daddr); |
| 344 | #endif |
| 345 | if (!neigh) { |
Murat Sezgin | dcbcdb5 | 2014-05-15 16:06:13 -0700 | [diff] [blame] | 346 | neigh = neigh_lookup(&nd_tbl, &daddr, dst->dev); |
| 347 | } |
Murat Sezgin | e9b8458 | 2015-01-27 17:34:14 -0800 | [diff] [blame] | 348 | |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 349 | if (!neigh) { |
| 350 | rcu_read_unlock(); |
| 351 | ecm_interface_route_release(&ecm_rt); |
Murat Sezgin | dcbcdb5 | 2014-05-15 16:06:13 -0700 | [diff] [blame] | 352 | DEBUG_WARN("No neigh reference\n"); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 353 | return false; |
| 354 | } |
| 355 | if (!(neigh->nud_state & NUD_VALID)) { |
| 356 | rcu_read_unlock(); |
Murat Sezgin | dcbcdb5 | 2014-05-15 16:06:13 -0700 | [diff] [blame] | 357 | neigh_release(neigh); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 358 | ecm_interface_route_release(&ecm_rt); |
Murat Sezgin | dcbcdb5 | 2014-05-15 16:06:13 -0700 | [diff] [blame] | 359 | DEBUG_WARN("NUD invalid\n"); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 360 | return false; |
| 361 | } |
| 362 | if (!neigh->dev) { |
| 363 | rcu_read_unlock(); |
Murat Sezgin | dcbcdb5 | 2014-05-15 16:06:13 -0700 | [diff] [blame] | 364 | neigh_release(neigh); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 365 | ecm_interface_route_release(&ecm_rt); |
Murat Sezgin | dcbcdb5 | 2014-05-15 16:06:13 -0700 | [diff] [blame] | 366 | DEBUG_WARN("Neigh dev invalid\n"); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 367 | return false; |
| 368 | } |
| 369 | |
| 370 | /* |
| 371 | * If neigh->dev is a loopback then addr is a local address in which case we take the MAC from given device |
| 372 | */ |
| 373 | if (neigh->dev->flags & IFF_LOOPBACK) { |
| 374 | // GGG TODO Create an equivalent logic to that for ipv4, maybe need to create an ip6_dev_find()? |
| 375 | DEBUG_TRACE("local address " ECM_IP_ADDR_OCTAL_FMT " (found loopback)\n", ECM_IP_ADDR_TO_OCTAL(addr)); |
| 376 | memset(mac_addr, 0, 6); |
| 377 | } else { |
| 378 | memcpy(mac_addr, neigh->ha, 6); |
| 379 | } |
| 380 | rcu_read_unlock(); |
Murat Sezgin | dcbcdb5 | 2014-05-15 16:06:13 -0700 | [diff] [blame] | 381 | neigh_release(neigh); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 382 | ecm_interface_route_release(&ecm_rt); |
| 383 | |
| 384 | DEBUG_TRACE(ECM_IP_ADDR_OCTAL_FMT " maps to %pM\n", ECM_IP_ADDR_TO_OCTAL(addr), mac_addr); |
| 385 | return true; |
| 386 | } |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 387 | |
| 388 | /* |
| 389 | * ecm_interface_find_gateway_ipv6() |
| 390 | * Finds the ipv6 gateway ip address of a given ipv6 address. |
| 391 | */ |
| 392 | static bool ecm_interface_find_gateway_ipv6(ip_addr_t addr, ip_addr_t gw_addr) |
| 393 | { |
| 394 | struct ecm_interface_route ecm_rt; |
| 395 | struct rt6_info *rt; |
| 396 | |
| 397 | /* |
| 398 | * Find the ipv6 route of the given ip address to look up |
| 399 | * whether we have a gateway to reach to that ip address or not. |
| 400 | */ |
| 401 | if (!ecm_interface_find_route_by_addr(addr, &ecm_rt)) { |
| 402 | return false; |
| 403 | } |
| 404 | DEBUG_ASSERT(!ecm_rt.v4_route, "Did not locate a v6 route!\n"); |
| 405 | DEBUG_TRACE("Found route\n"); |
| 406 | |
| 407 | /* |
| 408 | * Is this destination reachable via a gateway? |
| 409 | */ |
| 410 | rt = ecm_rt.rt.rtv6; |
| 411 | if (ECM_IP_ADDR_MATCH(rt->rt6i_dst.addr.in6_u.u6_addr32, rt->rt6i_gateway.in6_u.u6_addr32) && !(rt->rt6i_flags & RTF_GATEWAY)) { |
Murat Sezgin | 313f222 | 2016-08-11 12:22:10 -0700 | [diff] [blame] | 412 | ecm_interface_route_release(&ecm_rt); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 413 | return false; |
| 414 | } |
| 415 | |
| 416 | ECM_NIN6_ADDR_TO_IP_ADDR(gw_addr, rt->rt6i_gateway) |
Murat Sezgin | 313f222 | 2016-08-11 12:22:10 -0700 | [diff] [blame] | 417 | ecm_interface_route_release(&ecm_rt); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 418 | return true; |
| 419 | } |
Murat Sezgin | 49465a4 | 2014-11-24 15:37:48 -0800 | [diff] [blame] | 420 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 421 | |
| 422 | /* |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 423 | * ecm_interface_find_gateway_ipv4() |
| 424 | * Finds the ipv4 gateway address of a given ipv4 address. |
| 425 | */ |
| 426 | static bool ecm_interface_find_gateway_ipv4(ip_addr_t addr, ip_addr_t gw_addr) |
| 427 | { |
| 428 | struct ecm_interface_route ecm_rt; |
| 429 | struct rtable *rt; |
| 430 | |
| 431 | /* |
| 432 | * Find the ipv4 route of the given ip address to look up |
| 433 | * whether we have a gateway to reach to that ip address or not. |
| 434 | */ |
| 435 | if (!ecm_interface_find_route_by_addr(addr, &ecm_rt)) { |
| 436 | return false; |
| 437 | } |
| 438 | DEBUG_ASSERT(ecm_rt.v4_route, "Did not locate a v4 route!\n"); |
| 439 | DEBUG_TRACE("Found route\n"); |
| 440 | |
| 441 | /* |
| 442 | * Is this destination reachable via a gateway? |
| 443 | */ |
| 444 | rt = ecm_rt.rt.rtv4; |
| 445 | #if (LINUX_VERSION_CODE <= KERNEL_VERSION(3, 6, 0)) |
| 446 | if (!(rt->rt_dst != rt->rt_gateway) && !(rt->rt_flags & RTF_GATEWAY)) { |
| 447 | #else |
| 448 | if (!rt->rt_uses_gateway && !(rt->rt_flags & RTF_GATEWAY)) { |
| 449 | #endif |
Murat Sezgin | 313f222 | 2016-08-11 12:22:10 -0700 | [diff] [blame] | 450 | ecm_interface_route_release(&ecm_rt); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 451 | return false; |
| 452 | } |
| 453 | |
| 454 | ECM_NIN4_ADDR_TO_IP_ADDR(gw_addr, rt->rt_gateway) |
Murat Sezgin | 313f222 | 2016-08-11 12:22:10 -0700 | [diff] [blame] | 455 | ecm_interface_route_release(&ecm_rt); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 456 | return true; |
| 457 | } |
| 458 | |
| 459 | /* |
| 460 | * ecm_interface_find_gateway() |
| 461 | * Finds the gateway ip address of a given ECM ip address type. |
| 462 | */ |
| 463 | bool ecm_interface_find_gateway(ip_addr_t addr, ip_addr_t gw_addr) |
| 464 | { |
| 465 | if (ECM_IP_ADDR_IS_V4(addr)) { |
| 466 | return ecm_interface_find_gateway_ipv4(addr, gw_addr); |
| 467 | } |
| 468 | |
| 469 | #ifdef ECM_IPV6_ENABLE |
| 470 | return ecm_interface_find_gateway_ipv6(addr, gw_addr); |
| 471 | #else |
| 472 | return false; |
| 473 | #endif |
| 474 | } |
| 475 | EXPORT_SYMBOL(ecm_interface_find_gateway); |
| 476 | |
| 477 | /* |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 478 | * ecm_interface_mac_addr_get_ipv4() |
| 479 | * Return mac for an IPv4 address |
| 480 | */ |
| 481 | static bool ecm_interface_mac_addr_get_ipv4(ip_addr_t addr, uint8_t *mac_addr, bool *on_link, ip_addr_t gw_addr) |
| 482 | { |
| 483 | struct neighbour *neigh; |
| 484 | struct ecm_interface_route ecm_rt; |
| 485 | struct rtable *rt; |
| 486 | struct dst_entry *dst; |
| 487 | __be32 ipv4_addr; |
Radha krishna Simha Jiguru | f7dc34c | 2014-05-12 18:59:07 +0530 | [diff] [blame] | 488 | |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 489 | /* |
| 490 | * Get the MAC address that corresponds to IP address given. |
| 491 | * We look up the rtable entries and, from its neighbour structure, obtain the hardware address. |
| 492 | * This means we will also work if the neighbours are routers too. |
| 493 | * We also locate the MAC if the address is a local host address. |
| 494 | */ |
| 495 | ECM_IP_ADDR_TO_NIN4_ADDR(ipv4_addr, addr); |
| 496 | if (!ecm_interface_find_route_by_addr(addr, &ecm_rt)) { |
Kiran Kumar C. S. K | 7d17822 | 2014-06-27 18:47:29 +0530 | [diff] [blame] | 497 | *on_link = false; |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 498 | return false; |
| 499 | } |
| 500 | DEBUG_ASSERT(ecm_rt.v4_route, "Did not locate a v4 route!\n"); |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 501 | DEBUG_TRACE("Found route\n"); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 502 | |
| 503 | /* |
| 504 | * Is this destination on link or off-link via a gateway? |
| 505 | */ |
| 506 | rt = ecm_rt.rt.rtv4; |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 507 | #if (LINUX_VERSION_CODE <= KERNEL_VERSION(3,6,0)) |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 508 | if ((rt->rt_dst != rt->rt_gateway) || (rt->rt_flags & RTF_GATEWAY)) { |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 509 | #else |
| 510 | if (rt->rt_uses_gateway || (rt->rt_flags & RTF_GATEWAY)) { |
| 511 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 512 | *on_link = false; |
| 513 | ECM_NIN4_ADDR_TO_IP_ADDR(gw_addr, rt->rt_gateway) |
| 514 | } else { |
| 515 | *on_link = true; |
| 516 | } |
| 517 | |
| 518 | /* |
| 519 | * Get the neighbour entry for the address |
| 520 | */ |
| 521 | rcu_read_lock(); |
| 522 | dst = ecm_rt.dst; |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 523 | #if (LINUX_VERSION_CODE <= KERNEL_VERSION(3,6,0)) |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 524 | neigh = dst_get_neighbour_noref(dst); |
| 525 | if (neigh) { |
| 526 | neigh_hold(neigh); |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 527 | } |
| 528 | #else |
| 529 | neigh = dst_neigh_lookup(dst, &ipv4_addr); |
| 530 | #endif |
| 531 | if (!neigh) { |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 532 | neigh = neigh_lookup(&arp_tbl, &ipv4_addr, dst->dev); |
| 533 | } |
| 534 | if (!neigh) { |
| 535 | rcu_read_unlock(); |
| 536 | ecm_interface_route_release(&ecm_rt); |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 537 | DEBUG_WARN("no neigh\n"); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 538 | return false; |
| 539 | } |
| 540 | if (!(neigh->nud_state & NUD_VALID)) { |
| 541 | rcu_read_unlock(); |
| 542 | neigh_release(neigh); |
| 543 | ecm_interface_route_release(&ecm_rt); |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 544 | DEBUG_WARN("neigh nud state is not valid\n"); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 545 | return false; |
| 546 | } |
| 547 | if (!neigh->dev) { |
| 548 | rcu_read_unlock(); |
| 549 | neigh_release(neigh); |
| 550 | ecm_interface_route_release(&ecm_rt); |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 551 | DEBUG_WARN("neigh has no device\n"); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 552 | return false; |
| 553 | } |
| 554 | |
| 555 | /* |
| 556 | * If the device is loopback this will be because the address is a local address |
| 557 | * In this case locate the device that has this local address and get its mac. |
| 558 | */ |
| 559 | if (neigh->dev->type == ARPHRD_LOOPBACK) { |
| 560 | struct net_device *dev; |
| 561 | |
| 562 | DEBUG_TRACE("%pI4 finds loopback device, dev: %p (%s)\n", &ipv4_addr, neigh->dev, neigh->dev->name); |
| 563 | rcu_read_unlock(); |
| 564 | neigh_release(neigh); |
| 565 | ecm_interface_route_release(&ecm_rt); |
| 566 | |
| 567 | /* |
| 568 | * Lookup the device that has this IP address assigned |
| 569 | */ |
| 570 | dev = ip_dev_find(&init_net, ipv4_addr); |
| 571 | if (!dev) { |
| 572 | DEBUG_WARN("Unable to locate dev for: %pI4\n", &ipv4_addr); |
| 573 | return false; |
| 574 | } |
| 575 | memcpy(mac_addr, dev->dev_addr, (size_t)dev->addr_len); |
| 576 | DEBUG_TRACE("is local addr: %pI4, mac: %pM, dev ifindex: %d, dev: %p (%s), dev_type: %d\n", |
| 577 | &ipv4_addr, mac_addr, dev->ifindex, dev, dev->name, dev->type); |
| 578 | dev_put(dev); |
| 579 | return true; |
| 580 | } |
| 581 | |
| 582 | if (!(neigh->dev->flags & IFF_NOARP)) { |
| 583 | memcpy(mac_addr, neigh->ha, (size_t)neigh->dev->addr_len); |
| 584 | } else { |
| 585 | DEBUG_TRACE("non-arp device: %p (%s, type: %d) to reach %pI4\n", neigh->dev, neigh->dev->name, neigh->dev->type, &ipv4_addr); |
| 586 | memset(mac_addr, 0, 6); |
| 587 | } |
| 588 | DEBUG_TRACE("addr: %pI4, mac: %pM, iif: %d, neigh dev ifindex: %d, dev: %p (%s), dev_type: %d\n", |
| 589 | &ipv4_addr, mac_addr, rt->rt_iif, neigh->dev->ifindex, neigh->dev, neigh->dev->name, neigh->dev->type); |
| 590 | |
| 591 | rcu_read_unlock(); |
| 592 | neigh_release(neigh); |
| 593 | ecm_interface_route_release(&ecm_rt); |
| 594 | return true; |
| 595 | } |
| 596 | |
| 597 | /* |
| 598 | * ecm_interface_mac_addr_get() |
| 599 | * Return the mac address for the given IP address. Returns false on failure. |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 600 | */ |
| 601 | bool ecm_interface_mac_addr_get(ip_addr_t addr, uint8_t *mac_addr, bool *on_link, ip_addr_t gw_addr) |
| 602 | { |
| 603 | if (ECM_IP_ADDR_IS_V4(addr)) { |
| 604 | return ecm_interface_mac_addr_get_ipv4(addr, mac_addr, on_link, gw_addr); |
| 605 | } |
| 606 | |
Gareth Williams | 8ac3429 | 2015-03-17 14:06:58 +0000 | [diff] [blame] | 607 | #ifdef ECM_IPV6_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 608 | return ecm_interface_mac_addr_get_ipv6(addr, mac_addr, on_link, gw_addr); |
Murat Sezgin | 49465a4 | 2014-11-24 15:37:48 -0800 | [diff] [blame] | 609 | #else |
| 610 | return false; |
| 611 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 612 | } |
| 613 | EXPORT_SYMBOL(ecm_interface_mac_addr_get); |
| 614 | |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 615 | #ifdef ECM_IPV6_ENABLE |
| 616 | /* |
| 617 | * ecm_interface_mac_addr_get_ipv6_no_route() |
| 618 | * Finds the mac address of a node from its ip address reachable via |
| 619 | * the given device. It looks up the mac address in the neighbour entries. |
| 620 | * It doesn't do any route lookup to find the dst entry. |
| 621 | */ |
| 622 | static bool ecm_interface_mac_addr_get_ipv6_no_route(struct net_device *dev, ip_addr_t addr, uint8_t *mac_addr) |
| 623 | { |
| 624 | struct in6_addr daddr; |
| 625 | struct neighbour *neigh; |
| 626 | struct net_device *local_dev; |
| 627 | |
| 628 | memset(mac_addr, 0, ETH_ALEN); |
| 629 | |
| 630 | /* |
| 631 | * Get the MAC address that corresponds to IP address given. |
| 632 | */ |
| 633 | ECM_IP_ADDR_TO_NIN6_ADDR(daddr, addr); |
| 634 | local_dev = ipv6_dev_find(&init_net, &daddr, 1); |
| 635 | if (local_dev) { |
| 636 | DEBUG_TRACE("%pi6 is a local address\n", &daddr); |
| 637 | memcpy(mac_addr, dev->dev_addr, ETH_ALEN); |
| 638 | dev_put(local_dev); |
| 639 | return true; |
| 640 | } |
| 641 | |
| 642 | rcu_read_lock(); |
| 643 | neigh = neigh_lookup(&nd_tbl, &daddr, dev); |
| 644 | if (!neigh) { |
| 645 | rcu_read_unlock(); |
| 646 | DEBUG_WARN("No neigh reference\n"); |
| 647 | return false; |
| 648 | } |
| 649 | if (!(neigh->nud_state & NUD_VALID)) { |
| 650 | neigh_release(neigh); |
| 651 | rcu_read_unlock(); |
| 652 | DEBUG_WARN("NUD invalid\n"); |
| 653 | return false; |
| 654 | } |
| 655 | if (!neigh->dev) { |
| 656 | neigh_release(neigh); |
| 657 | rcu_read_unlock(); |
| 658 | DEBUG_WARN("Neigh dev invalid\n"); |
| 659 | return false; |
| 660 | } |
| 661 | |
| 662 | if (neigh->dev->flags & IFF_NOARP) { |
| 663 | neigh_release(neigh); |
| 664 | rcu_read_unlock(); |
| 665 | DEBUG_TRACE("dest MAC is zero: %pM\n", mac_addr); |
| 666 | return true; |
| 667 | } |
| 668 | |
| 669 | memcpy(mac_addr, neigh->ha, (size_t)neigh->dev->addr_len); |
| 670 | neigh_release(neigh); |
| 671 | rcu_read_unlock(); |
| 672 | DEBUG_TRACE(ECM_IP_ADDR_OCTAL_FMT " maps to %pM\n", ECM_IP_ADDR_TO_OCTAL(addr), mac_addr); |
| 673 | return true; |
| 674 | } |
| 675 | #endif |
| 676 | |
| 677 | /* |
| 678 | * ecm_interface_mac_addr_get_ipv4_no_route() |
| 679 | * Finds the mac address of a node from its ip address reachable via |
| 680 | * the given device. It looks up the mac address in the neighbour entries. |
| 681 | * It doesn't do any route lookup to find the dst entry. |
| 682 | */ |
| 683 | static bool ecm_interface_mac_addr_get_ipv4_no_route(struct net_device *dev, ip_addr_t ip_addr, uint8_t *mac_addr) |
| 684 | { |
| 685 | struct neighbour *neigh; |
| 686 | __be32 be_addr; |
| 687 | struct net_device *local_dev; |
| 688 | |
| 689 | memset(mac_addr, 0, ETH_ALEN); |
| 690 | |
| 691 | ECM_IP_ADDR_TO_NIN4_ADDR(be_addr, ip_addr); |
| 692 | local_dev = ip_dev_find(&init_net, be_addr); |
| 693 | if (local_dev) { |
| 694 | DEBUG_TRACE("%pI4n is a local address\n", &be_addr); |
| 695 | memcpy(mac_addr, dev->dev_addr, ETH_ALEN); |
| 696 | dev_put(local_dev); |
| 697 | return true; |
| 698 | } |
| 699 | |
| 700 | rcu_read_lock(); |
| 701 | neigh = neigh_lookup(&arp_tbl, &be_addr, dev); |
| 702 | if (!neigh) { |
| 703 | rcu_read_unlock(); |
| 704 | DEBUG_WARN("no neigh\n"); |
| 705 | return false; |
| 706 | } |
| 707 | if (!(neigh->nud_state & NUD_VALID)) { |
| 708 | neigh_release(neigh); |
| 709 | rcu_read_unlock(); |
| 710 | DEBUG_WARN("neigh nud state is not valid\n"); |
| 711 | return false; |
| 712 | } |
| 713 | if (!neigh->dev) { |
| 714 | neigh_release(neigh); |
| 715 | rcu_read_unlock(); |
| 716 | DEBUG_WARN("neigh has no device\n"); |
| 717 | return false; |
| 718 | } |
| 719 | |
| 720 | if (neigh->dev->flags & IFF_NOARP) { |
| 721 | neigh_release(neigh); |
| 722 | rcu_read_unlock(); |
| 723 | DEBUG_TRACE("dest MAC is zero: %pM\n", mac_addr); |
| 724 | return true; |
| 725 | } |
| 726 | |
| 727 | memcpy(mac_addr, neigh->ha, (size_t)neigh->dev->addr_len); |
| 728 | neigh_release(neigh); |
| 729 | rcu_read_unlock(); |
| 730 | DEBUG_TRACE("dest MAC: %pM\n", mac_addr); |
| 731 | return true; |
| 732 | |
| 733 | } |
| 734 | |
| 735 | /* |
| 736 | * ecm_interface_mac_addr_get_no_route() |
| 737 | * Return the mac address for the given IP address reacahble via the given device. |
| 738 | * Return false on failure, true on success. |
| 739 | */ |
| 740 | bool ecm_interface_mac_addr_get_no_route(struct net_device *dev, ip_addr_t addr, uint8_t *mac_addr) |
| 741 | { |
| 742 | if (ECM_IP_ADDR_IS_V4(addr)) { |
| 743 | return ecm_interface_mac_addr_get_ipv4_no_route(dev, addr, mac_addr); |
| 744 | } |
| 745 | |
| 746 | #ifdef ECM_IPV6_ENABLE |
| 747 | return ecm_interface_mac_addr_get_ipv6_no_route(dev, addr, mac_addr); |
| 748 | #else |
| 749 | return false; |
| 750 | #endif |
| 751 | } |
| 752 | EXPORT_SYMBOL(ecm_interface_mac_addr_get_no_route); |
| 753 | |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 754 | #ifdef ECM_MULTICAST_ENABLE |
| 755 | /* |
| 756 | * ecm_interface_multicast_check_for_br_dev() |
| 757 | * Find a bridge dev is present or not in an |
| 758 | * array of Ifindexs |
| 759 | */ |
| 760 | bool ecm_interface_multicast_check_for_br_dev(uint32_t dest_if[], uint8_t max_if) |
| 761 | { |
| 762 | struct net_device *br_dev; |
| 763 | int i; |
| 764 | |
| 765 | for (i = 0; i < max_if; i++) { |
| 766 | br_dev = dev_get_by_index(&init_net, dest_if[i]); |
| 767 | if (!br_dev) { |
ratheesh kannoth | c5df16c | 2018-03-16 21:07:23 +0530 | [diff] [blame] | 768 | /* |
| 769 | * Interface got deleted; but is yet to be updated in MFC table |
| 770 | */ |
| 771 | DEBUG_WARN("Could not find a valid netdev here\n"); |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 772 | continue; |
| 773 | } |
| 774 | |
| 775 | if (ecm_front_end_is_bridge_device(br_dev)) { |
| 776 | dev_put(br_dev); |
| 777 | return true; |
| 778 | } |
| 779 | dev_put(br_dev); |
| 780 | } |
| 781 | return false; |
| 782 | } |
| 783 | EXPORT_SYMBOL(ecm_interface_multicast_check_for_br_dev); |
Shyam Sunder | a2e08ee | 2015-06-18 21:32:13 +0530 | [diff] [blame] | 784 | |
| 785 | /* |
ratheesh kannoth | c5df16c | 2018-03-16 21:07:23 +0530 | [diff] [blame] | 786 | * ecm_interface_multicast_is_iface_type() |
| 787 | * Checks if interface of type exist in mc_if_index |
| 788 | */ |
| 789 | bool ecm_interface_multicast_is_iface_type(int32_t mc_if_index[], int32_t max_if_index, unsigned short type) |
| 790 | { |
| 791 | int32_t i; |
| 792 | struct net_device *dev; |
| 793 | |
| 794 | for (i = 0; i < max_if_index; i++) { |
| 795 | |
| 796 | if (!mc_if_index[i]) { |
| 797 | break; |
| 798 | } |
| 799 | |
| 800 | dev = dev_get_by_index(&init_net, mc_if_index[i]); |
| 801 | if (!dev) { |
| 802 | DEBUG_WARN("Could not find a valid interface with index = %d\n", mc_if_index[i]); |
| 803 | continue; |
| 804 | } |
| 805 | |
| 806 | if (dev->type == type) { |
| 807 | DEBUG_TRACE("Interface dev = %s of type %u\n", dev->name, type); |
| 808 | dev_put(dev); |
| 809 | return true; |
| 810 | } |
| 811 | |
| 812 | dev_put(dev); |
| 813 | } |
| 814 | |
| 815 | return false; |
| 816 | } |
| 817 | |
| 818 | /* |
Shyam Sunder | a2e08ee | 2015-06-18 21:32:13 +0530 | [diff] [blame] | 819 | * ecm_interface_multicast_check_for_src_if_index() |
| 820 | * Find if a source netdev ifindex is matching with list of |
| 821 | * multicast destination netdev ifindex. If find a match then |
| 822 | * returns a new list of destination netdev ifindex excluding |
| 823 | * the ifindex of source netdev. |
| 824 | */ |
| 825 | int32_t ecm_interface_multicast_check_for_src_ifindex(int32_t mc_if_index[], int32_t max_if_index, int32_t if_num) |
| 826 | { |
| 827 | int32_t i; |
| 828 | int32_t valid_index; |
| 829 | |
| 830 | for (i = 0, valid_index = 0; i < max_if_index; i++) { |
| 831 | if (mc_if_index[i] == 0) { |
| 832 | break; |
| 833 | } |
| 834 | |
| 835 | if (mc_if_index[i] != if_num) { |
| 836 | mc_if_index[valid_index] = mc_if_index[i]; |
| 837 | valid_index++; |
| 838 | continue; |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | return valid_index; |
| 843 | } |
| 844 | EXPORT_SYMBOL(ecm_interface_multicast_check_for_src_ifindex); |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 845 | #endif |
| 846 | |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 847 | /* |
| 848 | * ecm_interface_addr_find_route_by_addr_ipv4() |
| 849 | * Return the route for the given IP address. Returns NULL on failure. |
| 850 | */ |
| 851 | static bool ecm_interface_find_route_by_addr_ipv4(ip_addr_t addr, struct ecm_interface_route *ecm_rt) |
| 852 | { |
| 853 | __be32 be_addr; |
| 854 | |
| 855 | /* |
| 856 | * Get a route to the given IP address, this will allow us to also find the interface |
| 857 | * it is using to communicate with that IP address. |
| 858 | */ |
| 859 | ECM_IP_ADDR_TO_NIN4_ADDR(be_addr, addr); |
| 860 | ecm_rt->rt.rtv4 = ip_route_output(&init_net, be_addr, 0, 0, 0); |
| 861 | if (IS_ERR(ecm_rt->rt.rtv4)) { |
| 862 | DEBUG_TRACE("No output route to: %pI4n\n", &be_addr); |
| 863 | return false; |
| 864 | } |
| 865 | DEBUG_TRACE("Output route to: %pI4n is: %p\n", &be_addr, ecm_rt->rt.rtv4); |
| 866 | ecm_rt->dst = (struct dst_entry *)ecm_rt->rt.rtv4; |
| 867 | ecm_rt->v4_route = true; |
| 868 | return true; |
| 869 | } |
| 870 | |
Gareth Williams | 8ac3429 | 2015-03-17 14:06:58 +0000 | [diff] [blame] | 871 | #ifdef ECM_IPV6_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 872 | /* |
| 873 | * ecm_interface_addr_find_route_by_addr_ipv6() |
| 874 | * Return the route for the given IP address. Returns NULL on failure. |
| 875 | */ |
| 876 | static bool ecm_interface_find_route_by_addr_ipv6(ip_addr_t addr, struct ecm_interface_route *ecm_rt) |
| 877 | { |
| 878 | struct in6_addr naddr; |
| 879 | |
| 880 | ECM_IP_ADDR_TO_NIN6_ADDR(naddr, addr); |
| 881 | |
| 882 | /* |
| 883 | * Get a route to the given IP address, this will allow us to also find the interface |
| 884 | * it is using to communicate with that IP address. |
| 885 | */ |
| 886 | ecm_rt->rt.rtv6 = rt6_lookup(&init_net, &naddr, NULL, 0, 0); |
| 887 | if (!ecm_rt->rt.rtv6) { |
| 888 | DEBUG_TRACE("No output route to: " ECM_IP_ADDR_OCTAL_FMT "\n", ECM_IP_ADDR_TO_OCTAL(addr)); |
| 889 | return NULL; |
| 890 | } |
| 891 | DEBUG_TRACE("Output route to: " ECM_IP_ADDR_OCTAL_FMT " is: %p\n", ECM_IP_ADDR_TO_OCTAL(addr), ecm_rt->rt.rtv6); |
| 892 | ecm_rt->dst = (struct dst_entry *)ecm_rt->rt.rtv6; |
| 893 | ecm_rt->v4_route = false; |
| 894 | return true; |
| 895 | } |
Murat Sezgin | 49465a4 | 2014-11-24 15:37:48 -0800 | [diff] [blame] | 896 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 897 | |
| 898 | /* |
| 899 | * ecm_interface_addr_find_route_by_addr() |
| 900 | * Return the route (in the given parameter) for the given IP address. Returns false on failure. |
| 901 | * |
| 902 | * Route is the device on which the addr is reachable, which may be loopback for local addresses. |
| 903 | * |
| 904 | * Returns true if the route was able to be located. The route must be released using ecm_interface_route_release(). |
| 905 | */ |
| 906 | bool ecm_interface_find_route_by_addr(ip_addr_t addr, struct ecm_interface_route *ecm_rt) |
| 907 | { |
| 908 | char __attribute__((unused)) addr_str[40]; |
Radha krishna Simha Jiguru | f7dc34c | 2014-05-12 18:59:07 +0530 | [diff] [blame] | 909 | |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 910 | DEBUG_ECM_IP_ADDR_TO_STRING(addr_str, addr); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 911 | DEBUG_TRACE("Locate route to: %s\n", addr_str); |
| 912 | |
| 913 | if (ECM_IP_ADDR_IS_V4(addr)) { |
| 914 | return ecm_interface_find_route_by_addr_ipv4(addr, ecm_rt); |
| 915 | } |
| 916 | |
Gareth Williams | 8ac3429 | 2015-03-17 14:06:58 +0000 | [diff] [blame] | 917 | #ifdef ECM_IPV6_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 918 | return ecm_interface_find_route_by_addr_ipv6(addr, ecm_rt); |
Murat Sezgin | 49465a4 | 2014-11-24 15:37:48 -0800 | [diff] [blame] | 919 | #else |
| 920 | return false; |
| 921 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 922 | } |
| 923 | EXPORT_SYMBOL(ecm_interface_find_route_by_addr); |
| 924 | |
| 925 | /* |
| 926 | * ecm_interface_route_release() |
| 927 | * Release an ecm route |
| 928 | */ |
| 929 | void ecm_interface_route_release(struct ecm_interface_route *rt) |
| 930 | { |
| 931 | dst_release(rt->dst); |
| 932 | } |
| 933 | EXPORT_SYMBOL(ecm_interface_route_release); |
| 934 | |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 935 | #ifdef ECM_IPV6_ENABLE |
| 936 | /* |
| 937 | * ecm_interface_send_neighbour_solicitation() |
| 938 | * Issue an IPv6 Neighbour soliciation request. |
| 939 | */ |
| 940 | void ecm_interface_send_neighbour_solicitation(struct net_device *dev, ip_addr_t addr) |
| 941 | { |
| 942 | struct in6_addr dst_addr, src_addr; |
| 943 | struct in6_addr mc_dst_addr; |
| 944 | struct rt6_info *rt6i; |
| 945 | struct neighbour *neigh; |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 946 | struct net *netf = dev_net(dev); |
| 947 | int ret; |
| 948 | |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 949 | /* |
| 950 | * Find source and destination addresses in Linux format. We need |
| 951 | * mcast destination address as well. |
| 952 | */ |
| 953 | ECM_IP_ADDR_TO_NIN6_ADDR(dst_addr, addr); |
| 954 | addrconf_addr_solict_mult(&dst_addr, &mc_dst_addr); |
Murat Sezgin | 96ed034 | 2017-05-19 09:48:57 -0700 | [diff] [blame] | 955 | ret = ipv6_dev_get_saddr(netf, dev, &mc_dst_addr, 0, &src_addr); |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 956 | |
| 957 | /* |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 958 | * Find the route entry |
| 959 | */ |
| 960 | rt6i = rt6_lookup(netf, &dst_addr, NULL, 0, 0); |
| 961 | if (!rt6i) { |
Murat Sezgin | f21210e | 2016-04-04 13:58:20 -0700 | [diff] [blame] | 962 | DEBUG_TRACE("IPv6 Route lookup failure for destination IPv6 address " ECM_IP_ADDR_OCTAL_FMT "\n", ECM_IP_ADDR_TO_OCTAL(addr)); |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 963 | return; |
| 964 | } |
| 965 | |
| 966 | /* |
| 967 | * Find the neighbor entry |
| 968 | */ |
| 969 | #if (LINUX_VERSION_CODE <= KERNEL_VERSION(3,6,0)) |
| 970 | neigh = rt6i->dst.ops->neigh_lookup(&rt6i->dst, &dst_addr); |
| 971 | #else |
| 972 | neigh = rt6i->dst.ops->neigh_lookup(&rt6i->dst, NULL, &dst_addr); |
| 973 | #endif |
| 974 | if (neigh == NULL) { |
Murat Sezgin | f21210e | 2016-04-04 13:58:20 -0700 | [diff] [blame] | 975 | DEBUG_TRACE("Neighbour lookup failure for destination IPv6 address " ECM_IP_ADDR_OCTAL_FMT "\n", ECM_IP_ADDR_TO_OCTAL(addr)); |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 976 | dst_release(&rt6i->dst); |
| 977 | return; |
| 978 | } |
| 979 | |
| 980 | /* |
| 981 | * Issue a Neighbour soliciation request |
| 982 | */ |
| 983 | DEBUG_TRACE("Issue Neighbour solicitation request\n"); |
Murat Sezgin | e1c51d8 | 2016-02-10 16:42:58 -0800 | [diff] [blame] | 984 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0)) |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 985 | ndisc_send_ns(dev, neigh, &dst_addr, &mc_dst_addr, &src_addr); |
Murat Sezgin | e1c51d8 | 2016-02-10 16:42:58 -0800 | [diff] [blame] | 986 | #else |
| 987 | ndisc_send_ns(dev, &dst_addr, &mc_dst_addr, &src_addr); |
| 988 | #endif |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 989 | neigh_release(neigh); |
| 990 | dst_release(&rt6i->dst); |
| 991 | } |
| 992 | EXPORT_SYMBOL(ecm_interface_send_neighbour_solicitation); |
| 993 | #endif |
| 994 | |
| 995 | /* |
| 996 | * ecm_interface_send_arp_request() |
| 997 | * Issue and ARP request. |
| 998 | */ |
| 999 | void ecm_interface_send_arp_request(struct net_device *dest_dev, ip_addr_t dest_addr, bool on_link, ip_addr_t gw_addr) |
| 1000 | { |
| 1001 | /* |
| 1002 | * Possible ARP does not know the address yet |
| 1003 | */ |
Murat Sezgin | 4c09321 | 2016-03-24 14:59:02 -0700 | [diff] [blame] | 1004 | struct neighbour *neigh; |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 1005 | __be32 ipv4_addr; |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 1006 | |
| 1007 | /* |
Murat Sezgin | 987493e | 2016-04-15 12:33:47 -0700 | [diff] [blame] | 1008 | * Convert the ECM IP address type to network order IPv4 address. |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 1009 | */ |
| 1010 | ECM_IP_ADDR_TO_NIN4_ADDR(ipv4_addr, dest_addr); |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 1011 | |
| 1012 | /* |
| 1013 | * If we have a GW for this address, then we have to send ARP request to the GW |
| 1014 | */ |
| 1015 | if (!on_link && !ECM_IP_ADDR_IS_NULL(gw_addr)) { |
| 1016 | ECM_IP_ADDR_TO_NIN4_ADDR(ipv4_addr, gw_addr); |
| 1017 | } |
| 1018 | |
Murat Sezgin | 4c09321 | 2016-03-24 14:59:02 -0700 | [diff] [blame] | 1019 | /* |
| 1020 | * If we don't have this neighbor, create it before sending the arp request, |
| 1021 | * so that when we receive the arp reply we update the neigh entry. |
| 1022 | */ |
| 1023 | neigh = neigh_lookup(&arp_tbl, &ipv4_addr, dest_dev); |
| 1024 | if (!neigh) { |
Murat Sezgin | 987493e | 2016-04-15 12:33:47 -0700 | [diff] [blame] | 1025 | neigh = neigh_create(&arp_tbl, &ipv4_addr, dest_dev); |
| 1026 | if (IS_ERR(neigh)) { |
| 1027 | DEBUG_WARN("Unable to create ARP request neigh for %pI4\n", &ipv4_addr); |
| 1028 | return; |
| 1029 | } |
Murat Sezgin | 4c09321 | 2016-03-24 14:59:02 -0700 | [diff] [blame] | 1030 | } |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 1031 | |
Murat Sezgin | 987493e | 2016-04-15 12:33:47 -0700 | [diff] [blame] | 1032 | DEBUG_TRACE("Send ARP for %pI4\n", &ipv4_addr); |
| 1033 | neigh_event_send(neigh, NULL); |
| 1034 | neigh_release(neigh); |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 1035 | } |
| 1036 | EXPORT_SYMBOL(ecm_interface_send_arp_request); |
| 1037 | |
Xiaoping Fan | c773546 | 2015-08-09 18:57:26 -0700 | [diff] [blame] | 1038 | /* |
| 1039 | * ecm_interface_ipv4_neigh_get() |
| 1040 | * Returns neighbour reference for a given IP address which must be released when you are done with it. |
| 1041 | * |
| 1042 | * Returns NULL on fail. |
| 1043 | */ |
| 1044 | struct neighbour *ecm_interface_ipv4_neigh_get(ip_addr_t addr) |
| 1045 | { |
| 1046 | struct neighbour *neigh; |
| 1047 | struct rtable *rt; |
| 1048 | struct dst_entry *dst; |
| 1049 | __be32 ipv4_addr; |
| 1050 | |
| 1051 | ECM_IP_ADDR_TO_NIN4_ADDR(ipv4_addr, addr); |
| 1052 | rt = ip_route_output(&init_net, ipv4_addr, 0, 0, 0); |
| 1053 | if (IS_ERR(rt)) { |
| 1054 | return NULL; |
| 1055 | } |
| 1056 | dst = (struct dst_entry *)rt; |
| 1057 | neigh = dst_neigh_lookup(dst, &ipv4_addr); |
| 1058 | ip_rt_put(rt); |
| 1059 | return neigh; |
| 1060 | } |
| 1061 | |
| 1062 | #ifdef ECM_IPV6_ENABLE |
| 1063 | /* |
| 1064 | * ecm_interface_ipv6_neigh_get() |
| 1065 | * Returns neighbour reference for a given IP address which must be released when you are done with it. |
| 1066 | * |
| 1067 | * Returns NULL on fail. |
| 1068 | */ |
| 1069 | struct neighbour *ecm_interface_ipv6_neigh_get(ip_addr_t addr) |
| 1070 | { |
| 1071 | struct neighbour *neigh; |
| 1072 | struct rt6_info *rt; |
| 1073 | struct dst_entry *dst; |
| 1074 | struct in6_addr ipv6_addr; |
| 1075 | |
| 1076 | ECM_IP_ADDR_TO_NIN6_ADDR(ipv6_addr, addr); |
| 1077 | rt = rt6_lookup(&init_net, &ipv6_addr, NULL, 0, 0); |
| 1078 | if (!rt) { |
| 1079 | return NULL; |
| 1080 | } |
| 1081 | dst = (struct dst_entry *)rt; |
| 1082 | neigh = dst_neigh_lookup(dst, &ipv6_addr); |
| 1083 | dst_release(dst); |
| 1084 | return neigh; |
| 1085 | } |
| 1086 | #endif |
| 1087 | |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 1088 | /* |
Shyam Sunder | 2ca0249 | 2016-08-05 20:55:12 +0530 | [diff] [blame] | 1089 | * ecm_interface_is_pptp() |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 1090 | * skip pptp tunnel encapsulated traffic |
| 1091 | * |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 1092 | * ECM does not handle PPTP, |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 1093 | * this function detects packets of that type so they can be skipped over to improve their throughput. |
| 1094 | */ |
Shyam Sunder | 2ca0249 | 2016-08-05 20:55:12 +0530 | [diff] [blame] | 1095 | bool ecm_interface_is_pptp(struct sk_buff *skb, const struct net_device *out) |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 1096 | { |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 1097 | struct net_device *in; |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 1098 | |
ratheesh kannoth | f4801a0 | 2016-12-09 22:46:39 +0530 | [diff] [blame] | 1099 | /* |
| 1100 | * skip first pass of l2tp/pptp tunnel encapsulated traffic |
| 1101 | */ |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 1102 | if (out->type == ARPHRD_PPP) { |
ratheesh kannoth | f4801a0 | 2016-12-09 22:46:39 +0530 | [diff] [blame] | 1103 | if (out->priv_flags & IFF_PPP_PPTP) { |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 1104 | return true; |
| 1105 | } |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | in = dev_get_by_index(&init_net, skb->skb_iif); |
ratheesh kannoth | 08b8e44 | 2015-10-02 00:24:55 +0530 | [diff] [blame] | 1109 | if (!in) { |
| 1110 | return true; |
| 1111 | } |
| 1112 | |
| 1113 | if (in->type == ARPHRD_PPP) { |
ratheesh kannoth | f4801a0 | 2016-12-09 22:46:39 +0530 | [diff] [blame] | 1114 | if (in->priv_flags & IFF_PPP_PPTP) { |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 1115 | dev_put(in); |
| 1116 | return true; |
| 1117 | } |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | dev_put(in); |
| 1121 | return false; |
| 1122 | } |
| 1123 | |
Shyam Sunder | 2ca0249 | 2016-08-05 20:55:12 +0530 | [diff] [blame] | 1124 | #ifdef ECM_INTERFACE_PPP_ENABLE |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 1125 | /* |
Shyam Sunder | 2ca0249 | 2016-08-05 20:55:12 +0530 | [diff] [blame] | 1126 | * ecm_interface_is_l2tp_packet_by_version() |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 1127 | * Check version of l2tp tunnel encapsulated traffic |
| 1128 | * |
| 1129 | * ECM does not handle l2tp, |
| 1130 | * this function detects packets of that type so they can be skipped over to improve their throughput. |
| 1131 | */ |
Shyam Sunder | 2ca0249 | 2016-08-05 20:55:12 +0530 | [diff] [blame] | 1132 | bool ecm_interface_is_l2tp_packet_by_version(struct sk_buff *skb, const struct net_device *out, int ver) |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 1133 | { |
ratheesh kannoth | f4801a0 | 2016-12-09 22:46:39 +0530 | [diff] [blame] | 1134 | uint32_t flag = 0; |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 1135 | struct net_device *in; |
| 1136 | |
ratheesh kannoth | f4801a0 | 2016-12-09 22:46:39 +0530 | [diff] [blame] | 1137 | switch (ver) { |
| 1138 | case 2: |
| 1139 | flag = IFF_PPP_L2TPV2; |
| 1140 | break; |
| 1141 | case 3: |
| 1142 | flag = IFF_PPP_L2TPV3; |
| 1143 | break; |
| 1144 | default: |
| 1145 | break; |
| 1146 | } |
| 1147 | |
| 1148 | /* |
| 1149 | * skip first pass of l2tp/pptp tunnel encapsulated traffic |
| 1150 | */ |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 1151 | if (out->type == ARPHRD_PPP) { |
ratheesh kannoth | f4801a0 | 2016-12-09 22:46:39 +0530 | [diff] [blame] | 1152 | if (out->priv_flags & flag) { |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 1153 | return true; |
| 1154 | } |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | in = dev_get_by_index(&init_net, skb->skb_iif); |
| 1158 | if (!in) { |
| 1159 | return true; |
| 1160 | } |
| 1161 | |
| 1162 | if (in->type == ARPHRD_PPP) { |
ratheesh kannoth | f4801a0 | 2016-12-09 22:46:39 +0530 | [diff] [blame] | 1163 | if (in->priv_flags & flag) { |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 1164 | dev_put(in); |
| 1165 | return true; |
| 1166 | } |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 1167 | } |
| 1168 | |
ratheesh kannoth | 08b8e44 | 2015-10-02 00:24:55 +0530 | [diff] [blame] | 1169 | dev_put(in); |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 1170 | return false; |
| 1171 | } |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 1172 | |
Xiaoping Fan | 80e406b | 2015-01-29 16:15:31 -0800 | [diff] [blame] | 1173 | /* |
Shyam Sunder | 2ca0249 | 2016-08-05 20:55:12 +0530 | [diff] [blame] | 1174 | * ecm_interface_is_l2tp_pptp() |
Xiaoping Fan | 80e406b | 2015-01-29 16:15:31 -0800 | [diff] [blame] | 1175 | * skip l2tp/pptp tunnel encapsulated traffic |
| 1176 | * |
| 1177 | * ECM does not handle L2TP or PPTP encapsulated packets, |
| 1178 | * this function detects packets of that type so they can be skipped over to improve their throughput. |
| 1179 | */ |
Shyam Sunder | 2ca0249 | 2016-08-05 20:55:12 +0530 | [diff] [blame] | 1180 | bool ecm_interface_is_l2tp_pptp(struct sk_buff *skb, const struct net_device *out) |
Xiaoping Fan | 80e406b | 2015-01-29 16:15:31 -0800 | [diff] [blame] | 1181 | { |
ratheesh kannoth | f4801a0 | 2016-12-09 22:46:39 +0530 | [diff] [blame] | 1182 | struct net_device *in; |
Xiaoping Fan | 80e406b | 2015-01-29 16:15:31 -0800 | [diff] [blame] | 1183 | |
| 1184 | /* |
| 1185 | * skip first pass of l2tp/pptp tunnel encapsulated traffic |
| 1186 | */ |
| 1187 | if (out->type == ARPHRD_PPP) { |
ratheesh kannoth | f4801a0 | 2016-12-09 22:46:39 +0530 | [diff] [blame] | 1188 | if (out->priv_flags & (IFF_PPP_L2TPV2 | IFF_PPP_L2TPV3 | |
| 1189 | IFF_PPP_PPTP)) { |
| 1190 | return true; |
Xiaoping Fan | 80e406b | 2015-01-29 16:15:31 -0800 | [diff] [blame] | 1191 | } |
| 1192 | } |
| 1193 | |
ratheesh kannoth | f4801a0 | 2016-12-09 22:46:39 +0530 | [diff] [blame] | 1194 | in = dev_get_by_index(&init_net, skb->skb_iif); |
| 1195 | if (!in) { |
Xiaoping Fan | 80e406b | 2015-01-29 16:15:31 -0800 | [diff] [blame] | 1196 | return true; |
| 1197 | } |
| 1198 | |
ratheesh kannoth | f4801a0 | 2016-12-09 22:46:39 +0530 | [diff] [blame] | 1199 | if (in->type == ARPHRD_PPP) { |
| 1200 | if (in->priv_flags & (IFF_PPP_L2TPV2 | IFF_PPP_L2TPV3 | |
| 1201 | IFF_PPP_PPTP)) { |
| 1202 | dev_put(in); |
| 1203 | return true; |
| 1204 | } |
| 1205 | } |
| 1206 | |
| 1207 | dev_put(in); |
Xiaoping Fan | 80e406b | 2015-01-29 16:15:31 -0800 | [diff] [blame] | 1208 | return false; |
ratheesh kannoth | f4801a0 | 2016-12-09 22:46:39 +0530 | [diff] [blame] | 1209 | |
Xiaoping Fan | 80e406b | 2015-01-29 16:15:31 -0800 | [diff] [blame] | 1210 | } |
| 1211 | #endif |
| 1212 | |
Gareth Williams | 141d238 | 2014-11-25 11:35:19 -0800 | [diff] [blame] | 1213 | #ifdef ECM_INTERFACE_VLAN_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1214 | /* |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1215 | * ecm_interface_vlan_interface_establish() |
| 1216 | * Returns a reference to a iface of the VLAN type, possibly creating one if necessary. |
| 1217 | * Returns NULL on failure or a reference to interface. |
| 1218 | */ |
| 1219 | static struct ecm_db_iface_instance *ecm_interface_vlan_interface_establish(struct ecm_db_interface_info_vlan *type_info, |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1220 | char *dev_name, int32_t dev_interface_num, int32_t ae_interface_num, int32_t mtu) |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1221 | { |
| 1222 | struct ecm_db_iface_instance *nii; |
| 1223 | struct ecm_db_iface_instance *ii; |
| 1224 | |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1225 | DEBUG_INFO("Establish VLAN iface: %s with address: %pM, vlan tag: %u, vlan_tpid: %x MTU: %d, if num: %d, accel engine if id: %d\n", |
| 1226 | dev_name, type_info->address, type_info->vlan_tag, type_info->vlan_tpid, mtu, dev_interface_num, ae_interface_num); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1227 | |
| 1228 | /* |
| 1229 | * Locate the iface |
| 1230 | */ |
Radha krishna Simha Jiguru | f7dc34c | 2014-05-12 18:59:07 +0530 | [diff] [blame] | 1231 | ii = ecm_db_iface_find_and_ref_vlan(type_info->address, type_info->vlan_tag, type_info->vlan_tpid); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1232 | if (ii) { |
| 1233 | DEBUG_TRACE("%p: iface established\n", ii); |
| 1234 | return ii; |
| 1235 | } |
| 1236 | |
| 1237 | /* |
| 1238 | * No iface - create one |
| 1239 | */ |
| 1240 | nii = ecm_db_iface_alloc(); |
| 1241 | if (!nii) { |
| 1242 | DEBUG_WARN("Failed to establish iface\n"); |
| 1243 | return NULL; |
| 1244 | } |
| 1245 | |
| 1246 | /* |
| 1247 | * Add iface into the database, atomically to avoid races creating the same thing |
| 1248 | */ |
| 1249 | spin_lock_bh(&ecm_interface_lock); |
Radha krishna Simha Jiguru | f7dc34c | 2014-05-12 18:59:07 +0530 | [diff] [blame] | 1250 | ii = ecm_db_iface_find_and_ref_vlan(type_info->address, type_info->vlan_tag, type_info->vlan_tpid); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1251 | if (ii) { |
| 1252 | spin_unlock_bh(&ecm_interface_lock); |
| 1253 | ecm_db_iface_deref(nii); |
| 1254 | return ii; |
| 1255 | } |
Radha krishna Simha Jiguru | f7dc34c | 2014-05-12 18:59:07 +0530 | [diff] [blame] | 1256 | ecm_db_iface_add_vlan(nii, type_info->address, type_info->vlan_tag, type_info->vlan_tpid, dev_name, |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1257 | mtu, dev_interface_num, ae_interface_num, NULL, nii); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1258 | spin_unlock_bh(&ecm_interface_lock); |
| 1259 | |
| 1260 | DEBUG_TRACE("%p: vlan iface established\n", nii); |
| 1261 | return nii; |
| 1262 | } |
Gareth Williams | 141d238 | 2014-11-25 11:35:19 -0800 | [diff] [blame] | 1263 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1264 | |
| 1265 | /* |
| 1266 | * ecm_interface_bridge_interface_establish() |
| 1267 | * Returns a reference to a iface of the BRIDGE type, possibly creating one if necessary. |
| 1268 | * Returns NULL on failure or a reference to interface. |
| 1269 | */ |
| 1270 | static struct ecm_db_iface_instance *ecm_interface_bridge_interface_establish(struct ecm_db_interface_info_bridge *type_info, |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1271 | char *dev_name, int32_t dev_interface_num, int32_t ae_interface_num, int32_t mtu) |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1272 | { |
| 1273 | struct ecm_db_iface_instance *nii; |
| 1274 | struct ecm_db_iface_instance *ii; |
| 1275 | |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1276 | DEBUG_INFO("Establish BRIDGE iface: %s with address: %pM, MTU: %d, if num: %d, accel engine if id: %d\n", |
| 1277 | dev_name, type_info->address, mtu, dev_interface_num, ae_interface_num); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1278 | |
| 1279 | /* |
| 1280 | * Locate the iface |
| 1281 | */ |
| 1282 | ii = ecm_db_iface_find_and_ref_bridge(type_info->address); |
| 1283 | if (ii) { |
| 1284 | DEBUG_TRACE("%p: iface established\n", ii); |
| 1285 | return ii; |
| 1286 | } |
| 1287 | |
| 1288 | /* |
| 1289 | * No iface - create one |
| 1290 | */ |
| 1291 | nii = ecm_db_iface_alloc(); |
| 1292 | if (!nii) { |
| 1293 | DEBUG_WARN("Failed to establish iface\n"); |
| 1294 | return NULL; |
| 1295 | } |
| 1296 | |
| 1297 | /* |
| 1298 | * Add iface into the database, atomically to avoid races creating the same thing |
| 1299 | */ |
| 1300 | spin_lock_bh(&ecm_interface_lock); |
| 1301 | ii = ecm_db_iface_find_and_ref_bridge(type_info->address); |
| 1302 | if (ii) { |
| 1303 | spin_unlock_bh(&ecm_interface_lock); |
| 1304 | ecm_db_iface_deref(nii); |
| 1305 | return ii; |
| 1306 | } |
| 1307 | ecm_db_iface_add_bridge(nii, type_info->address, dev_name, |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1308 | mtu, dev_interface_num, ae_interface_num, NULL, nii); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1309 | spin_unlock_bh(&ecm_interface_lock); |
| 1310 | |
| 1311 | DEBUG_TRACE("%p: bridge iface established\n", nii); |
| 1312 | return nii; |
| 1313 | } |
| 1314 | |
Murat Sezgin | 910c966 | 2015-03-11 16:15:06 -0700 | [diff] [blame] | 1315 | #ifdef ECM_INTERFACE_BOND_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1316 | /* |
| 1317 | * ecm_interface_lag_interface_establish() |
| 1318 | * Returns a reference to a iface of the LAG type, possibly creating one if necessary. |
| 1319 | * Returns NULL on failure or a reference to interface. |
| 1320 | */ |
| 1321 | static struct ecm_db_iface_instance *ecm_interface_lag_interface_establish(struct ecm_db_interface_info_lag *type_info, |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1322 | char *dev_name, int32_t dev_interface_num, int32_t ae_interface_num, int32_t mtu) |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1323 | { |
| 1324 | struct ecm_db_iface_instance *nii; |
| 1325 | struct ecm_db_iface_instance *ii; |
| 1326 | |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1327 | DEBUG_INFO("Establish LAG iface: %s with address: %pM, MTU: %d, if num: %d, accel engine if id: %d\n", |
| 1328 | dev_name, type_info->address, mtu, dev_interface_num, ae_interface_num); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1329 | |
| 1330 | /* |
| 1331 | * Locate the iface |
| 1332 | */ |
| 1333 | ii = ecm_db_iface_find_and_ref_lag(type_info->address); |
| 1334 | if (ii) { |
| 1335 | DEBUG_TRACE("%p: iface established\n", ii); |
| 1336 | return ii; |
| 1337 | } |
| 1338 | |
| 1339 | /* |
| 1340 | * No iface - create one |
| 1341 | */ |
| 1342 | nii = ecm_db_iface_alloc(); |
| 1343 | if (!nii) { |
| 1344 | DEBUG_WARN("Failed to establish iface\n"); |
| 1345 | return NULL; |
| 1346 | } |
| 1347 | |
| 1348 | /* |
| 1349 | * Add iface into the database, atomically to avoid races creating the same thing |
| 1350 | */ |
| 1351 | spin_lock_bh(&ecm_interface_lock); |
| 1352 | ii = ecm_db_iface_find_and_ref_lag(type_info->address); |
| 1353 | if (ii) { |
| 1354 | spin_unlock_bh(&ecm_interface_lock); |
| 1355 | ecm_db_iface_deref(nii); |
| 1356 | return ii; |
| 1357 | } |
| 1358 | ecm_db_iface_add_lag(nii, type_info->address, dev_name, |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1359 | mtu, dev_interface_num, ae_interface_num, NULL, nii); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1360 | spin_unlock_bh(&ecm_interface_lock); |
| 1361 | |
| 1362 | DEBUG_TRACE("%p: lag iface established\n", nii); |
| 1363 | return nii; |
| 1364 | } |
Murat Sezgin | 910c966 | 2015-03-11 16:15:06 -0700 | [diff] [blame] | 1365 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1366 | |
| 1367 | /* |
| 1368 | * ecm_interface_ethernet_interface_establish() |
| 1369 | * Returns a reference to a iface of the ETHERNET type, possibly creating one if necessary. |
| 1370 | * Returns NULL on failure or a reference to interface. |
| 1371 | */ |
| 1372 | static struct ecm_db_iface_instance *ecm_interface_ethernet_interface_establish(struct ecm_db_interface_info_ethernet *type_info, |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1373 | char *dev_name, int32_t dev_interface_num, int32_t ae_interface_num, int32_t mtu) |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1374 | { |
| 1375 | struct ecm_db_iface_instance *nii; |
| 1376 | struct ecm_db_iface_instance *ii; |
| 1377 | |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1378 | DEBUG_INFO("Establish ETHERNET iface: %s with address: %pM, MTU: %d, if num: %d, accel engine if id: %d\n", |
| 1379 | dev_name, type_info->address, mtu, dev_interface_num, ae_interface_num); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1380 | |
| 1381 | /* |
| 1382 | * Locate the iface |
| 1383 | */ |
Tushar Mathur | 4ab0bf9 | 2014-06-10 20:37:07 +0530 | [diff] [blame] | 1384 | ii = ecm_db_iface_ifidx_find_and_ref_ethernet(type_info->address, dev_interface_num); |
| 1385 | |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1386 | if (ii) { |
| 1387 | DEBUG_TRACE("%p: iface established\n", ii); |
Murat Sezgin | 5f2947a | 2016-06-28 12:09:33 -0700 | [diff] [blame] | 1388 | /* |
| 1389 | * Update the accel engine interface identifier, just in case it was changed. |
| 1390 | */ |
| 1391 | ecm_db_iface_ae_interface_identifier_set(ii, ae_interface_num); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1392 | return ii; |
| 1393 | } |
| 1394 | |
| 1395 | /* |
| 1396 | * No iface - create one |
| 1397 | */ |
| 1398 | nii = ecm_db_iface_alloc(); |
| 1399 | if (!nii) { |
| 1400 | DEBUG_WARN("Failed to establish iface\n"); |
| 1401 | return NULL; |
| 1402 | } |
| 1403 | |
| 1404 | /* |
| 1405 | * Add iface into the database, atomically to avoid races creating the same thing |
| 1406 | */ |
| 1407 | spin_lock_bh(&ecm_interface_lock); |
Tushar Mathur | 4ab0bf9 | 2014-06-10 20:37:07 +0530 | [diff] [blame] | 1408 | ii = ecm_db_iface_ifidx_find_and_ref_ethernet(type_info->address, dev_interface_num); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1409 | if (ii) { |
| 1410 | spin_unlock_bh(&ecm_interface_lock); |
| 1411 | ecm_db_iface_deref(nii); |
| 1412 | return ii; |
| 1413 | } |
| 1414 | ecm_db_iface_add_ethernet(nii, type_info->address, dev_name, |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1415 | mtu, dev_interface_num, ae_interface_num, NULL, nii); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1416 | spin_unlock_bh(&ecm_interface_lock); |
| 1417 | |
| 1418 | DEBUG_TRACE("%p: ethernet iface established\n", nii); |
| 1419 | return nii; |
| 1420 | } |
| 1421 | |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 1422 | #ifdef ECM_INTERFACE_PPPOE_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1423 | /* |
| 1424 | * ecm_interface_pppoe_interface_establish() |
| 1425 | * Returns a reference to a iface of the PPPoE type, possibly creating one if necessary. |
| 1426 | * Returns NULL on failure or a reference to interface. |
| 1427 | */ |
| 1428 | static struct ecm_db_iface_instance *ecm_interface_pppoe_interface_establish(struct ecm_db_interface_info_pppoe *type_info, |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1429 | char *dev_name, int32_t dev_interface_num, int32_t ae_interface_num, int32_t mtu) |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1430 | { |
| 1431 | struct ecm_db_iface_instance *nii; |
| 1432 | struct ecm_db_iface_instance *ii; |
| 1433 | |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1434 | DEBUG_INFO("Establish PPPoE iface: %s with session id: %u, remote mac: %pM, MTU: %d, if num: %d, accel engine if id: %d\n", |
| 1435 | dev_name, type_info->pppoe_session_id, type_info->remote_mac, mtu, dev_interface_num, ae_interface_num); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1436 | |
| 1437 | /* |
| 1438 | * Locate the iface |
| 1439 | */ |
| 1440 | ii = ecm_db_iface_find_and_ref_pppoe(type_info->pppoe_session_id, type_info->remote_mac); |
| 1441 | if (ii) { |
| 1442 | DEBUG_TRACE("%p: iface established\n", ii); |
| 1443 | return ii; |
| 1444 | } |
| 1445 | |
| 1446 | /* |
| 1447 | * No iface - create one |
| 1448 | */ |
| 1449 | nii = ecm_db_iface_alloc(); |
| 1450 | if (!nii) { |
| 1451 | DEBUG_WARN("Failed to establish iface\n"); |
| 1452 | return NULL; |
| 1453 | } |
| 1454 | |
| 1455 | /* |
| 1456 | * Add iface into the database, atomically to avoid races creating the same thing |
| 1457 | */ |
| 1458 | spin_lock_bh(&ecm_interface_lock); |
| 1459 | ii = ecm_db_iface_find_and_ref_pppoe(type_info->pppoe_session_id, type_info->remote_mac); |
| 1460 | if (ii) { |
| 1461 | spin_unlock_bh(&ecm_interface_lock); |
| 1462 | ecm_db_iface_deref(nii); |
| 1463 | return ii; |
| 1464 | } |
| 1465 | ecm_db_iface_add_pppoe(nii, type_info->pppoe_session_id, type_info->remote_mac, dev_name, |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1466 | mtu, dev_interface_num, ae_interface_num, NULL, nii); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1467 | spin_unlock_bh(&ecm_interface_lock); |
| 1468 | |
| 1469 | DEBUG_TRACE("%p: pppoe iface established\n", nii); |
| 1470 | return nii; |
| 1471 | } |
Gareth Williams | c5b9d71 | 2014-05-09 20:40:07 +0100 | [diff] [blame] | 1472 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1473 | |
ratheesh kannoth | cfdcb33 | 2015-12-24 07:19:18 +0530 | [diff] [blame] | 1474 | #ifdef ECM_INTERFACE_MAP_T_ENABLE |
| 1475 | /* |
| 1476 | * ecm_interface_map_t_interface_establish() |
| 1477 | * Returns a reference to a iface of the PPPoE type, possibly creating one if necessary. |
| 1478 | * Returns NULL on failure or a reference to interface. |
| 1479 | */ |
| 1480 | static struct ecm_db_iface_instance *ecm_interface_map_t_interface_establish(struct ecm_db_interface_info_map_t *type_info, |
| 1481 | char *dev_name, int32_t dev_interface_num, int32_t ae_interface_num, int32_t mtu) |
| 1482 | { |
| 1483 | struct ecm_db_iface_instance *nii; |
| 1484 | struct ecm_db_iface_instance *ii; |
| 1485 | |
| 1486 | DEBUG_TRACE("Establish MAP-T iface: %s MTU: %d, if num: %d, accel engine if id: %d\n", |
| 1487 | dev_name, mtu, dev_interface_num, ae_interface_num); |
| 1488 | |
| 1489 | /* |
| 1490 | * Locate the iface |
| 1491 | */ |
Manish Verma | f70e161 | 2018-08-20 01:15:40 +0530 | [diff] [blame] | 1492 | ii = ecm_db_iface_find_and_ref_map_t(type_info->if_index, ae_interface_num); |
ratheesh kannoth | cfdcb33 | 2015-12-24 07:19:18 +0530 | [diff] [blame] | 1493 | if (ii) { |
| 1494 | DEBUG_TRACE("%p: iface established\n", ii); |
ratheesh kannoth | cfdcb33 | 2015-12-24 07:19:18 +0530 | [diff] [blame] | 1495 | return ii; |
| 1496 | } |
| 1497 | |
| 1498 | /* |
| 1499 | * No iface - create one |
| 1500 | */ |
| 1501 | nii = ecm_db_iface_alloc(); |
| 1502 | if (!nii) { |
| 1503 | DEBUG_WARN("Failed to establish iface\n"); |
| 1504 | return NULL; |
| 1505 | } |
| 1506 | |
| 1507 | /* |
| 1508 | * Add iface into the database, atomically to avoid races creating the same thing |
| 1509 | */ |
| 1510 | spin_lock_bh(&ecm_interface_lock); |
Manish Verma | f70e161 | 2018-08-20 01:15:40 +0530 | [diff] [blame] | 1511 | ii = ecm_db_iface_find_and_ref_map_t(type_info->if_index, ae_interface_num); |
ratheesh kannoth | cfdcb33 | 2015-12-24 07:19:18 +0530 | [diff] [blame] | 1512 | if (ii) { |
| 1513 | spin_unlock_bh(&ecm_interface_lock); |
| 1514 | ecm_db_iface_deref(nii); |
ratheesh kannoth | cfdcb33 | 2015-12-24 07:19:18 +0530 | [diff] [blame] | 1515 | return ii; |
| 1516 | } |
| 1517 | ecm_db_iface_add_map_t(nii, type_info, dev_name, |
| 1518 | mtu, dev_interface_num, ae_interface_num, NULL, nii); |
| 1519 | spin_unlock_bh(&ecm_interface_lock); |
| 1520 | |
| 1521 | DEBUG_TRACE("%p: map_t iface established\n", nii); |
| 1522 | return nii; |
| 1523 | } |
| 1524 | #endif |
| 1525 | |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 1526 | #ifdef ECM_INTERFACE_L2TPV2_ENABLE |
| 1527 | /* |
| 1528 | * ecm_interface_pppol2tpv2_interface_establish() |
| 1529 | * Returns a reference to a iface of the PPPoL2TPV2 type, possibly creating one if necessary. |
| 1530 | * Returns NULL on failure or a reference to interface. |
| 1531 | */ |
| 1532 | static struct ecm_db_iface_instance *ecm_interface_pppol2tpv2_interface_establish(struct ecm_db_interface_info_pppol2tpv2 *type_info, |
| 1533 | char *dev_name, int32_t dev_interface_num, int32_t ae_interface_num, int32_t mtu) |
| 1534 | { |
| 1535 | struct ecm_db_iface_instance *nii; |
| 1536 | struct ecm_db_iface_instance *ii; |
| 1537 | |
| 1538 | DEBUG_INFO("Establish PPPol2tp iface: %s with tunnel id=%u session id %u\n", dev_name, type_info->l2tp.tunnel.tunnel_id, |
| 1539 | type_info->l2tp.session.session_id); |
| 1540 | /* |
| 1541 | * Locate the iface |
| 1542 | */ |
| 1543 | ii = ecm_db_iface_find_and_ref_pppol2tpv2(type_info->l2tp.tunnel.tunnel_id, type_info->l2tp.session.session_id); |
| 1544 | if (ii) { |
| 1545 | DEBUG_TRACE("%p: iface established\n", ii); |
ratheesh kannoth | ed72185 | 2015-09-28 12:39:52 +0530 | [diff] [blame] | 1546 | ecm_db_iface_update_ae_interface_identifier(ii, ae_interface_num); |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 1547 | return ii; |
| 1548 | } |
| 1549 | |
| 1550 | /* |
| 1551 | * No iface - create one |
| 1552 | */ |
| 1553 | nii = ecm_db_iface_alloc(); |
| 1554 | if (!nii) { |
| 1555 | DEBUG_WARN("Failed to establish iface\n"); |
| 1556 | return NULL; |
| 1557 | } |
| 1558 | |
| 1559 | /* |
| 1560 | * Add iface into the database, atomically to avoid races creating the same thing |
| 1561 | */ |
| 1562 | spin_lock_bh(&ecm_interface_lock); |
| 1563 | ii = ecm_db_iface_find_and_ref_pppol2tpv2(type_info->l2tp.tunnel.tunnel_id, type_info->l2tp.session.session_id); |
| 1564 | if (ii) { |
| 1565 | spin_unlock_bh(&ecm_interface_lock); |
| 1566 | ecm_db_iface_deref(nii); |
ratheesh kannoth | ed72185 | 2015-09-28 12:39:52 +0530 | [diff] [blame] | 1567 | ecm_db_iface_update_ae_interface_identifier(ii, ae_interface_num); |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 1568 | return ii; |
| 1569 | } |
| 1570 | |
| 1571 | ecm_db_iface_add_pppol2tpv2(nii, type_info, dev_name, mtu, dev_interface_num, ae_interface_num, NULL, nii); |
| 1572 | spin_unlock_bh(&ecm_interface_lock); |
| 1573 | |
| 1574 | DEBUG_TRACE("%p: pppol2tpv2 iface established\n", nii); |
| 1575 | return nii; |
| 1576 | } |
| 1577 | |
| 1578 | #endif |
| 1579 | |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 1580 | #ifdef ECM_INTERFACE_PPTP_ENABLE |
| 1581 | /* |
| 1582 | * ecm_interface_pptp_interface_establish() |
| 1583 | * Returns a reference to a iface of the PPTP type, possibly creating one if necessary. |
| 1584 | * Returns NULL on failure or a reference to interface. |
| 1585 | */ |
| 1586 | static struct ecm_db_iface_instance *ecm_interface_pptp_interface_establish(struct ecm_db_interface_info_pptp *type_info, |
| 1587 | char *dev_name, int32_t dev_interface_num, int32_t ae_interface_num, int32_t mtu) |
| 1588 | { |
| 1589 | struct ecm_db_iface_instance *nii; |
| 1590 | struct ecm_db_iface_instance *ii; |
| 1591 | |
| 1592 | DEBUG_INFO("Establish PPTP iface: %s with local call id %u peer call id %u\n", dev_name, type_info->src_call_id, |
| 1593 | type_info->dst_call_id); |
| 1594 | /* |
| 1595 | * Locate the iface |
| 1596 | */ |
Swaraj Sha | 0562058 | 2018-08-15 23:21:16 +0530 | [diff] [blame] | 1597 | ii = ecm_db_iface_find_and_ref_pptp(type_info->src_call_id, type_info->dst_call_id, ae_interface_num); |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 1598 | if (ii) { |
| 1599 | DEBUG_TRACE("%p: iface established\n", ii); |
| 1600 | ecm_db_iface_update_ae_interface_identifier(ii, ae_interface_num); |
| 1601 | return ii; |
| 1602 | } |
| 1603 | |
| 1604 | /* |
| 1605 | * No iface - create one |
| 1606 | */ |
| 1607 | nii = ecm_db_iface_alloc(); |
| 1608 | if (!nii) { |
| 1609 | DEBUG_WARN("Failed to establish iface\n"); |
| 1610 | return NULL; |
| 1611 | } |
| 1612 | |
| 1613 | /* |
| 1614 | * Add iface into the database, atomically to avoid races creating the same thing |
| 1615 | */ |
| 1616 | spin_lock_bh(&ecm_interface_lock); |
Swaraj Sha | 0562058 | 2018-08-15 23:21:16 +0530 | [diff] [blame] | 1617 | ii = ecm_db_iface_find_and_ref_pptp(type_info->src_call_id, type_info->dst_call_id, ae_interface_num); |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 1618 | if (ii) { |
| 1619 | spin_unlock_bh(&ecm_interface_lock); |
| 1620 | ecm_db_iface_deref(nii); |
| 1621 | ecm_db_iface_update_ae_interface_identifier(ii, ae_interface_num); |
| 1622 | return ii; |
| 1623 | } |
| 1624 | |
| 1625 | ecm_db_iface_add_pptp(nii, type_info, dev_name, mtu, dev_interface_num, ae_interface_num, NULL, nii); |
| 1626 | spin_unlock_bh(&ecm_interface_lock); |
| 1627 | |
| 1628 | DEBUG_TRACE("%p: pptp iface established\n", nii); |
| 1629 | return nii; |
| 1630 | } |
| 1631 | #endif |
| 1632 | |
Suman Ghosh | 9e4245f | 2018-04-11 01:11:41 +0530 | [diff] [blame] | 1633 | #ifdef ECM_INTERFACE_GRE_TUN_ENABLE |
| 1634 | /* |
| 1635 | * ecm_interface_gre_tun_interface_establish() |
| 1636 | * Returns a reference to a iface of the gre type, possibly creating one if necessary. |
| 1637 | * Returns NULL on failure or a reference to interface. |
| 1638 | */ |
| 1639 | static struct ecm_db_iface_instance *ecm_interface_gre_tun_interface_establish(struct ecm_db_interface_info_gre_tun *type_info, |
| 1640 | char *dev_name, int32_t dev_interface_num, int32_t ae_interface_num, int32_t mtu) |
| 1641 | { |
| 1642 | struct ecm_db_iface_instance *nii; |
| 1643 | struct ecm_db_iface_instance *ii; |
| 1644 | |
| 1645 | DEBUG_TRACE("Establish GRE TUN iface: %s MTU: %d, if num: %d, accel engine if id: %d\n", |
| 1646 | dev_name, mtu, dev_interface_num, ae_interface_num); |
| 1647 | |
| 1648 | /* |
| 1649 | * Locate the iface |
| 1650 | */ |
Suman Ghosh | 8f199b2 | 2018-07-13 18:51:27 +0530 | [diff] [blame] | 1651 | ii = ecm_db_iface_find_and_ref_gre_tun(type_info->if_index, ae_interface_num); |
Suman Ghosh | 9e4245f | 2018-04-11 01:11:41 +0530 | [diff] [blame] | 1652 | if (ii) { |
| 1653 | DEBUG_TRACE("%p: iface established\n", ii); |
Suman Ghosh | 9e4245f | 2018-04-11 01:11:41 +0530 | [diff] [blame] | 1654 | return ii; |
| 1655 | } |
| 1656 | |
| 1657 | /* |
| 1658 | * No iface - create one |
| 1659 | */ |
| 1660 | nii = ecm_db_iface_alloc(); |
| 1661 | if (!nii) { |
| 1662 | DEBUG_WARN("Failed to establish iface\n"); |
| 1663 | return NULL; |
| 1664 | } |
| 1665 | |
| 1666 | /* |
| 1667 | * Add iface into the database, atomically to avoid races creating the same thing |
| 1668 | */ |
| 1669 | spin_lock_bh(&ecm_interface_lock); |
Suman Ghosh | 8f199b2 | 2018-07-13 18:51:27 +0530 | [diff] [blame] | 1670 | ii = ecm_db_iface_find_and_ref_gre_tun(type_info->if_index, ae_interface_num); |
Suman Ghosh | 9e4245f | 2018-04-11 01:11:41 +0530 | [diff] [blame] | 1671 | if (ii) { |
| 1672 | spin_unlock_bh(&ecm_interface_lock); |
| 1673 | ecm_db_iface_deref(nii); |
Suman Ghosh | 9e4245f | 2018-04-11 01:11:41 +0530 | [diff] [blame] | 1674 | return ii; |
| 1675 | } |
| 1676 | ecm_db_iface_add_gre_tun(nii, type_info, dev_name, |
| 1677 | mtu, dev_interface_num, ae_interface_num, NULL, nii); |
| 1678 | spin_unlock_bh(&ecm_interface_lock); |
| 1679 | |
| 1680 | DEBUG_TRACE("%p: gre iface established\n", nii); |
| 1681 | return nii; |
| 1682 | } |
| 1683 | #endif |
| 1684 | |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1685 | /* |
| 1686 | * ecm_interface_unknown_interface_establish() |
| 1687 | * Returns a reference to a iface of the UNKNOWN type, possibly creating one if necessary. |
| 1688 | * Returns NULL on failure or a reference to interface. |
| 1689 | */ |
| 1690 | static struct ecm_db_iface_instance *ecm_interface_unknown_interface_establish(struct ecm_db_interface_info_unknown *type_info, |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1691 | char *dev_name, int32_t dev_interface_num, int32_t ae_interface_num, int32_t mtu) |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1692 | { |
| 1693 | struct ecm_db_iface_instance *nii; |
| 1694 | struct ecm_db_iface_instance *ii; |
| 1695 | |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1696 | DEBUG_INFO("Establish UNKNOWN iface: %s with os_specific_ident: %u, MTU: %d, if num: %d, accel engine if id: %d\n", |
| 1697 | dev_name, type_info->os_specific_ident, mtu, dev_interface_num, ae_interface_num); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1698 | |
| 1699 | /* |
| 1700 | * Locate the iface |
| 1701 | */ |
| 1702 | ii = ecm_db_iface_find_and_ref_unknown(type_info->os_specific_ident); |
| 1703 | if (ii) { |
| 1704 | DEBUG_TRACE("%p: iface established\n", ii); |
| 1705 | return ii; |
| 1706 | } |
| 1707 | |
| 1708 | /* |
| 1709 | * No iface - create one |
| 1710 | */ |
| 1711 | nii = ecm_db_iface_alloc(); |
| 1712 | if (!nii) { |
| 1713 | DEBUG_WARN("Failed to establish iface\n"); |
| 1714 | return NULL; |
| 1715 | } |
| 1716 | |
| 1717 | /* |
| 1718 | * Add iface into the database, atomically to avoid races creating the same thing |
| 1719 | */ |
| 1720 | spin_lock_bh(&ecm_interface_lock); |
| 1721 | ii = ecm_db_iface_find_and_ref_unknown(type_info->os_specific_ident); |
| 1722 | if (ii) { |
| 1723 | spin_unlock_bh(&ecm_interface_lock); |
| 1724 | ecm_db_iface_deref(nii); |
| 1725 | return ii; |
| 1726 | } |
| 1727 | ecm_db_iface_add_unknown(nii, type_info->os_specific_ident, dev_name, |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1728 | mtu, dev_interface_num, ae_interface_num, NULL, nii); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1729 | spin_unlock_bh(&ecm_interface_lock); |
| 1730 | |
| 1731 | DEBUG_TRACE("%p: unknown iface established\n", nii); |
| 1732 | return nii; |
| 1733 | } |
| 1734 | |
| 1735 | /* |
| 1736 | * ecm_interface_loopback_interface_establish() |
| 1737 | * Returns a reference to a iface of the LOOPBACK type, possibly creating one if necessary. |
| 1738 | * Returns NULL on failure or a reference to interface. |
| 1739 | */ |
| 1740 | static struct ecm_db_iface_instance *ecm_interface_loopback_interface_establish(struct ecm_db_interface_info_loopback *type_info, |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1741 | char *dev_name, int32_t dev_interface_num, int32_t ae_interface_num, int32_t mtu) |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1742 | { |
| 1743 | struct ecm_db_iface_instance *nii; |
| 1744 | struct ecm_db_iface_instance *ii; |
| 1745 | |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1746 | DEBUG_INFO("Establish LOOPBACK iface: %s with os_specific_ident: %u, MTU: %d, if num: %d, accel engine if id: %d\n", |
| 1747 | dev_name, type_info->os_specific_ident, mtu, dev_interface_num, ae_interface_num); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1748 | |
| 1749 | /* |
| 1750 | * Locate the iface |
| 1751 | */ |
| 1752 | ii = ecm_db_iface_find_and_ref_loopback(type_info->os_specific_ident); |
| 1753 | if (ii) { |
| 1754 | DEBUG_TRACE("%p: iface established\n", ii); |
| 1755 | return ii; |
| 1756 | } |
| 1757 | |
| 1758 | /* |
| 1759 | * No iface - create one |
| 1760 | */ |
| 1761 | nii = ecm_db_iface_alloc(); |
| 1762 | if (!nii) { |
| 1763 | DEBUG_WARN("Failed to establish iface\n"); |
| 1764 | return NULL; |
| 1765 | } |
| 1766 | |
| 1767 | /* |
| 1768 | * Add iface into the database, atomically to avoid races creating the same thing |
| 1769 | */ |
| 1770 | spin_lock_bh(&ecm_interface_lock); |
| 1771 | ii = ecm_db_iface_find_and_ref_loopback(type_info->os_specific_ident); |
| 1772 | if (ii) { |
| 1773 | spin_unlock_bh(&ecm_interface_lock); |
| 1774 | ecm_db_iface_deref(nii); |
| 1775 | return ii; |
| 1776 | } |
| 1777 | ecm_db_iface_add_loopback(nii, type_info->os_specific_ident, dev_name, |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1778 | mtu, dev_interface_num, ae_interface_num, NULL, nii); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1779 | spin_unlock_bh(&ecm_interface_lock); |
| 1780 | |
| 1781 | DEBUG_TRACE("%p: loopback iface established\n", nii); |
| 1782 | return nii; |
| 1783 | } |
| 1784 | |
Murat Sezgin | 69a2753 | 2015-03-12 14:09:40 -0700 | [diff] [blame] | 1785 | #ifdef ECM_INTERFACE_IPSEC_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1786 | /* |
| 1787 | * ecm_interface_ipsec_tunnel_interface_establish() |
| 1788 | * Returns a reference to a iface of the IPSEC_TUNNEL type, possibly creating one if necessary. |
| 1789 | * Returns NULL on failure or a reference to interface. |
| 1790 | * |
| 1791 | * NOTE: GGG TODO THIS NEEDS TO TAKE A PROPER APPROACH TO IPSEC TUNNELS USING ENDPOINT ADDRESSING AS THE TYPE INFO KEYS |
| 1792 | */ |
| 1793 | static struct ecm_db_iface_instance *ecm_interface_ipsec_tunnel_interface_establish(struct ecm_db_interface_info_ipsec_tunnel *type_info, |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1794 | char *dev_name, int32_t dev_interface_num, int32_t ae_interface_num, int32_t mtu) |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1795 | { |
| 1796 | struct ecm_db_iface_instance *nii; |
| 1797 | struct ecm_db_iface_instance *ii; |
| 1798 | |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1799 | DEBUG_INFO("Establish IPSEC_TUNNEL iface: %s with os_specific_ident: %u, MTU: %d, if num: %d, accel engine if id: %d\n", |
| 1800 | dev_name, type_info->os_specific_ident, mtu, dev_interface_num, ae_interface_num); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1801 | |
| 1802 | /* |
| 1803 | * Locate the iface |
| 1804 | */ |
| 1805 | ii = ecm_db_iface_find_and_ref_ipsec_tunnel(type_info->os_specific_ident); |
| 1806 | if (ii) { |
| 1807 | DEBUG_TRACE("%p: iface established\n", ii); |
| 1808 | return ii; |
| 1809 | } |
| 1810 | |
| 1811 | /* |
| 1812 | * No iface - create one |
| 1813 | */ |
| 1814 | nii = ecm_db_iface_alloc(); |
| 1815 | if (!nii) { |
| 1816 | DEBUG_WARN("Failed to establish iface\n"); |
| 1817 | return NULL; |
| 1818 | } |
| 1819 | |
| 1820 | /* |
| 1821 | * Add iface into the database, atomically to avoid races creating the same thing |
| 1822 | */ |
| 1823 | spin_lock_bh(&ecm_interface_lock); |
| 1824 | ii = ecm_db_iface_find_and_ref_ipsec_tunnel(type_info->os_specific_ident); |
| 1825 | if (ii) { |
| 1826 | spin_unlock_bh(&ecm_interface_lock); |
| 1827 | ecm_db_iface_deref(nii); |
| 1828 | return ii; |
| 1829 | } |
| 1830 | ecm_db_iface_add_ipsec_tunnel(nii, type_info->os_specific_ident, dev_name, |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1831 | mtu, dev_interface_num, ae_interface_num, NULL, nii); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1832 | spin_unlock_bh(&ecm_interface_lock); |
| 1833 | |
| 1834 | DEBUG_TRACE("%p: ipsec_tunnel iface established\n", nii); |
| 1835 | return nii; |
| 1836 | } |
Murat Sezgin | 69a2753 | 2015-03-12 14:09:40 -0700 | [diff] [blame] | 1837 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1838 | |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 1839 | #ifdef ECM_INTERFACE_SIT_ENABLE |
Murat Sezgin | bde55f9 | 2015-03-11 16:44:11 -0700 | [diff] [blame] | 1840 | #ifdef CONFIG_IPV6_SIT_6RD |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1841 | /* |
| 1842 | * ecm_interface_sit_interface_establish() |
| 1843 | * Returns a reference to a iface of the SIT type, possibly creating one if necessary. |
| 1844 | * Returns NULL on failure or a reference to interface. |
| 1845 | */ |
| 1846 | static struct ecm_db_iface_instance *ecm_interface_sit_interface_establish(struct ecm_db_interface_info_sit *type_info, |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1847 | char *dev_name, int32_t dev_interface_num, int32_t ae_interface_num, int32_t mtu) |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1848 | { |
| 1849 | struct ecm_db_iface_instance *nii; |
| 1850 | struct ecm_db_iface_instance *ii; |
| 1851 | |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1852 | DEBUG_INFO("Establish SIT iface: %s with saddr: " ECM_IP_ADDR_OCTAL_FMT ", daddr: " ECM_IP_ADDR_OCTAL_FMT ", MTU: %d, if num: %d, accel engine if id: %d\n", |
| 1853 | dev_name, ECM_IP_ADDR_TO_OCTAL(type_info->saddr), ECM_IP_ADDR_TO_OCTAL(type_info->daddr), mtu, dev_interface_num, ae_interface_num); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1854 | |
| 1855 | /* |
| 1856 | * Locate the iface |
| 1857 | */ |
Murat Sezgin | ed9c1c6 | 2017-07-14 16:57:23 -0700 | [diff] [blame] | 1858 | ii = ecm_db_iface_find_and_ref_sit(type_info->saddr, type_info->daddr, ae_interface_num); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1859 | if (ii) { |
| 1860 | DEBUG_TRACE("%p: iface established\n", ii); |
| 1861 | return ii; |
| 1862 | } |
| 1863 | |
| 1864 | /* |
| 1865 | * No iface - create one |
| 1866 | */ |
| 1867 | nii = ecm_db_iface_alloc(); |
| 1868 | if (!nii) { |
| 1869 | DEBUG_WARN("Failed to establish iface\n"); |
| 1870 | return NULL; |
| 1871 | } |
| 1872 | |
| 1873 | /* |
| 1874 | * Add iface into the database, atomically to avoid races creating the same thing |
| 1875 | */ |
| 1876 | spin_lock_bh(&ecm_interface_lock); |
Murat Sezgin | ed9c1c6 | 2017-07-14 16:57:23 -0700 | [diff] [blame] | 1877 | ii = ecm_db_iface_find_and_ref_sit(type_info->saddr, type_info->daddr, ae_interface_num); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1878 | if (ii) { |
| 1879 | spin_unlock_bh(&ecm_interface_lock); |
| 1880 | ecm_db_iface_deref(nii); |
| 1881 | return ii; |
| 1882 | } |
| 1883 | ecm_db_iface_add_sit(nii, type_info, dev_name, mtu, dev_interface_num, |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1884 | ae_interface_num, NULL, nii); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1885 | spin_unlock_bh(&ecm_interface_lock); |
| 1886 | |
| 1887 | DEBUG_TRACE("%p: sit iface established\n", nii); |
| 1888 | return nii; |
| 1889 | } |
Murat Sezgin | cc6eedf | 2014-05-09 23:59:19 -0700 | [diff] [blame] | 1890 | #endif |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 1891 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1892 | |
Murat Sezgin | c140256 | 2015-03-12 12:32:20 -0700 | [diff] [blame] | 1893 | #ifdef ECM_INTERFACE_TUNIPIP6_ENABLE |
Gareth Williams | 8ac3429 | 2015-03-17 14:06:58 +0000 | [diff] [blame] | 1894 | #ifdef ECM_IPV6_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1895 | /* |
| 1896 | * ecm_interface_tunipip6_interface_establish() |
| 1897 | * Returns a reference to a iface of the TUNIPIP6 type, possibly creating one if necessary. |
| 1898 | * Returns NULL on failure or a reference to interface. |
| 1899 | */ |
| 1900 | static struct ecm_db_iface_instance *ecm_interface_tunipip6_interface_establish(struct ecm_db_interface_info_tunipip6 *type_info, |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1901 | char *dev_name, int32_t dev_interface_num, int32_t ae_interface_num, int32_t mtu) |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1902 | { |
| 1903 | struct ecm_db_iface_instance *nii; |
| 1904 | struct ecm_db_iface_instance *ii; |
| 1905 | |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1906 | DEBUG_INFO("Establish TUNIPIP6 iface: %s with saddr: " ECM_IP_ADDR_OCTAL_FMT ", daddr: " ECM_IP_ADDR_OCTAL_FMT ", MTU: %d, if num: %d, accel engine if id: %d\n", |
| 1907 | dev_name, ECM_IP_ADDR_TO_OCTAL(type_info->saddr), ECM_IP_ADDR_TO_OCTAL(type_info->daddr), mtu, dev_interface_num, ae_interface_num); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1908 | |
| 1909 | /* |
| 1910 | * Locate the iface |
| 1911 | */ |
Apoorv Gupta | 39b3328 | 2018-08-02 09:25:59 +0530 | [diff] [blame] | 1912 | ii = ecm_db_iface_find_and_ref_tunipip6(type_info->saddr, type_info->daddr, ae_interface_num); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1913 | if (ii) { |
| 1914 | DEBUG_TRACE("%p: iface established\n", ii); |
| 1915 | return ii; |
| 1916 | } |
| 1917 | |
| 1918 | /* |
| 1919 | * No iface - create one |
| 1920 | */ |
| 1921 | nii = ecm_db_iface_alloc(); |
| 1922 | if (!nii) { |
| 1923 | DEBUG_WARN("Failed to establish iface\n"); |
| 1924 | return NULL; |
| 1925 | } |
| 1926 | |
| 1927 | /* |
| 1928 | * Add iface into the database, atomically to avoid races creating the same thing |
| 1929 | */ |
| 1930 | spin_lock_bh(&ecm_interface_lock); |
Apoorv Gupta | 39b3328 | 2018-08-02 09:25:59 +0530 | [diff] [blame] | 1931 | ii = ecm_db_iface_find_and_ref_tunipip6(type_info->saddr, type_info->daddr, ae_interface_num); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1932 | if (ii) { |
| 1933 | spin_unlock_bh(&ecm_interface_lock); |
| 1934 | ecm_db_iface_deref(nii); |
| 1935 | return ii; |
| 1936 | } |
| 1937 | ecm_db_iface_add_tunipip6(nii, type_info, dev_name, mtu, dev_interface_num, |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1938 | ae_interface_num, NULL, nii); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1939 | spin_unlock_bh(&ecm_interface_lock); |
| 1940 | |
| 1941 | DEBUG_TRACE("%p: tunipip6 iface established\n", nii); |
| 1942 | return nii; |
| 1943 | } |
Murat Sezgin | c140256 | 2015-03-12 12:32:20 -0700 | [diff] [blame] | 1944 | #endif |
Gareth Williams | 8ac3429 | 2015-03-17 14:06:58 +0000 | [diff] [blame] | 1945 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1946 | |
| 1947 | /* |
| 1948 | * ecm_interface_establish_and_ref() |
| 1949 | * Establish an interface instance for the given interface detail. |
| 1950 | */ |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1951 | struct ecm_db_iface_instance *ecm_interface_establish_and_ref(struct ecm_front_end_connection_instance *feci, |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 1952 | struct net_device *dev, struct sk_buff *skb) |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1953 | { |
| 1954 | int32_t dev_interface_num; |
| 1955 | char *dev_name; |
| 1956 | int32_t dev_type; |
| 1957 | int32_t dev_mtu; |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 1958 | int32_t ae_interface_num; |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1959 | struct ecm_db_iface_instance *ii; |
Suman Ghosh | 8f199b2 | 2018-07-13 18:51:27 +0530 | [diff] [blame] | 1960 | int32_t interface_type; |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1961 | union { |
| 1962 | struct ecm_db_interface_info_ethernet ethernet; /* type == ECM_DB_IFACE_TYPE_ETHERNET */ |
Gareth Williams | 141d238 | 2014-11-25 11:35:19 -0800 | [diff] [blame] | 1963 | #ifdef ECM_INTERFACE_VLAN_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1964 | struct ecm_db_interface_info_vlan vlan; /* type == ECM_DB_IFACE_TYPE_VLAN */ |
Gareth Williams | 141d238 | 2014-11-25 11:35:19 -0800 | [diff] [blame] | 1965 | #endif |
Murat Sezgin | 910c966 | 2015-03-11 16:15:06 -0700 | [diff] [blame] | 1966 | #ifdef ECM_INTERFACE_BOND_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1967 | struct ecm_db_interface_info_lag lag; /* type == ECM_DB_IFACE_TYPE_LAG */ |
Murat Sezgin | 910c966 | 2015-03-11 16:15:06 -0700 | [diff] [blame] | 1968 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1969 | struct ecm_db_interface_info_bridge bridge; /* type == ECM_DB_IFACE_TYPE_BRIDGE */ |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 1970 | #ifdef ECM_INTERFACE_PPPOE_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1971 | struct ecm_db_interface_info_pppoe pppoe; /* type == ECM_DB_IFACE_TYPE_PPPOE */ |
Murat Sezgin | aad635c | 2015-03-06 16:11:41 -0800 | [diff] [blame] | 1972 | #endif |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 1973 | #ifdef ECM_INTERFACE_L2TPV2_ENABLE |
| 1974 | struct ecm_db_interface_info_pppol2tpv2 pppol2tpv2; /* type == ECM_DB_IFACE_TYPE_PPPOL2TPV2 */ |
| 1975 | #endif |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 1976 | #ifdef ECM_INTERFACE_PPTP_ENABLE |
| 1977 | struct ecm_db_interface_info_pptp pptp; /* type == ECM_DB_IFACE_TYPE_PPTP */ |
| 1978 | #endif |
ratheesh kannoth | cfdcb33 | 2015-12-24 07:19:18 +0530 | [diff] [blame] | 1979 | #ifdef ECM_INTERFACE_MAP_T_ENABLE |
| 1980 | struct ecm_db_interface_info_map_t map_t; /* type == ECM_DB_IFACE_TYPE_MAP_T */ |
| 1981 | #endif |
Suman Ghosh | 9e4245f | 2018-04-11 01:11:41 +0530 | [diff] [blame] | 1982 | #ifdef ECM_INTERFACE_GRE_TUN_ENABLE |
| 1983 | struct ecm_db_interface_info_gre_tun gre_tun; /* type == ECM_DB_IFACE_TYPE_GRE */ |
| 1984 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1985 | struct ecm_db_interface_info_unknown unknown; /* type == ECM_DB_IFACE_TYPE_UNKNOWN */ |
| 1986 | struct ecm_db_interface_info_loopback loopback; /* type == ECM_DB_IFACE_TYPE_LOOPBACK */ |
Murat Sezgin | 69a2753 | 2015-03-12 14:09:40 -0700 | [diff] [blame] | 1987 | #ifdef ECM_INTERFACE_IPSEC_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1988 | struct ecm_db_interface_info_ipsec_tunnel ipsec_tunnel; /* type == ECM_DB_IFACE_TYPE_IPSEC_TUNNEL */ |
Murat Sezgin | 69a2753 | 2015-03-12 14:09:40 -0700 | [diff] [blame] | 1989 | #endif |
Murat Sezgin | bde55f9 | 2015-03-11 16:44:11 -0700 | [diff] [blame] | 1990 | #ifdef ECM_INTERFACE_SIT_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1991 | struct ecm_db_interface_info_sit sit; /* type == ECM_DB_IFACE_TYPE_SIT */ |
Murat Sezgin | bde55f9 | 2015-03-11 16:44:11 -0700 | [diff] [blame] | 1992 | #endif |
Murat Sezgin | c140256 | 2015-03-12 12:32:20 -0700 | [diff] [blame] | 1993 | #ifdef ECM_INTERFACE_TUNIPIP6_ENABLE |
Gareth Williams | 8ac3429 | 2015-03-17 14:06:58 +0000 | [diff] [blame] | 1994 | #ifdef ECM_IPV6_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1995 | struct ecm_db_interface_info_tunipip6 tunipip6; /* type == ECM_DB_IFACE_TYPE_TUNIPIP6 */ |
Murat Sezgin | c140256 | 2015-03-12 12:32:20 -0700 | [diff] [blame] | 1996 | #endif |
Gareth Williams | 8ac3429 | 2015-03-17 14:06:58 +0000 | [diff] [blame] | 1997 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1998 | } type_info; |
Gareth Williams | c5b9d71 | 2014-05-09 20:40:07 +0100 | [diff] [blame] | 1999 | |
Suman Ghosh | 9e4245f | 2018-04-11 01:11:41 +0530 | [diff] [blame] | 2000 | #ifdef ECM_INTERFACE_GRE_TUN_ENABLE |
| 2001 | struct ip_tunnel *gre4_tunnel; |
| 2002 | struct ip6_tnl *gre6_tunnel; |
| 2003 | #endif |
Gareth Williams | dbb2bfd | 2014-11-20 16:42:09 -0800 | [diff] [blame] | 2004 | #ifdef ECM_INTERFACE_PPP_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2005 | int channel_count; |
| 2006 | struct ppp_channel *ppp_chan[1]; |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2007 | int channel_protocol; |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 2008 | #ifdef ECM_INTERFACE_PPPOE_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2009 | struct pppoe_opt addressing; |
Gareth Williams | c5b9d71 | 2014-05-09 20:40:07 +0100 | [diff] [blame] | 2010 | #endif |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 2011 | #ifdef ECM_INTERFACE_PPTP_ENABLE |
| 2012 | int protocol = IPPROTO_IP; |
| 2013 | struct pptp_opt opt; |
| 2014 | struct iphdr *v4_hdr = NULL; |
| 2015 | if (skb) { |
| 2016 | v4_hdr = ip_hdr(skb); |
| 2017 | protocol = v4_hdr->protocol; |
| 2018 | } |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 2019 | #endif |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 2020 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2021 | /* |
| 2022 | * Get basic information about the given device |
| 2023 | */ |
| 2024 | dev_interface_num = dev->ifindex; |
| 2025 | dev_name = dev->name; |
| 2026 | dev_type = dev->type; |
| 2027 | dev_mtu = dev->mtu; |
| 2028 | |
| 2029 | /* |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 2030 | * Does the accel engine recognise this interface? |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2031 | */ |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 2032 | ae_interface_num = feci->ae_interface_number_by_dev_get(dev); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2033 | |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 2034 | DEBUG_TRACE("Establish interface instance for device: %p is type: %d, name: %s, ifindex: %d, ae_if: %d, mtu: %d\n", |
| 2035 | dev, dev_type, dev_name, dev_interface_num, ae_interface_num, dev_mtu); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2036 | |
| 2037 | /* |
| 2038 | * Extract from the device more type-specific information |
| 2039 | */ |
| 2040 | if (dev_type == ARPHRD_ETHER) { |
Shyam Sunder | 39e2567 | 2015-09-03 14:28:09 +0530 | [diff] [blame] | 2041 | |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2042 | /* |
Murat Sezgin | f983c4d | 2018-09-04 16:59:23 -0700 | [diff] [blame] | 2043 | * If MAC address is zeros, do nothing. |
| 2044 | */ |
| 2045 | if (is_zero_ether_addr(dev->dev_addr)) { |
| 2046 | DEBUG_WARN("Net device %p MAC address is all zeros\n", dev); |
| 2047 | return NULL; |
| 2048 | } |
| 2049 | |
| 2050 | /* |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2051 | * Ethernet - but what sub type? |
| 2052 | */ |
| 2053 | |
Gareth Williams | 141d238 | 2014-11-25 11:35:19 -0800 | [diff] [blame] | 2054 | #ifdef ECM_INTERFACE_VLAN_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2055 | /* |
| 2056 | * VLAN? |
| 2057 | */ |
| 2058 | if (is_vlan_dev(dev)) { |
| 2059 | /* |
| 2060 | * VLAN master |
| 2061 | * GGG No locking needed here, ASSUMPTION is that real_dev is held for as long as we have dev. |
| 2062 | */ |
| 2063 | memcpy(type_info.vlan.address, dev->dev_addr, 6); |
Radha krishna Simha Jiguru | f7dc34c | 2014-05-12 18:59:07 +0530 | [diff] [blame] | 2064 | type_info.vlan.vlan_tag = vlan_dev_vlan_id(dev); |
Amit Gupta | 8975f9d | 2017-07-12 20:34:36 +0530 | [diff] [blame] | 2065 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0)) |
Murat Sezgin | b267606 | 2015-06-12 17:05:31 -0700 | [diff] [blame] | 2066 | type_info.vlan.vlan_tpid = ETH_P_8021Q; |
Amit Gupta | 8975f9d | 2017-07-12 20:34:36 +0530 | [diff] [blame] | 2067 | #else |
| 2068 | type_info.vlan.vlan_tpid = ntohs(vlan_dev_vlan_proto(dev)); |
| 2069 | #endif |
Radha krishna Simha Jiguru | f7dc34c | 2014-05-12 18:59:07 +0530 | [diff] [blame] | 2070 | DEBUG_TRACE("Net device: %p is VLAN, mac: %pM, vlan_id: %x vlan_tpid: %x\n", |
| 2071 | dev, type_info.vlan.address, type_info.vlan.vlan_tag, type_info.vlan.vlan_tpid); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2072 | |
| 2073 | /* |
| 2074 | * Establish this type of interface |
| 2075 | */ |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 2076 | ii = ecm_interface_vlan_interface_establish(&type_info.vlan, dev_name, dev_interface_num, ae_interface_num, dev_mtu); |
Shyam Sunder | 39e2567 | 2015-09-03 14:28:09 +0530 | [diff] [blame] | 2077 | goto identifier_update; |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2078 | } |
Gareth Williams | 141d238 | 2014-11-25 11:35:19 -0800 | [diff] [blame] | 2079 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2080 | |
| 2081 | /* |
| 2082 | * BRIDGE? |
| 2083 | */ |
| 2084 | if (ecm_front_end_is_bridge_device(dev)) { |
| 2085 | /* |
| 2086 | * Bridge |
| 2087 | */ |
| 2088 | memcpy(type_info.bridge.address, dev->dev_addr, 6); |
| 2089 | |
| 2090 | DEBUG_TRACE("Net device: %p is BRIDGE, mac: %pM\n", |
| 2091 | dev, type_info.bridge.address); |
| 2092 | |
| 2093 | /* |
| 2094 | * Establish this type of interface |
| 2095 | */ |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 2096 | ii = ecm_interface_bridge_interface_establish(&type_info.bridge, dev_name, dev_interface_num, ae_interface_num, dev_mtu); |
Shyam Sunder | 39e2567 | 2015-09-03 14:28:09 +0530 | [diff] [blame] | 2097 | goto identifier_update; |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2098 | } |
| 2099 | |
Murat Sezgin | 910c966 | 2015-03-11 16:15:06 -0700 | [diff] [blame] | 2100 | #ifdef ECM_INTERFACE_BOND_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2101 | /* |
| 2102 | * LAG? |
| 2103 | */ |
| 2104 | if (ecm_front_end_is_lag_master(dev)) { |
| 2105 | /* |
| 2106 | * Link aggregation |
| 2107 | */ |
| 2108 | memcpy(type_info.lag.address, dev->dev_addr, 6); |
| 2109 | |
| 2110 | DEBUG_TRACE("Net device: %p is LAG, mac: %pM\n", |
| 2111 | dev, type_info.lag.address); |
| 2112 | |
| 2113 | /* |
| 2114 | * Establish this type of interface |
| 2115 | */ |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 2116 | ii = ecm_interface_lag_interface_establish(&type_info.lag, dev_name, dev_interface_num, ae_interface_num, dev_mtu); |
Shyam Sunder | 39e2567 | 2015-09-03 14:28:09 +0530 | [diff] [blame] | 2117 | goto identifier_update; |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2118 | } |
Murat Sezgin | 910c966 | 2015-03-11 16:15:06 -0700 | [diff] [blame] | 2119 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2120 | |
Suman Ghosh | 9e4245f | 2018-04-11 01:11:41 +0530 | [diff] [blame] | 2121 | #ifdef ECM_INTERFACE_GRE_TAP_ENABLE |
Murat Sezgin | 31effef | 2017-11-13 15:09:34 -0800 | [diff] [blame] | 2122 | /* |
| 2123 | * GRE TAP? |
| 2124 | */ |
| 2125 | if (dev->priv_flags & (IFF_GRE_V4_TAP | IFF_GRE_V6_TAP)) { |
Suman Ghosh | 8f199b2 | 2018-07-13 18:51:27 +0530 | [diff] [blame] | 2126 | interface_type = feci->ae_interface_type_get(feci, dev); |
| 2127 | ae_interface_num = feci->ae_interface_number_by_dev_type_get(dev, interface_type); |
| 2128 | |
Murat Sezgin | 31effef | 2017-11-13 15:09:34 -0800 | [diff] [blame] | 2129 | /* |
| 2130 | * GRE TAP interface is handled as ethernet interface, however it is possible |
| 2131 | * that the acceleration engine may not be ready yet to handle the connection. |
| 2132 | * In this case the acceleration engine interface is not found for this type and |
| 2133 | * we should wait until it is ready. |
| 2134 | */ |
| 2135 | if (ae_interface_num < 0) { |
Suman Ghosh | 8f199b2 | 2018-07-13 18:51:27 +0530 | [diff] [blame] | 2136 | DEBUG_TRACE("GRE TAP interface is not ready yet. Interface type: %d\n", interface_type); |
Murat Sezgin | 31effef | 2017-11-13 15:09:34 -0800 | [diff] [blame] | 2137 | return NULL; |
| 2138 | } |
| 2139 | } |
| 2140 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2141 | /* |
| 2142 | * ETHERNET! |
| 2143 | * Just plain ethernet it seems |
| 2144 | */ |
| 2145 | memcpy(type_info.ethernet.address, dev->dev_addr, 6); |
| 2146 | DEBUG_TRACE("Net device: %p is ETHERNET, mac: %pM\n", |
| 2147 | dev, type_info.ethernet.address); |
| 2148 | |
| 2149 | /* |
| 2150 | * Establish this type of interface |
| 2151 | */ |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 2152 | ii = ecm_interface_ethernet_interface_establish(&type_info.ethernet, dev_name, dev_interface_num, ae_interface_num, dev_mtu); |
Shyam Sunder | 39e2567 | 2015-09-03 14:28:09 +0530 | [diff] [blame] | 2153 | |
| 2154 | identifier_update: |
| 2155 | if (ii) { |
| 2156 | /* |
| 2157 | * An interface identifier/ifindex can be change after network restart. Below |
| 2158 | * functtion will check interface_identifier present in 'ii' with new dev_interface_num. |
| 2159 | * If differ then update new ifindex and update the interface identifier hash table. |
| 2160 | */ |
| 2161 | ecm_db_iface_identifier_hash_table_entry_check_and_update(ii, dev_interface_num); |
| 2162 | } |
| 2163 | |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2164 | return ii; |
| 2165 | } |
| 2166 | |
| 2167 | /* |
| 2168 | * LOOPBACK? |
| 2169 | */ |
| 2170 | if (dev_type == ARPHRD_LOOPBACK) { |
| 2171 | DEBUG_TRACE("Net device: %p is LOOPBACK type: %d\n", dev, dev_type); |
| 2172 | type_info.loopback.os_specific_ident = dev_interface_num; |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 2173 | ii = ecm_interface_loopback_interface_establish(&type_info.loopback, dev_name, dev_interface_num, ae_interface_num, dev_mtu); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2174 | return ii; |
| 2175 | } |
| 2176 | |
Murat Sezgin | 69a2753 | 2015-03-12 14:09:40 -0700 | [diff] [blame] | 2177 | #ifdef ECM_INTERFACE_IPSEC_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2178 | /* |
| 2179 | * IPSEC? |
| 2180 | */ |
| 2181 | if (dev_type == ECM_ARPHRD_IPSEC_TUNNEL_TYPE) { |
| 2182 | DEBUG_TRACE("Net device: %p is IPSec tunnel type: %d\n", dev, dev_type); |
| 2183 | type_info.ipsec_tunnel.os_specific_ident = dev_interface_num; |
Ankit Dhanuka | 6d5014a | 2014-06-22 17:21:44 +0530 | [diff] [blame] | 2184 | |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2185 | // GGG TODO Flesh this out with tunnel endpoint addressing detail |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 2186 | ii = ecm_interface_ipsec_tunnel_interface_establish(&type_info.ipsec_tunnel, dev_name, dev_interface_num, ae_interface_num, dev_mtu); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2187 | return ii; |
| 2188 | } |
Murat Sezgin | 69a2753 | 2015-03-12 14:09:40 -0700 | [diff] [blame] | 2189 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2190 | |
ratheesh kannoth | cfdcb33 | 2015-12-24 07:19:18 +0530 | [diff] [blame] | 2191 | #ifdef ECM_INTERFACE_MAP_T_ENABLE |
| 2192 | if (dev_type == ARPHRD_NONE) { |
| 2193 | if (is_map_t_dev(dev)) { |
| 2194 | type_info.map_t.if_index = dev_interface_num; |
Manish Verma | f70e161 | 2018-08-20 01:15:40 +0530 | [diff] [blame] | 2195 | interface_type = feci->ae_interface_type_get(feci, dev); |
| 2196 | ae_interface_num = feci->ae_interface_number_by_dev_type_get(dev, interface_type); |
| 2197 | |
| 2198 | if (ae_interface_num < 0) { |
| 2199 | DEBUG_TRACE("MAP-T interface is not ready yet\n"); |
| 2200 | return NULL; |
| 2201 | } |
| 2202 | |
ratheesh kannoth | cfdcb33 | 2015-12-24 07:19:18 +0530 | [diff] [blame] | 2203 | ii = ecm_interface_map_t_interface_establish(&type_info.map_t, dev_name, dev_interface_num, ae_interface_num, dev_mtu); |
| 2204 | return ii; |
| 2205 | } |
| 2206 | |
| 2207 | } |
| 2208 | #endif |
| 2209 | |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 2210 | #ifdef ECM_INTERFACE_SIT_ENABLE |
Murat Sezgin | bde55f9 | 2015-03-11 16:44:11 -0700 | [diff] [blame] | 2211 | #ifdef CONFIG_IPV6_SIT_6RD |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2212 | /* |
| 2213 | * SIT (6-in-4)? |
| 2214 | */ |
| 2215 | if (dev_type == ARPHRD_SIT) { |
| 2216 | struct ip_tunnel *tunnel; |
| 2217 | struct ip_tunnel_6rd_parm *ip6rd; |
| 2218 | const struct iphdr *tiph; |
| 2219 | |
| 2220 | DEBUG_TRACE("Net device: %p is SIT (6-in-4) type: %d\n", dev, dev_type); |
| 2221 | |
| 2222 | tunnel = (struct ip_tunnel*)netdev_priv(dev); |
| 2223 | ip6rd = &tunnel->ip6rd; |
| 2224 | |
| 2225 | /* |
| 2226 | * Get the Tunnel device IP header info |
| 2227 | */ |
| 2228 | tiph = &tunnel->parms.iph ; |
| 2229 | |
| 2230 | type_info.sit.prefixlen = ip6rd->prefixlen; |
| 2231 | type_info.sit.relay_prefix = ip6rd->relay_prefix; |
| 2232 | type_info.sit.relay_prefixlen = ip6rd->relay_prefixlen; |
| 2233 | ECM_NIN4_ADDR_TO_IP_ADDR(type_info.sit.saddr, tiph->saddr); |
| 2234 | ECM_NIN4_ADDR_TO_IP_ADDR(type_info.sit.daddr, tiph->daddr); |
| 2235 | type_info.sit.prefix[0] = ntohl(ip6rd->prefix.s6_addr32[0]); |
| 2236 | type_info.sit.prefix[1] = ntohl(ip6rd->prefix.s6_addr32[1]); |
| 2237 | type_info.sit.prefix[2] = ntohl(ip6rd->prefix.s6_addr32[2]); |
| 2238 | type_info.sit.prefix[3] = ntohl(ip6rd->prefix.s6_addr32[3]); |
| 2239 | type_info.sit.ttl = tiph->ttl; |
| 2240 | type_info.sit.tos = tiph->tos; |
Radha krishna Simha Jiguru | f7dc34c | 2014-05-12 18:59:07 +0530 | [diff] [blame] | 2241 | |
Suman Ghosh | 8f199b2 | 2018-07-13 18:51:27 +0530 | [diff] [blame] | 2242 | interface_type = feci->ae_interface_type_get(feci, dev); |
Murat Sezgin | ed9c1c6 | 2017-07-14 16:57:23 -0700 | [diff] [blame] | 2243 | ae_interface_num = feci->ae_interface_number_by_dev_type_get(dev, interface_type); |
| 2244 | |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 2245 | ii = ecm_interface_sit_interface_establish(&type_info.sit, dev_name, dev_interface_num, ae_interface_num, dev_mtu); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2246 | return ii; |
| 2247 | } |
Murat Sezgin | cc6eedf | 2014-05-09 23:59:19 -0700 | [diff] [blame] | 2248 | #endif |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 2249 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2250 | |
Murat Sezgin | c140256 | 2015-03-12 12:32:20 -0700 | [diff] [blame] | 2251 | #ifdef ECM_INTERFACE_TUNIPIP6_ENABLE |
Gareth Williams | 8ac3429 | 2015-03-17 14:06:58 +0000 | [diff] [blame] | 2252 | #ifdef ECM_IPV6_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2253 | /* |
| 2254 | * IPIP6 Tunnel? |
| 2255 | */ |
| 2256 | if (dev_type == ARPHRD_TUNNEL6) { |
| 2257 | struct ip6_tnl *tunnel; |
| 2258 | struct flowi6 *fl6; |
| 2259 | |
| 2260 | DEBUG_TRACE("Net device: %p is TUNIPIP6 type: %d\n", dev, dev_type); |
| 2261 | |
| 2262 | /* |
| 2263 | * Get the tunnel device flow information (discover the output path of the tunnel) |
| 2264 | */ |
| 2265 | tunnel = (struct ip6_tnl *)netdev_priv(dev); |
| 2266 | fl6 = &tunnel->fl.u.ip6; |
| 2267 | |
| 2268 | ECM_NIN6_ADDR_TO_IP_ADDR(type_info.tunipip6.saddr, fl6->saddr); |
| 2269 | ECM_NIN6_ADDR_TO_IP_ADDR(type_info.tunipip6.daddr, fl6->daddr); |
| 2270 | type_info.tunipip6.hop_limit = tunnel->parms.hop_limit; |
| 2271 | type_info.tunipip6.flags = ntohl(tunnel->parms.flags); |
| 2272 | type_info.tunipip6.flowlabel = fl6->flowlabel; /* flow Label In kernel is stored in big endian format */ |
Radha krishna Simha Jiguru | f7dc34c | 2014-05-12 18:59:07 +0530 | [diff] [blame] | 2273 | |
Suman Ghosh | 8f199b2 | 2018-07-13 18:51:27 +0530 | [diff] [blame] | 2274 | interface_type = feci->ae_interface_type_get(feci, dev); |
Apoorv Gupta | 39b3328 | 2018-08-02 09:25:59 +0530 | [diff] [blame] | 2275 | ae_interface_num = feci->ae_interface_number_by_dev_type_get(dev, interface_type); |
| 2276 | |
| 2277 | if (ae_interface_num < 0) { |
| 2278 | DEBUG_TRACE("TUNIPIP6 interface is not ready yet\n"); |
| 2279 | return NULL; |
| 2280 | } |
| 2281 | |
| 2282 | ii = ecm_interface_tunipip6_interface_establish(&type_info.tunipip6, dev_name, |
| 2283 | dev_interface_num, ae_interface_num, dev_mtu); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2284 | return ii; |
| 2285 | } |
Murat Sezgin | c140256 | 2015-03-12 12:32:20 -0700 | [diff] [blame] | 2286 | #endif |
Gareth Williams | 8ac3429 | 2015-03-17 14:06:58 +0000 | [diff] [blame] | 2287 | #endif |
| 2288 | |
Suman Ghosh | 9e4245f | 2018-04-11 01:11:41 +0530 | [diff] [blame] | 2289 | #ifdef ECM_INTERFACE_GRE_TUN_ENABLE |
| 2290 | if ((dev_type == ARPHRD_IPGRE) || (dev_type == ARPHRD_IP6GRE)) { |
Suman Ghosh | 9e4245f | 2018-04-11 01:11:41 +0530 | [diff] [blame] | 2291 | type_info.gre_tun.if_index = dev_interface_num; |
| 2292 | if (dev_type == ARPHRD_IPGRE) { |
| 2293 | gre4_tunnel = netdev_priv(dev); |
| 2294 | if (!gre4_tunnel) { |
| 2295 | DEBUG_WARN("failed to obtain node address for host. GREv4 tunnel not ready\n"); |
| 2296 | return NULL; |
| 2297 | } |
| 2298 | ECM_NIN4_ADDR_TO_IP_ADDR(type_info.gre_tun.local_ip, gre4_tunnel->parms.iph.saddr); |
| 2299 | ECM_NIN4_ADDR_TO_IP_ADDR(type_info.gre_tun.remote_ip, gre4_tunnel->parms.iph.daddr); |
| 2300 | } else { |
| 2301 | gre6_tunnel = netdev_priv(dev); |
| 2302 | if (!gre6_tunnel) { |
| 2303 | DEBUG_WARN("failed to obtain node address for host. GREv6 tunnel not ready\n"); |
| 2304 | return NULL; |
| 2305 | } |
| 2306 | ECM_NIN6_ADDR_TO_IP_ADDR(type_info.gre_tun.local_ip, gre6_tunnel->parms.laddr); |
| 2307 | ECM_NIN6_ADDR_TO_IP_ADDR(type_info.gre_tun.remote_ip, gre6_tunnel->parms.raddr); |
| 2308 | } |
| 2309 | |
Suman Ghosh | 8f199b2 | 2018-07-13 18:51:27 +0530 | [diff] [blame] | 2310 | interface_type = feci->ae_interface_type_get(feci, dev); |
| 2311 | ae_interface_num = feci->ae_interface_number_by_dev_type_get(dev, interface_type); |
| 2312 | if (ae_interface_num < 0) { |
| 2313 | DEBUG_TRACE("GRE TUN interface is not ready yet. Interface type: %d\n", interface_type); |
| 2314 | return NULL; |
| 2315 | } |
| 2316 | |
Suman Ghosh | 9e4245f | 2018-04-11 01:11:41 +0530 | [diff] [blame] | 2317 | ii = ecm_interface_gre_tun_interface_establish(&type_info.gre_tun, dev_name, dev_interface_num, ae_interface_num, dev_mtu); |
| 2318 | if (ii) { |
| 2319 | /* |
| 2320 | * The ifindex of a virtual netdevice like a GRE tunnel session can change if it is destroyed |
| 2321 | * and comes up again. Detect if the ifindex has changed and update it if required |
| 2322 | */ |
| 2323 | ecm_db_iface_identifier_hash_table_entry_check_and_update(ii, dev_interface_num); |
| 2324 | } |
| 2325 | return ii; |
| 2326 | } |
| 2327 | #endif |
| 2328 | |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2329 | /* |
| 2330 | * If this is NOT PPP then it is unknown to the ecm |
| 2331 | */ |
| 2332 | if (dev_type != ARPHRD_PPP) { |
| 2333 | DEBUG_TRACE("Net device: %p is UNKNOWN type: %d\n", dev, dev_type); |
| 2334 | type_info.unknown.os_specific_ident = dev_interface_num; |
| 2335 | |
| 2336 | /* |
| 2337 | * Establish this type of interface |
| 2338 | */ |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 2339 | ii = ecm_interface_unknown_interface_establish(&type_info.unknown, dev_name, dev_interface_num, ae_interface_num, dev_mtu); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2340 | return ii; |
| 2341 | } |
| 2342 | |
Gareth Williams | dbb2bfd | 2014-11-20 16:42:09 -0800 | [diff] [blame] | 2343 | #ifndef ECM_INTERFACE_PPP_ENABLE |
Gareth Williams | c5b9d71 | 2014-05-09 20:40:07 +0100 | [diff] [blame] | 2344 | /* |
ratheesh kannoth | f4801a0 | 2016-12-09 22:46:39 +0530 | [diff] [blame] | 2345 | * PPP Support is NOT provided for. |
Gareth Williams | c5b9d71 | 2014-05-09 20:40:07 +0100 | [diff] [blame] | 2346 | * Interface is therefore unknown |
| 2347 | */ |
| 2348 | DEBUG_TRACE("Net device: %p is UNKNOWN (PPP Unsupported) type: %d\n", dev, dev_type); |
| 2349 | type_info.unknown.os_specific_ident = dev_interface_num; |
| 2350 | |
| 2351 | /* |
| 2352 | * Establish this type of interface |
| 2353 | */ |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 2354 | ii = ecm_interface_unknown_interface_establish(&type_info.unknown, dev_name, dev_interface_num, ae_interface_num, dev_mtu); |
Gareth Williams | c5b9d71 | 2014-05-09 20:40:07 +0100 | [diff] [blame] | 2355 | return ii; |
| 2356 | #else |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 2357 | |
| 2358 | #ifdef ECM_INTERFACE_L2TPV2_ENABLE |
| 2359 | /* |
| 2360 | * ppp_xmit lock is held by linux kernel for l2tp packet in transmit |
| 2361 | * direction. we need to check for l2tp packet and avoid calls to |
| 2362 | * ppp_is_multilink() and ppp_hold_channels() which acquire same lock |
| 2363 | */ |
ratheesh kannoth | f4801a0 | 2016-12-09 22:46:39 +0530 | [diff] [blame] | 2364 | |
| 2365 | if ((dev->priv_flags & IFF_PPP_L2TPV2) && ppp_is_xmit_locked(dev)) { |
Murat Sezgin | db0c5d8 | 2017-02-22 11:43:03 -0800 | [diff] [blame] | 2366 | if (skb && (skb->skb_iif == dev->ifindex)) { |
ratheesh kannoth | 08b8e44 | 2015-10-02 00:24:55 +0530 | [diff] [blame] | 2367 | struct pppol2tp_common_addr info; |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 2368 | |
ratheesh kannoth | 08b8e44 | 2015-10-02 00:24:55 +0530 | [diff] [blame] | 2369 | if (__ppp_is_multilink(dev) > 0) { |
| 2370 | DEBUG_TRACE("Net device: %p is MULTILINK PPP - Unknown to the ECM\n", dev); |
| 2371 | type_info.unknown.os_specific_ident = dev_interface_num; |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 2372 | |
ratheesh kannoth | 08b8e44 | 2015-10-02 00:24:55 +0530 | [diff] [blame] | 2373 | /* |
| 2374 | * Establish this type of interface |
| 2375 | */ |
| 2376 | ii = ecm_interface_unknown_interface_establish(&type_info.unknown, dev_name, dev_interface_num, ae_interface_num, dev_mtu); |
| 2377 | return ii; |
| 2378 | } |
| 2379 | channel_count = __ppp_hold_channels(dev, ppp_chan, 1); |
| 2380 | if (channel_count != 1) { |
| 2381 | DEBUG_TRACE("Net device: %p PPP has %d channels - ECM cannot handle this (interface becomes Unknown type)\n", |
| 2382 | dev, channel_count); |
| 2383 | type_info.unknown.os_specific_ident = dev_interface_num; |
| 2384 | |
| 2385 | /* |
| 2386 | * Establish this type of interface |
| 2387 | */ |
| 2388 | ii = ecm_interface_unknown_interface_establish(&type_info.unknown, dev_name, dev_interface_num, ae_interface_num, dev_mtu); |
| 2389 | return ii; |
| 2390 | } |
| 2391 | |
| 2392 | if (pppol2tp_channel_addressing_get(ppp_chan[0], &info)) { |
| 2393 | ppp_release_channels(ppp_chan, 1); |
ratheesh kannoth | ed72185 | 2015-09-28 12:39:52 +0530 | [diff] [blame] | 2394 | return NULL; |
| 2395 | } |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 2396 | |
ratheesh kannoth | 08b8e44 | 2015-10-02 00:24:55 +0530 | [diff] [blame] | 2397 | type_info.pppol2tpv2.l2tp.tunnel.tunnel_id = info.local_tunnel_id; |
| 2398 | type_info.pppol2tpv2.l2tp.tunnel.peer_tunnel_id = info.remote_tunnel_id; |
| 2399 | type_info.pppol2tpv2.l2tp.session.session_id = info.local_session_id; |
| 2400 | type_info.pppol2tpv2.l2tp.session.peer_session_id = info.remote_session_id; |
| 2401 | type_info.pppol2tpv2.udp.sport = ntohs(info.local_addr.sin_port); |
| 2402 | type_info.pppol2tpv2.udp.dport = ntohs(info.remote_addr.sin_port); |
| 2403 | type_info.pppol2tpv2.ip.saddr = ntohl(info.local_addr.sin_addr.s_addr); |
| 2404 | type_info.pppol2tpv2.ip.daddr = ntohl(info.remote_addr.sin_addr.s_addr); |
ratheesh kannoth | ed72185 | 2015-09-28 12:39:52 +0530 | [diff] [blame] | 2405 | |
| 2406 | /* |
ratheesh kannoth | 08b8e44 | 2015-10-02 00:24:55 +0530 | [diff] [blame] | 2407 | * Release the channel. Note that next_dev is still (correctly) held. |
ratheesh kannoth | ed72185 | 2015-09-28 12:39:52 +0530 | [diff] [blame] | 2408 | */ |
ratheesh kannoth | 08b8e44 | 2015-10-02 00:24:55 +0530 | [diff] [blame] | 2409 | ppp_release_channels(ppp_chan, 1); |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 2410 | |
ratheesh kannoth | 08b8e44 | 2015-10-02 00:24:55 +0530 | [diff] [blame] | 2411 | DEBUG_TRACE("Net device: %p PPPo2L2TP session: %d,n", dev, type_info.pppol2tpv2.l2tp.session.peer_session_id); |
ratheesh kannoth | ed72185 | 2015-09-28 12:39:52 +0530 | [diff] [blame] | 2412 | |
| 2413 | /* |
| 2414 | * Establish this type of interface |
| 2415 | */ |
| 2416 | ii = ecm_interface_pppol2tpv2_interface_establish(&type_info.pppol2tpv2, dev_name, dev_interface_num, ae_interface_num, dev_mtu); |
| 2417 | return ii; |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 2418 | } |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 2419 | } |
| 2420 | #endif |
| 2421 | |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 2422 | #ifdef ECM_INTERFACE_PPTP_ENABLE |
Suman Ghosh | 4273a8e | 2018-05-03 16:21:14 +0530 | [diff] [blame] | 2423 | if ((protocol == IPPROTO_GRE) && skb && v4_hdr && (dev->priv_flags & IFF_PPP_PPTP)) { |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 2424 | struct gre_hdr_pptp *gre_hdr; |
| 2425 | uint16_t proto; |
| 2426 | int ret; |
| 2427 | |
| 2428 | skb_pull(skb, sizeof(struct iphdr)); |
| 2429 | gre_hdr = (struct gre_hdr_pptp *)(skb->data); |
| 2430 | proto = ntohs(gre_hdr->protocol); |
| 2431 | if ((gre_hdr->version == GRE_VERSION_PPTP) && (proto == GRE_PROTOCOL_PPTP)) { |
| 2432 | ret = pptp_session_find(&opt, gre_hdr->call_id, v4_hdr->daddr); |
| 2433 | if (ret < 0) { |
| 2434 | skb_push(skb, sizeof(struct iphdr)); |
| 2435 | DEBUG_WARN("PPTP session info not found\n"); |
| 2436 | return NULL; |
| 2437 | } |
| 2438 | |
| 2439 | /* |
| 2440 | * Get PPTP session info |
| 2441 | */ |
| 2442 | type_info.pptp.src_call_id = ntohs(opt.src_addr.call_id); |
| 2443 | type_info.pptp.dst_call_id = ntohs(opt.dst_addr.call_id); |
| 2444 | type_info.pptp.src_ip = ntohl(opt.src_addr.sin_addr.s_addr); |
| 2445 | type_info.pptp.dst_ip = ntohl(opt.dst_addr.sin_addr.s_addr); |
| 2446 | |
| 2447 | skb_push(skb, sizeof(struct iphdr)); |
| 2448 | |
Swaraj Sha | 0562058 | 2018-08-15 23:21:16 +0530 | [diff] [blame] | 2449 | interface_type = feci->ae_interface_type_get(feci, dev); |
| 2450 | ae_interface_num = feci->ae_interface_number_by_dev_type_get(dev, interface_type); |
| 2451 | |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 2452 | /* |
| 2453 | * Establish this type of interface |
| 2454 | */ |
| 2455 | ii = ecm_interface_pptp_interface_establish(&type_info.pptp, dev_name, dev_interface_num, ae_interface_num, dev_mtu); |
Shyam Sunder | 65f013e | 2015-12-14 18:04:54 +0530 | [diff] [blame] | 2456 | if (ii) { |
| 2457 | /* |
| 2458 | * The ifindex of a virtual netdevice like a PPTP session can change if it is destroyed |
| 2459 | * and comes up again. Detect if the ifindex has changed and update it if required |
| 2460 | */ |
| 2461 | ecm_db_iface_identifier_hash_table_entry_check_and_update(ii, dev_interface_num); |
| 2462 | } |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 2463 | return ii; |
| 2464 | } |
| 2465 | |
| 2466 | skb_push(skb, sizeof(struct iphdr)); |
| 2467 | |
| 2468 | DEBUG_TRACE("Unknown GRE protocol \n"); |
| 2469 | type_info.unknown.os_specific_ident = dev_interface_num; |
| 2470 | |
| 2471 | /* |
| 2472 | * Establish this type of interface |
| 2473 | */ |
| 2474 | ii = ecm_interface_unknown_interface_establish(&type_info.unknown, dev_name, dev_interface_num, ae_interface_num, dev_mtu); |
| 2475 | return ii; |
| 2476 | } |
| 2477 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2478 | /* |
| 2479 | * PPP - but what is the channel type? |
| 2480 | * First: If this is multi-link then we do not support it |
| 2481 | */ |
| 2482 | if (ppp_is_multilink(dev) > 0) { |
| 2483 | DEBUG_TRACE("Net device: %p is MULTILINK PPP - Unknown to the ECM\n", dev); |
| 2484 | type_info.unknown.os_specific_ident = dev_interface_num; |
| 2485 | |
| 2486 | /* |
| 2487 | * Establish this type of interface |
| 2488 | */ |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 2489 | ii = ecm_interface_unknown_interface_establish(&type_info.unknown, dev_name, dev_interface_num, ae_interface_num, dev_mtu); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2490 | return ii; |
| 2491 | } |
| 2492 | |
| 2493 | DEBUG_TRACE("Net device: %p is PPP\n", dev); |
| 2494 | |
| 2495 | /* |
| 2496 | * Get the PPP channel and then enquire what kind of channel it is |
| 2497 | * NOTE: Not multilink so only one channel to get. |
| 2498 | */ |
| 2499 | channel_count = ppp_hold_channels(dev, ppp_chan, 1); |
| 2500 | if (channel_count != 1) { |
Gareth Williams | 6f96a4b | 2014-05-29 19:41:21 +0100 | [diff] [blame] | 2501 | DEBUG_TRACE("Net device: %p PPP has %d channels - ECM cannot handle this (interface becomes Unknown type)\n", |
| 2502 | dev, channel_count); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2503 | type_info.unknown.os_specific_ident = dev_interface_num; |
| 2504 | |
| 2505 | /* |
| 2506 | * Establish this type of interface |
| 2507 | */ |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 2508 | ii = ecm_interface_unknown_interface_establish(&type_info.unknown, dev_name, dev_interface_num, ae_interface_num, dev_mtu); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2509 | return ii; |
| 2510 | } |
| 2511 | |
| 2512 | /* |
| 2513 | * Get channel protocol type |
Gareth Williams | 6f96a4b | 2014-05-29 19:41:21 +0100 | [diff] [blame] | 2514 | * NOTE: Not all PPP channels support channel specific methods. |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2515 | */ |
Gareth Williams | 6f96a4b | 2014-05-29 19:41:21 +0100 | [diff] [blame] | 2516 | channel_protocol = ppp_channel_get_protocol(ppp_chan[0]); |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 2517 | |
| 2518 | #ifdef ECM_INTERFACE_L2TPV2_ENABLE |
| 2519 | if (channel_protocol == PX_PROTO_OL2TP) { |
ratheesh kannoth | 08b8e44 | 2015-10-02 00:24:55 +0530 | [diff] [blame] | 2520 | struct pppol2tp_common_addr info; |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2521 | |
ratheesh kannoth | 08b8e44 | 2015-10-02 00:24:55 +0530 | [diff] [blame] | 2522 | if (pppol2tp_channel_addressing_get(ppp_chan[0], &info)) { |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 2523 | ppp_release_channels(ppp_chan, 1); |
| 2524 | return NULL; |
| 2525 | } |
| 2526 | |
ratheesh kannoth | 08b8e44 | 2015-10-02 00:24:55 +0530 | [diff] [blame] | 2527 | type_info.pppol2tpv2.l2tp.tunnel.tunnel_id = info.local_tunnel_id; |
| 2528 | type_info.pppol2tpv2.l2tp.tunnel.peer_tunnel_id = info.remote_tunnel_id; |
| 2529 | type_info.pppol2tpv2.l2tp.session.session_id = info.local_session_id; |
| 2530 | type_info.pppol2tpv2.l2tp.session.peer_session_id = info.remote_session_id; |
| 2531 | type_info.pppol2tpv2.udp.sport = ntohs(info.local_addr.sin_port); |
| 2532 | type_info.pppol2tpv2.udp.dport = ntohs(info.remote_addr.sin_port); |
| 2533 | type_info.pppol2tpv2.ip.saddr = ntohl(info.local_addr.sin_addr.s_addr); |
| 2534 | type_info.pppol2tpv2.ip.daddr = ntohl(info.remote_addr.sin_addr.s_addr); |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 2535 | |
| 2536 | /* |
| 2537 | * Release the channel. Note that next_dev is still (correctly) held. |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2538 | */ |
| 2539 | ppp_release_channels(ppp_chan, 1); |
| 2540 | |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 2541 | DEBUG_TRACE("Net device: %p PPPo2L2TP session: %d,n", dev, type_info.pppol2tpv2.l2tp.session.peer_session_id); |
| 2542 | |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2543 | /* |
| 2544 | * Establish this type of interface |
| 2545 | */ |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 2546 | ii = ecm_interface_pppol2tpv2_interface_establish(&type_info.pppol2tpv2, dev_name, dev_interface_num, ae_interface_num, dev_mtu); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2547 | return ii; |
| 2548 | } |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 2549 | #endif |
| 2550 | #ifdef ECM_INTERFACE_PPPOE_ENABLE |
| 2551 | if (channel_protocol == PX_PROTO_OE) { |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 2552 | /* |
| 2553 | * PPPoE channel |
| 2554 | */ |
| 2555 | DEBUG_TRACE("Net device: %p PPP channel is PPPoE\n", dev); |
| 2556 | |
| 2557 | /* |
| 2558 | * Get PPPoE session information and the underlying device it is using. |
| 2559 | */ |
| 2560 | pppoe_channel_addressing_get(ppp_chan[0], &addressing); |
| 2561 | type_info.pppoe.pppoe_session_id = (uint16_t)ntohs((uint16_t)addressing.pa.sid); |
| 2562 | memcpy(type_info.pppoe.remote_mac, addressing.pa.remote, ETH_ALEN); |
| 2563 | dev_put(addressing.dev); |
| 2564 | |
| 2565 | /* |
| 2566 | * Release the channel. Note that next_dev is still (correctly) held. |
| 2567 | */ |
| 2568 | ppp_release_channels(ppp_chan, 1); |
| 2569 | |
| 2570 | DEBUG_TRACE("Net device: %p PPPoE session: %x, remote mac: %pM\n", |
| 2571 | dev, type_info.pppoe.pppoe_session_id, type_info.pppoe.remote_mac); |
| 2572 | |
| 2573 | /* |
| 2574 | * Establish this type of interface |
| 2575 | */ |
| 2576 | ii = ecm_interface_pppoe_interface_establish(&type_info.pppoe, dev_name, dev_interface_num, ae_interface_num, dev_mtu); |
| 2577 | return ii; |
| 2578 | } |
| 2579 | #endif |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 2580 | |
| 2581 | #ifdef ECM_INTERFACE_PPTP_ENABLE |
| 2582 | if (channel_protocol == PX_PROTO_PPTP) { |
Swaraj Sha | 0562058 | 2018-08-15 23:21:16 +0530 | [diff] [blame] | 2583 | |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 2584 | pptp_channel_addressing_get(&opt, ppp_chan[0]); |
| 2585 | |
| 2586 | /* |
| 2587 | * Get PPTP session info |
| 2588 | */ |
| 2589 | type_info.pptp.src_call_id = ntohs(opt.src_addr.call_id); |
| 2590 | type_info.pptp.dst_call_id = ntohs(opt.dst_addr.call_id); |
| 2591 | type_info.pptp.src_ip = ntohl(opt.src_addr.sin_addr.s_addr); |
| 2592 | type_info.pptp.dst_ip = ntohl(opt.dst_addr.sin_addr.s_addr); |
| 2593 | |
| 2594 | DEBUG_TRACE("Net device: %p PPTP source call id: %d,n", dev, type_info.pptp.src_call_id); |
| 2595 | ppp_release_channels(ppp_chan, 1); |
| 2596 | |
Swaraj Sha | 0562058 | 2018-08-15 23:21:16 +0530 | [diff] [blame] | 2597 | interface_type = feci->ae_interface_type_get(feci, dev); |
| 2598 | ae_interface_num = feci->ae_interface_number_by_dev_type_get(dev, interface_type); |
| 2599 | |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 2600 | /* |
| 2601 | * Establish this type of interface |
| 2602 | */ |
| 2603 | ii = ecm_interface_pptp_interface_establish(&type_info.pptp, dev_name, dev_interface_num, ae_interface_num, dev_mtu); |
Shyam Sunder | 65f013e | 2015-12-14 18:04:54 +0530 | [diff] [blame] | 2604 | if (ii) { |
| 2605 | /* |
| 2606 | * The ifindex of a virtual netdevice like a PPTP session can change if it is destroyed |
| 2607 | * and comes up again. Detect if the ifindex has changed and update it if required |
| 2608 | */ |
| 2609 | ecm_db_iface_identifier_hash_table_entry_check_and_update(ii, dev_interface_num); |
| 2610 | } |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 2611 | return ii; |
| 2612 | } |
| 2613 | #endif |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 2614 | DEBUG_TRACE("Net device: %p PPP channel protocol: %d - Unknown to the ECM\n", dev, channel_protocol); |
| 2615 | type_info.unknown.os_specific_ident = dev_interface_num; |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2616 | |
| 2617 | /* |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 2618 | * Release the channel |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2619 | */ |
| 2620 | ppp_release_channels(ppp_chan, 1); |
| 2621 | |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2622 | /* |
| 2623 | * Establish this type of interface |
| 2624 | */ |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 2625 | ii = ecm_interface_unknown_interface_establish(&type_info.unknown, dev_name, dev_interface_num, ae_interface_num, dev_mtu); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2626 | return ii; |
Gareth Williams | c5b9d71 | 2014-05-09 20:40:07 +0100 | [diff] [blame] | 2627 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 2628 | } |
| 2629 | EXPORT_SYMBOL(ecm_interface_establish_and_ref); |
| 2630 | |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 2631 | #ifdef ECM_MULTICAST_ENABLE |
| 2632 | /* |
| 2633 | * ecm_interface_multicast_heirarchy_construct_single() |
| 2634 | * Create and return an interface heirarchy for a single interface for a multicast connection |
| 2635 | * |
| 2636 | * src_addr IP source address |
| 2637 | * dest_addr IP Destination address/Group Address |
| 2638 | * interface Pointer to a single multicast interface heirarchy |
| 2639 | * given_dest_dev Netdev pointer for destination interface |
| 2640 | * br_slave_dev Netdev pointer to a bridge slave device. It could be NULL in case of pure |
| 2641 | * routed flow without any bridge interface in destination dev list. |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 2642 | * skb sk_buff |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 2643 | */ |
Shyam Sunder | 8183683 | 2015-07-09 19:18:25 +0530 | [diff] [blame] | 2644 | static uint32_t ecm_interface_multicast_heirarchy_construct_single(struct ecm_front_end_connection_instance *feci, ip_addr_t src_addr, |
| 2645 | ip_addr_t dest_addr, struct ecm_db_iface_instance *interface, |
| 2646 | struct net_device *given_dest_dev, struct net_device *br_slave_dev, |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 2647 | uint8_t *src_node_addr, bool is_routed, __be16 *layer4hdr, struct sk_buff *skb) |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 2648 | { |
| 2649 | struct ecm_db_iface_instance *to_list_single[ECM_DB_IFACE_HEIRARCHY_MAX]; |
| 2650 | struct ecm_db_iface_instance **ifaces; |
| 2651 | struct ecm_db_iface_instance *ii_temp; |
| 2652 | struct net_device *dest_dev; |
| 2653 | int32_t current_interface_index; |
| 2654 | int32_t interfaces_cnt = 0; |
| 2655 | int32_t dest_dev_type; |
| 2656 | |
| 2657 | dest_dev = given_dest_dev; |
| 2658 | dev_hold(dest_dev); |
| 2659 | dest_dev_type = dest_dev->type; |
| 2660 | current_interface_index = ECM_DB_IFACE_HEIRARCHY_MAX; |
| 2661 | |
| 2662 | while (current_interface_index > 0) { |
| 2663 | struct ecm_db_iface_instance *ii; |
| 2664 | struct net_device *next_dev; |
| 2665 | |
| 2666 | /* |
| 2667 | * Get the ecm db interface instance for the device at hand |
| 2668 | */ |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 2669 | ii = ecm_interface_establish_and_ref(feci, dest_dev, skb); |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 2670 | interfaces_cnt++; |
| 2671 | |
| 2672 | /* |
| 2673 | * If the interface could not be established then we abort |
| 2674 | */ |
| 2675 | if (!ii) { |
| 2676 | DEBUG_WARN("Failed to establish interface: %p, name: %s\n", dest_dev, dest_dev->name); |
| 2677 | dev_put(dest_dev); |
| 2678 | |
| 2679 | /* |
| 2680 | * Release the interfaces heirarchy we constructed to this point. |
| 2681 | */ |
| 2682 | ecm_db_multicast_copy_if_heirarchy(to_list_single, interface); |
| 2683 | ecm_db_connection_interfaces_deref(to_list_single, current_interface_index); |
| 2684 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 2685 | } |
| 2686 | |
| 2687 | /* |
| 2688 | * Record the interface instance into the *ifaces |
| 2689 | */ |
| 2690 | current_interface_index--; |
| 2691 | ii_temp = ecm_db_multicast_if_instance_get_at_index(interface, current_interface_index); |
| 2692 | ifaces = (struct ecm_db_iface_instance **)ii_temp; |
| 2693 | *ifaces = ii; |
| 2694 | |
| 2695 | /* |
| 2696 | * Now we have to figure out what the next device will be (in the transmission path) |
| 2697 | */ |
| 2698 | do { |
Kiran Kumar C.S.K | d43bc3f | 2015-08-04 16:51:03 +0530 | [diff] [blame] | 2699 | #ifdef ECM_INTERFACE_PPP_ENABLE |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 2700 | int channel_count; |
| 2701 | struct ppp_channel *ppp_chan[1]; |
| 2702 | int channel_protocol; |
| 2703 | struct pppoe_opt addressing; |
| 2704 | #endif |
| 2705 | DEBUG_TRACE("Net device: %p is type: %d, name: %s\n", dest_dev, dest_dev_type, dest_dev->name); |
| 2706 | next_dev = NULL; |
| 2707 | |
| 2708 | if (dest_dev_type == ARPHRD_ETHER) { |
| 2709 | /* |
| 2710 | * Ethernet - but what sub type? |
| 2711 | */ |
| 2712 | |
| 2713 | /* |
| 2714 | * VLAN? |
| 2715 | */ |
| 2716 | if (is_vlan_dev(dest_dev)) { |
| 2717 | /* |
| 2718 | * VLAN master |
| 2719 | * No locking needed here, ASSUMPTION is that real_dev is held for as long as we have dev. |
| 2720 | */ |
Shyam Sunder | 9db2085 | 2016-03-09 19:04:49 +0530 | [diff] [blame] | 2721 | next_dev = ecm_interface_vlan_real_dev(dest_dev); |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 2722 | dev_hold(next_dev); |
| 2723 | DEBUG_TRACE("Net device: %p is VLAN, slave dev: %p (%s)\n", |
| 2724 | dest_dev, next_dev, next_dev->name); |
| 2725 | break; |
| 2726 | } |
| 2727 | |
| 2728 | /* |
| 2729 | * BRIDGE? |
| 2730 | */ |
| 2731 | if (ecm_front_end_is_bridge_device(dest_dev)) { |
| 2732 | if (!ecm_front_end_is_bridge_port(br_slave_dev)) { |
| 2733 | DEBUG_ASSERT(NULL, "%p: expected only bridge slave here\n", interface); |
| 2734 | |
| 2735 | /* |
| 2736 | * Release the interfaces heirarchy we constructed to this point. |
| 2737 | */ |
| 2738 | ecm_db_multicast_copy_if_heirarchy(to_list_single, interface); |
| 2739 | ecm_db_connection_interfaces_deref(to_list_single, current_interface_index); |
| 2740 | dev_put(dest_dev); |
| 2741 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 2742 | } |
| 2743 | |
| 2744 | next_dev = br_slave_dev; |
| 2745 | if (!next_dev) { |
| 2746 | DEBUG_WARN("Unable to obtain output port \n"); |
| 2747 | |
| 2748 | /* |
| 2749 | * Release the interfaces heirarchy we constructed to this point. |
| 2750 | */ |
| 2751 | ecm_db_multicast_copy_if_heirarchy(to_list_single, interface); |
| 2752 | ecm_db_connection_interfaces_deref(to_list_single, current_interface_index); |
| 2753 | dev_put(dest_dev); |
| 2754 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 2755 | } |
| 2756 | DEBUG_TRACE("Net device: %p is BRIDGE, next_dev: %p (%s)\n", dest_dev, next_dev, next_dev->name); |
| 2757 | dev_hold(next_dev); |
| 2758 | break; |
| 2759 | } |
| 2760 | |
Shyam Sunder | 8183683 | 2015-07-09 19:18:25 +0530 | [diff] [blame] | 2761 | #ifdef ECM_INTERFACE_BOND_ENABLE |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 2762 | /* |
| 2763 | * LAG? |
| 2764 | */ |
| 2765 | if (ecm_front_end_is_lag_master(dest_dev)) { |
| 2766 | /* |
| 2767 | * Link aggregation |
| 2768 | * Figure out which slave device of the link aggregation will be used to reach the destination. |
| 2769 | */ |
| 2770 | uint32_t src_addr_32 = 0; |
| 2771 | uint32_t dest_addr_32 = 0; |
Suman Ghosh | f14d217 | 2015-07-31 14:38:10 +0530 | [diff] [blame] | 2772 | struct in6_addr src_addr6; |
| 2773 | struct in6_addr dest_addr6; |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 2774 | uint8_t src_mac_addr[ETH_ALEN]; |
| 2775 | uint8_t dest_mac_addr[ETH_ALEN]; |
| 2776 | |
| 2777 | memset(src_mac_addr, 0, ETH_ALEN); |
| 2778 | memset(dest_mac_addr, 0, ETH_ALEN); |
| 2779 | |
Shyam Sunder | 8183683 | 2015-07-09 19:18:25 +0530 | [diff] [blame] | 2780 | if (ECM_IP_ADDR_IS_V4(src_addr)) { |
| 2781 | ECM_IP_ADDR_TO_NIN4_ADDR(src_addr_32, src_addr); |
| 2782 | ECM_IP_ADDR_TO_NIN4_ADDR(dest_addr_32, dest_addr); |
| 2783 | } |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 2784 | |
Shyam Sunder | 8183683 | 2015-07-09 19:18:25 +0530 | [diff] [blame] | 2785 | if (!is_routed) { |
| 2786 | memcpy(src_mac_addr, src_node_addr, ETH_ALEN); |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 2787 | } else { |
Shyam Sunder | 8183683 | 2015-07-09 19:18:25 +0530 | [diff] [blame] | 2788 | struct net_device *dest_dev_master; |
| 2789 | |
| 2790 | /* |
| 2791 | * Use appropriate source MAC address for routed packets |
| 2792 | */ |
| 2793 | dest_dev_master = ecm_interface_get_and_hold_dev_master(dest_dev); |
| 2794 | if (dest_dev_master) { |
| 2795 | memcpy(src_mac_addr, dest_dev_master->dev_addr, ETH_ALEN); |
| 2796 | dev_put(dest_dev_master); |
| 2797 | } else { |
| 2798 | memcpy(src_mac_addr, dest_dev->dev_addr, ETH_ALEN); |
| 2799 | } |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 2800 | } |
| 2801 | |
| 2802 | /* |
| 2803 | * Create Destination MAC address using IP multicast destination address |
| 2804 | */ |
| 2805 | ecm_translate_multicast_mac(dest_addr, dest_mac_addr); |
| 2806 | |
Shyam Sunder | 8183683 | 2015-07-09 19:18:25 +0530 | [diff] [blame] | 2807 | if (ECM_IP_ADDR_IS_V4(src_addr)) { |
| 2808 | next_dev = bond_get_tx_dev(NULL, src_mac_addr, dest_mac_addr, |
| 2809 | &src_addr_32, &dest_addr_32, |
Suman Ghosh | fb8e770 | 2015-08-20 15:27:57 +0530 | [diff] [blame] | 2810 | htons((uint16_t)ETH_P_IP), dest_dev, layer4hdr); |
Shyam Sunder | 8183683 | 2015-07-09 19:18:25 +0530 | [diff] [blame] | 2811 | } else { |
Suman Ghosh | f14d217 | 2015-07-31 14:38:10 +0530 | [diff] [blame] | 2812 | ECM_IP_ADDR_TO_NIN6_ADDR(src_addr6, src_addr); |
| 2813 | ECM_IP_ADDR_TO_NIN6_ADDR(dest_addr6, dest_addr); |
Shyam Sunder | 8183683 | 2015-07-09 19:18:25 +0530 | [diff] [blame] | 2814 | next_dev = bond_get_tx_dev(NULL, src_mac_addr, dest_mac_addr, |
Suman Ghosh | f14d217 | 2015-07-31 14:38:10 +0530 | [diff] [blame] | 2815 | src_addr6.s6_addr, dest_addr6.s6_addr, |
Shyam Sunder | e60540c | 2016-04-29 15:06:35 +0530 | [diff] [blame] | 2816 | htons((uint16_t)ETH_P_IPV6), dest_dev, layer4hdr); |
Shyam Sunder | 8183683 | 2015-07-09 19:18:25 +0530 | [diff] [blame] | 2817 | } |
| 2818 | |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 2819 | if (!(next_dev && netif_carrier_ok(next_dev))) { |
| 2820 | DEBUG_WARN("Unable to obtain LAG output slave device\n"); |
| 2821 | dev_put(dest_dev); |
| 2822 | |
| 2823 | /* |
| 2824 | * Release the interfaces heirarchy we constructed to this point. |
| 2825 | */ |
| 2826 | ecm_db_multicast_copy_if_heirarchy(to_list_single, interface); |
| 2827 | ecm_db_connection_interfaces_deref(to_list_single, current_interface_index); |
| 2828 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 2829 | } |
| 2830 | |
| 2831 | dev_hold(next_dev); |
| 2832 | DEBUG_TRACE("Net device: %p is LAG, slave dev: %p (%s)\n", dest_dev, next_dev, next_dev->name); |
| 2833 | break; |
| 2834 | } |
| 2835 | #endif |
| 2836 | |
| 2837 | /* |
| 2838 | * ETHERNET! |
| 2839 | * Just plain ethernet it seems. |
| 2840 | */ |
| 2841 | DEBUG_TRACE("Net device: %p is ETHERNET\n", dest_dev); |
| 2842 | break; |
| 2843 | } |
| 2844 | |
| 2845 | /* |
| 2846 | * LOOPBACK? |
| 2847 | */ |
| 2848 | if (dest_dev_type == ARPHRD_LOOPBACK) { |
| 2849 | DEBUG_TRACE("Net device: %p is LOOPBACK type: %d\n", dest_dev, dest_dev_type); |
| 2850 | break; |
| 2851 | } |
| 2852 | |
| 2853 | /* |
| 2854 | * IPSEC? |
| 2855 | */ |
| 2856 | if (dest_dev_type == ECM_ARPHRD_IPSEC_TUNNEL_TYPE) { |
| 2857 | DEBUG_TRACE("Net device: %p is IPSec tunnel type: %d\n", dest_dev, dest_dev_type); |
| 2858 | /* |
| 2859 | * TODO Figure out the next device the tunnel is using... |
| 2860 | */ |
| 2861 | break; |
| 2862 | } |
| 2863 | |
| 2864 | /* |
| 2865 | * SIT (6-in-4)? |
| 2866 | */ |
| 2867 | if (dest_dev_type == ARPHRD_SIT) { |
| 2868 | DEBUG_TRACE("Net device: %p is SIT (6-in-4) type: %d\n", dest_dev, dest_dev_type); |
| 2869 | /* |
| 2870 | * TODO Figure out the next device the tunnel is using... |
| 2871 | */ |
| 2872 | break; |
| 2873 | } |
| 2874 | |
| 2875 | /* |
| 2876 | * IPIP6 Tunnel? |
| 2877 | */ |
| 2878 | if (dest_dev_type == ARPHRD_TUNNEL6) { |
| 2879 | DEBUG_TRACE("Net device: %p is TUNIPIP6 type: %d\n", dest_dev, dest_dev_type); |
| 2880 | /* |
| 2881 | * TODO Figure out the next device the tunnel is using... |
| 2882 | */ |
| 2883 | break; |
| 2884 | } |
| 2885 | |
| 2886 | /* |
| 2887 | * If this is NOT PPP then it is unknown to the ecm and we cannot figure out it's next device. |
| 2888 | */ |
| 2889 | if (dest_dev_type != ARPHRD_PPP) { |
| 2890 | DEBUG_TRACE("Net device: %p is UNKNOWN type: %d\n", dest_dev, dest_dev_type); |
| 2891 | break; |
| 2892 | } |
| 2893 | |
Kiran Kumar C.S.K | d43bc3f | 2015-08-04 16:51:03 +0530 | [diff] [blame] | 2894 | #ifndef ECM_INTERFACE_PPP_ENABLE |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 2895 | DEBUG_TRACE("Net device: %p is UNKNOWN (PPP Unsupported) type: %d\n", dest_dev, dest_dev_type); |
| 2896 | #else |
| 2897 | /* |
| 2898 | * PPP - but what is the channel type? |
| 2899 | * First: If this is multi-link then we do not support it |
| 2900 | */ |
| 2901 | if (ppp_is_multilink(dest_dev) > 0) { |
| 2902 | DEBUG_TRACE("Net device: %p is MULTILINK PPP - Unknown to the ECM\n", dest_dev); |
| 2903 | break; |
| 2904 | } |
| 2905 | |
| 2906 | DEBUG_TRACE("Net device: %p is PPP\n", dest_dev); |
| 2907 | |
| 2908 | /* |
| 2909 | * Get the PPP channel and then enquire what kind of channel it is |
| 2910 | * NOTE: Not multilink so only one channel to get. |
| 2911 | */ |
| 2912 | channel_count = ppp_hold_channels(dest_dev, ppp_chan, 1); |
| 2913 | if (channel_count != 1) { |
| 2914 | DEBUG_TRACE("Net device: %p PPP has %d channels - Unknown to the ECM\n", |
| 2915 | dest_dev, channel_count); |
| 2916 | break; |
| 2917 | } |
| 2918 | |
| 2919 | /* |
| 2920 | * Get channel protocol type |
| 2921 | * NOTE: Not all PPP channels support channel specific methods. |
| 2922 | */ |
| 2923 | channel_protocol = ppp_channel_get_protocol(ppp_chan[0]); |
| 2924 | if (channel_protocol != PX_PROTO_OE) { |
| 2925 | DEBUG_TRACE("Net device: %p PPP channel protocol: %d - Unknown to the ECM\n", |
| 2926 | dest_dev, channel_protocol); |
| 2927 | |
| 2928 | /* |
| 2929 | * Release the channel |
| 2930 | */ |
| 2931 | ppp_release_channels(ppp_chan, 1); |
| 2932 | |
| 2933 | break; |
| 2934 | } |
| 2935 | |
| 2936 | /* |
| 2937 | * PPPoE channel |
| 2938 | */ |
| 2939 | DEBUG_TRACE("Net device: %p PPP channel is PPPoE\n", dest_dev); |
| 2940 | |
| 2941 | /* |
| 2942 | * Get PPPoE session information and the underlying device it is using. |
| 2943 | */ |
| 2944 | pppoe_channel_addressing_get(ppp_chan[0], &addressing); |
| 2945 | |
| 2946 | /* |
| 2947 | * Copy the dev hold into this, we will release the hold later |
| 2948 | */ |
| 2949 | next_dev = addressing.dev; |
| 2950 | |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 2951 | /* |
| 2952 | * Release the channel. Note that next_dev is still (correctly) held. |
| 2953 | */ |
| 2954 | ppp_release_channels(ppp_chan, 1); |
| 2955 | #endif |
| 2956 | } while (false); |
| 2957 | |
| 2958 | /* |
| 2959 | * No longer need dest_dev as it may become next_dev |
| 2960 | */ |
| 2961 | dev_put(dest_dev); |
| 2962 | |
| 2963 | /* |
| 2964 | * Check out the next_dev, if any |
| 2965 | */ |
| 2966 | if (!next_dev) { |
| 2967 | int32_t i __attribute__((unused)); |
| 2968 | DEBUG_INFO("Completed interface heirarchy construct with first interface @: %d\n", current_interface_index); |
| 2969 | #if DEBUG_LEVEL > 1 |
| 2970 | ecm_db_multicast_copy_if_heirarchy(to_list_single, interface); |
| 2971 | for (i = current_interface_index; i < ECM_DB_IFACE_HEIRARCHY_MAX; ++i) { |
| 2972 | DEBUG_TRACE("\tInterface @ %d: %p, type: %d, name: %s\n", \ |
Murat Sezgin | 3d9a764 | 2018-05-15 16:24:09 -0700 | [diff] [blame] | 2973 | i, to_list_single[i], ecm_db_iface_type_get(to_list_single[i]), \ |
| 2974 | ecm_db_interface_type_to_string(ecm_db_iface_type_get(to_list_single[i]))); |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 2975 | } |
| 2976 | #endif |
| 2977 | return current_interface_index; |
| 2978 | } |
| 2979 | |
| 2980 | /* |
| 2981 | * dest_dev becomes next_dev |
| 2982 | */ |
| 2983 | dest_dev = next_dev; |
| 2984 | dest_dev_type = dest_dev->type; |
| 2985 | } |
| 2986 | |
| 2987 | dev_put(dest_dev); |
| 2988 | |
| 2989 | ecm_db_multicast_copy_if_heirarchy(to_list_single, interface); |
| 2990 | ecm_db_connection_interfaces_deref(to_list_single, current_interface_index); |
| 2991 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 2992 | } |
| 2993 | |
| 2994 | /* |
| 2995 | * ecm_interface_multicast_heirarchy_construct_routed() |
| 2996 | * Create destination interface heirarchy for a routed multicast connectiona |
| 2997 | * |
| 2998 | * interfaces Pointer to the 2-D array of multicast interface heirarchies |
| 2999 | * in_dev Pointer to the source netdev |
| 3000 | * packet_src_addr Source IP of the multicast flow |
| 3001 | * packet_dest_addr Group(dest) IP of the multicast flow |
| 3002 | * max_dst Maximum number of netdev joined the multicast group |
| 3003 | * dst_if_index_base An array of if index joined the multicast group |
| 3004 | * interface_first_base An array of the index of the first interface in the list |
| 3005 | */ |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 3006 | int32_t ecm_interface_multicast_heirarchy_construct_routed(struct ecm_front_end_connection_instance *feci, |
| 3007 | struct ecm_db_iface_instance *interfaces, |
| 3008 | struct net_device *in_dev, |
| 3009 | ip_addr_t packet_src_addr, |
| 3010 | ip_addr_t packet_dest_addr, uint8_t max_if, |
| 3011 | uint32_t *dst_if_index_base, |
Shyam Sunder | a2e08ee | 2015-06-18 21:32:13 +0530 | [diff] [blame] | 3012 | uint32_t *interface_first_base, bool mfc_update, |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 3013 | __be16 *layer4hdr, struct sk_buff *skb) |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 3014 | { |
| 3015 | struct ecm_db_iface_instance *to_list_single[ECM_DB_IFACE_HEIRARCHY_MAX]; |
| 3016 | struct ecm_db_iface_instance *ifaces; |
| 3017 | struct net_device *dest_dev = NULL; |
| 3018 | struct net_device *br_dev_src = NULL; |
| 3019 | uint32_t *dst_if_index; |
| 3020 | uint32_t *interface_first; |
| 3021 | uint32_t br_if; |
| 3022 | uint32_t valid_if; |
Shyam Sunder | 4163787 | 2015-06-11 21:19:05 +0530 | [diff] [blame] | 3023 | int32_t if_num; |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 3024 | int32_t dest_dev_type; |
| 3025 | int if_index; |
| 3026 | int ii_cnt; |
| 3027 | int total_ii_count = 0; |
| 3028 | bool src_dev_is_bridge = false; |
| 3029 | |
| 3030 | DEBUG_TRACE("Construct interface heirarchy for dest_addr: " ECM_IP_ADDR_DOT_FMT " src_addr: " ECM_IP_ADDR_DOT_FMT "total destination ifs %d\n", |
| 3031 | ECM_IP_ADDR_TO_DOT(packet_dest_addr), ECM_IP_ADDR_TO_DOT(packet_src_addr), max_if); |
| 3032 | |
| 3033 | /* |
| 3034 | * Check if the source net_dev is a bridge slave. |
| 3035 | */ |
Shyam Sunder | a2e08ee | 2015-06-18 21:32:13 +0530 | [diff] [blame] | 3036 | if (in_dev && !mfc_update) { |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 3037 | if (ecm_front_end_is_bridge_port(in_dev)) { |
| 3038 | src_dev_is_bridge = true; |
Karthik Hariharan | 3e964a3 | 2015-09-22 21:40:52 +0530 | [diff] [blame] | 3039 | br_dev_src = ecm_interface_get_and_hold_dev_master(in_dev); |
| 3040 | DEBUG_ASSERT(br_dev_src, "Expected a master\n"); |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 3041 | |
| 3042 | /* |
| 3043 | * The source net_dev found as bridge slave. In case of routed interface |
| 3044 | * heirarchy MFC is not aware of any other bridge slave has joined the same |
| 3045 | * multicast group as a destination interface. Therfore we assume there |
| 3046 | * are bridge slaves present in multicast destination interface list |
| 3047 | * and increase the max_if by one. |
| 3048 | */ |
| 3049 | max_if++; |
| 3050 | } |
| 3051 | } |
| 3052 | |
| 3053 | ii_cnt = 0; |
| 3054 | br_if = if_num = 0; |
| 3055 | |
| 3056 | /* |
| 3057 | * This loop is for creating the destination interface hierarchy list. |
| 3058 | * We take the destination interface array we got from MFC (in form of ifindex array) |
| 3059 | * as input for this. |
| 3060 | */ |
| 3061 | for (if_index = 0, valid_if = 0; if_index < max_if; if_index++) { |
| 3062 | dst_if_index = ecm_db_multicast_if_first_get_at_index(dst_if_index_base, if_index); |
| 3063 | |
| 3064 | if (*dst_if_index == ECM_INTERFACE_LOOPBACK_DEV_INDEX) { |
| 3065 | continue; |
| 3066 | } |
| 3067 | |
| 3068 | dest_dev = dev_get_by_index(&init_net, *dst_if_index); |
| 3069 | if (!dest_dev) { |
| 3070 | if (!src_dev_is_bridge) { |
| 3071 | int i; |
| 3072 | |
| 3073 | /* |
| 3074 | * If already constructed any interface heirarchies before hitting |
| 3075 | * this error condition then Deref all interface heirarchies. |
| 3076 | */ |
| 3077 | if (valid_if > 0) { |
| 3078 | for (i = 0; i < valid_if; i++) { |
| 3079 | ifaces = ecm_db_multicast_if_heirarchy_get(interfaces, i); |
| 3080 | ecm_db_multicast_copy_if_heirarchy(to_list_single, ifaces); |
| 3081 | ecm_db_connection_interfaces_deref(to_list_single, interface_first_base[i]); |
| 3082 | } |
| 3083 | } |
| 3084 | |
| 3085 | /* |
| 3086 | * If valid netdev not found, Return 0 |
| 3087 | */ |
| 3088 | return 0; |
| 3089 | } |
Karthik Hariharan | 3e964a3 | 2015-09-22 21:40:52 +0530 | [diff] [blame] | 3090 | |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 3091 | dest_dev = br_dev_src; |
Karthik Hariharan | 3e964a3 | 2015-09-22 21:40:52 +0530 | [diff] [blame] | 3092 | |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 3093 | } |
| 3094 | |
| 3095 | dest_dev_type = dest_dev->type; |
| 3096 | |
| 3097 | if (ecm_front_end_is_bridge_device(dest_dev)) { |
| 3098 | struct net_device *mc_br_slave_dev = NULL; |
| 3099 | uint32_t mc_max_dst = ECM_DB_MULTICAST_IF_MAX; |
| 3100 | uint32_t mc_dst_if_index[ECM_DB_MULTICAST_IF_MAX]; |
| 3101 | |
| 3102 | if (ECM_IP_ADDR_IS_V4(packet_src_addr)) { |
| 3103 | if_num = mc_bridge_ipv4_get_if(dest_dev, htonl((packet_src_addr[0])), htonl(packet_dest_addr[0]), mc_max_dst, mc_dst_if_index); |
| 3104 | } else { |
| 3105 | struct in6_addr origin6; |
| 3106 | struct in6_addr group6; |
| 3107 | ECM_IP_ADDR_TO_NIN6_ADDR(origin6, packet_src_addr); |
| 3108 | ECM_IP_ADDR_TO_NIN6_ADDR(group6, packet_dest_addr); |
| 3109 | if_num = mc_bridge_ipv6_get_if(dest_dev, &origin6, &group6, mc_max_dst, mc_dst_if_index); |
| 3110 | } |
| 3111 | |
Shyam Sunder | 8183683 | 2015-07-09 19:18:25 +0530 | [diff] [blame] | 3112 | if ((if_num < 0) || (if_num > ECM_DB_MULTICAST_IF_MAX)) { |
| 3113 | int i; |
| 3114 | DEBUG_WARN("MCS is not ready\n"); |
| 3115 | |
| 3116 | /* |
| 3117 | * If already constructed any interface heirarchies before hitting |
| 3118 | * this error condition then Deref all interface heirarchies. |
| 3119 | */ |
| 3120 | if (valid_if > 0) { |
| 3121 | for (i = 0; i < valid_if; i++) { |
| 3122 | ifaces = ecm_db_multicast_if_heirarchy_get(interfaces, i); |
| 3123 | ecm_db_multicast_copy_if_heirarchy(to_list_single, ifaces); |
| 3124 | ecm_db_connection_interfaces_deref(to_list_single, interface_first_base[i]); |
| 3125 | } |
| 3126 | } |
| 3127 | |
Shyam Sunder | 4163787 | 2015-06-11 21:19:05 +0530 | [diff] [blame] | 3128 | dev_put(dest_dev); |
| 3129 | return 0; |
| 3130 | } |
| 3131 | |
Shyam Sunder | a450b58 | 2016-07-22 14:44:14 +0530 | [diff] [blame] | 3132 | if (in_dev && !mfc_update) { |
Shyam Sunder | 0658829 | 2016-04-18 19:57:39 +0530 | [diff] [blame] | 3133 | if_num = ecm_interface_multicast_check_for_src_ifindex(mc_dst_if_index, if_num, in_dev->ifindex); |
| 3134 | } |
Shyam Sunder | a2e08ee | 2015-06-18 21:32:13 +0530 | [diff] [blame] | 3135 | |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 3136 | for (br_if = 0; br_if < if_num; br_if++) { |
| 3137 | mc_br_slave_dev = dev_get_by_index(&init_net, mc_dst_if_index[br_if]); |
| 3138 | if (!mc_br_slave_dev) { |
| 3139 | continue; |
| 3140 | } |
| 3141 | |
| 3142 | if ((valid_if + br_if) > ECM_DB_MULTICAST_IF_MAX) { |
| 3143 | int i; |
| 3144 | |
| 3145 | /* |
| 3146 | * If already constructed any interface heirarchies before hitting |
| 3147 | * this error condition then Deref all interface heirarchies. |
| 3148 | */ |
| 3149 | for (i = 0; i < (valid_if + br_if); i++) { |
| 3150 | ifaces = ecm_db_multicast_if_heirarchy_get(interfaces, i); |
| 3151 | ecm_db_multicast_copy_if_heirarchy(to_list_single, ifaces); |
| 3152 | ecm_db_connection_interfaces_deref(to_list_single, interface_first_base[i]); |
| 3153 | } |
| 3154 | |
| 3155 | dev_put(dest_dev); |
| 3156 | dev_put(mc_br_slave_dev); |
| 3157 | return 0; |
| 3158 | } |
| 3159 | |
| 3160 | ifaces = ecm_db_multicast_if_heirarchy_get(interfaces, valid_if + br_if); |
| 3161 | /* |
| 3162 | * Construct a single interface heirarchy of a multicast dev. |
| 3163 | */ |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 3164 | ii_cnt = ecm_interface_multicast_heirarchy_construct_single(feci, packet_src_addr, packet_dest_addr, ifaces, dest_dev, mc_br_slave_dev, NULL, true, layer4hdr, skb); |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 3165 | if (ii_cnt == ECM_DB_IFACE_HEIRARCHY_MAX) { |
| 3166 | |
| 3167 | /* |
| 3168 | * If already constructed any interface heirarchies before hitting |
| 3169 | * this error condition then Deref all interface heirarchies. |
| 3170 | */ |
| 3171 | if ((valid_if + br_if) > 0) { |
| 3172 | int i; |
| 3173 | for (i = 0; i < (valid_if + br_if); i++) { |
| 3174 | ifaces = ecm_db_multicast_if_heirarchy_get(interfaces, i); |
| 3175 | ecm_db_multicast_copy_if_heirarchy(to_list_single, ifaces); |
| 3176 | ecm_db_connection_interfaces_deref(to_list_single, interface_first_base[i]); |
| 3177 | } |
| 3178 | } |
| 3179 | |
| 3180 | dev_put(dest_dev); |
| 3181 | dev_put(mc_br_slave_dev); |
| 3182 | return 0; |
| 3183 | } |
| 3184 | |
| 3185 | interface_first = ecm_db_multicast_if_first_get_at_index(interface_first_base, (valid_if + br_if)); |
| 3186 | *interface_first = ii_cnt; |
| 3187 | total_ii_count += ii_cnt; |
| 3188 | dev_put(mc_br_slave_dev); |
| 3189 | } |
| 3190 | |
| 3191 | valid_if += br_if; |
| 3192 | |
| 3193 | } else { |
| 3194 | |
| 3195 | DEBUG_ASSERT(valid_if < ECM_DB_MULTICAST_IF_MAX, "Bad array index size %d\n", valid_if); |
| 3196 | ifaces = ecm_db_multicast_if_heirarchy_get(interfaces, valid_if); |
| 3197 | /* |
| 3198 | * Construct a single interface heirarchy of a multicast dev. |
| 3199 | */ |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 3200 | ii_cnt = ecm_interface_multicast_heirarchy_construct_single(feci, packet_src_addr, packet_dest_addr, ifaces, dest_dev, NULL, NULL, true, layer4hdr, skb); |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 3201 | if (ii_cnt == ECM_DB_IFACE_HEIRARCHY_MAX) { |
| 3202 | |
| 3203 | /* |
| 3204 | * If already constructed any interface heirarchies before hitting |
| 3205 | * this error condition then Deref all interface heirarchies. |
| 3206 | */ |
| 3207 | if (valid_if > 0) { |
| 3208 | int i; |
| 3209 | for (i = 0; i < valid_if; i++) { |
| 3210 | ifaces = ecm_db_multicast_if_heirarchy_get(interfaces, i); |
| 3211 | ecm_db_multicast_copy_if_heirarchy(to_list_single, ifaces); |
| 3212 | ecm_db_connection_interfaces_deref(to_list_single, interface_first_base[i]); |
| 3213 | } |
| 3214 | } |
| 3215 | |
| 3216 | dev_put(dest_dev); |
| 3217 | return 0; |
| 3218 | } |
| 3219 | |
| 3220 | interface_first = ecm_db_multicast_if_first_get_at_index(interface_first_base, valid_if); |
| 3221 | *interface_first = ii_cnt; |
| 3222 | total_ii_count += ii_cnt; |
| 3223 | valid_if++; |
| 3224 | } |
| 3225 | |
| 3226 | dev_put(dest_dev); |
| 3227 | } |
| 3228 | return total_ii_count; |
| 3229 | } |
| 3230 | EXPORT_SYMBOL(ecm_interface_multicast_heirarchy_construct_routed); |
| 3231 | |
| 3232 | /* |
| 3233 | * ecm_interface_multicast_heirarchy_construct_bridged() |
| 3234 | * This function called when the Hyfi bridge snooper has IGMP/IMLD updates, this function |
| 3235 | * creates destination interface heirarchy for a bridged multicast connection. |
| 3236 | * |
| 3237 | * interfaces Pointer to the 2-D array of multicast interface heirarchies |
| 3238 | * dest_dev Pointer to the destination dev, here dest_dev is always a bridge type |
| 3239 | * packet_src_addr Source IP of the multicast flow |
| 3240 | * packet_dest_addr Group(dest) IP of the multicast flow |
| 3241 | * mc_max_dst Maximum number of bridge slaves joined the multicast group |
| 3242 | * mc_dst_if_index_base An array of if index joined the multicast group |
| 3243 | * interface_first_base An array of the index of the first interface in the list |
| 3244 | */ |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 3245 | int32_t ecm_interface_multicast_heirarchy_construct_bridged(struct ecm_front_end_connection_instance *feci, |
Shyam Sunder | 8183683 | 2015-07-09 19:18:25 +0530 | [diff] [blame] | 3246 | struct ecm_db_iface_instance *interfaces, struct net_device *dest_dev, |
| 3247 | ip_addr_t packet_src_addr, ip_addr_t packet_dest_addr, uint8_t mc_max_dst, |
Suman Ghosh | fb8e770 | 2015-08-20 15:27:57 +0530 | [diff] [blame] | 3248 | int *mc_dst_if_index_base, uint32_t *interface_first_base, uint8_t *src_node_addr, |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 3249 | __be16 *layer4hdr, struct sk_buff *skb) |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 3250 | { |
| 3251 | struct ecm_db_iface_instance *to_list_single[ECM_DB_IFACE_HEIRARCHY_MAX]; |
| 3252 | struct ecm_db_iface_instance *ifaces; |
| 3253 | struct net_device *mc_br_slave_dev = NULL; |
| 3254 | uint32_t *interface_first; |
| 3255 | int *mc_dst_if_index; |
| 3256 | int valid_if; |
| 3257 | int ii_cnt = 0; |
| 3258 | int br_if; |
| 3259 | int total_ii_cnt = 0; |
| 3260 | |
| 3261 | /* |
| 3262 | * Go through the newly joined interface index one by one and |
| 3263 | * create an interface heirarchy for each valid interface. |
| 3264 | */ |
| 3265 | for (br_if = 0, valid_if = 0; br_if < mc_max_dst; br_if++) { |
| 3266 | mc_dst_if_index = (int *)ecm_db_multicast_if_num_get_at_index(mc_dst_if_index_base, br_if); |
| 3267 | mc_br_slave_dev = dev_get_by_index(&init_net, *mc_dst_if_index); |
| 3268 | if (!mc_br_slave_dev) { |
| 3269 | |
| 3270 | /* |
| 3271 | * If already constructed any interface heirarchies before hitting |
| 3272 | * this error condition then Deref all interface heirarchies. |
| 3273 | */ |
| 3274 | if (valid_if > 0) { |
| 3275 | int i; |
| 3276 | for (i = 0; i < valid_if; i++) { |
| 3277 | ifaces = ecm_db_multicast_if_heirarchy_get(interfaces, i); |
| 3278 | ecm_db_multicast_copy_if_heirarchy(to_list_single, ifaces); |
| 3279 | ecm_db_connection_interfaces_deref(to_list_single, interface_first_base[i]); |
| 3280 | } |
| 3281 | } |
| 3282 | |
| 3283 | /* |
| 3284 | * If valid netdev not found, Return 0 |
| 3285 | */ |
| 3286 | return 0; |
| 3287 | } |
| 3288 | |
| 3289 | if (valid_if > ECM_DB_MULTICAST_IF_MAX) { |
| 3290 | int i; |
| 3291 | |
| 3292 | /* |
| 3293 | * If already constructed any interface heirarchies before hitting |
| 3294 | * this error condition then Deref all interface heirarchies. |
| 3295 | */ |
| 3296 | for (i = 0; i < valid_if; i++) { |
| 3297 | ifaces = ecm_db_multicast_if_heirarchy_get(interfaces, i); |
| 3298 | ecm_db_multicast_copy_if_heirarchy(to_list_single, ifaces); |
| 3299 | ecm_db_connection_interfaces_deref(to_list_single, interface_first_base[i]); |
| 3300 | } |
| 3301 | |
| 3302 | dev_put(mc_br_slave_dev); |
| 3303 | return 0; |
| 3304 | } |
| 3305 | |
| 3306 | ifaces = ecm_db_multicast_if_heirarchy_get(interfaces, valid_if); |
| 3307 | |
| 3308 | /* |
| 3309 | * Construct a single interface heirarchy of a multicast dev. |
| 3310 | */ |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 3311 | ii_cnt = ecm_interface_multicast_heirarchy_construct_single(feci, packet_src_addr, packet_dest_addr, ifaces, dest_dev, mc_br_slave_dev, src_node_addr, false, layer4hdr, skb); |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 3312 | if (ii_cnt == ECM_DB_IFACE_HEIRARCHY_MAX) { |
| 3313 | |
| 3314 | /* |
| 3315 | * If already constructed any interface heirarchies before hitting |
| 3316 | * this error condition then Deref all interface heirarchies. |
| 3317 | */ |
| 3318 | if (valid_if > 0) { |
| 3319 | int i; |
| 3320 | for (i = 0; i < valid_if; i++) { |
| 3321 | ifaces = ecm_db_multicast_if_heirarchy_get(interfaces, i); |
| 3322 | ecm_db_multicast_copy_if_heirarchy(to_list_single, ifaces); |
| 3323 | ecm_db_connection_interfaces_deref(to_list_single, interface_first_base[i]); |
| 3324 | } |
| 3325 | } |
| 3326 | |
| 3327 | dev_put(mc_br_slave_dev); |
| 3328 | return 0; |
| 3329 | } |
| 3330 | |
| 3331 | interface_first = ecm_db_multicast_if_first_get_at_index(interface_first_base, valid_if); |
| 3332 | *interface_first = ii_cnt; |
| 3333 | total_ii_cnt += ii_cnt; |
| 3334 | valid_if++; |
| 3335 | dev_put(mc_br_slave_dev); |
| 3336 | } |
| 3337 | |
Shyam Sunder | 280b34a | 2016-06-22 19:30:22 +0530 | [diff] [blame] | 3338 | return valid_if; |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 3339 | } |
| 3340 | EXPORT_SYMBOL(ecm_interface_multicast_heirarchy_construct_bridged); |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 3341 | |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 3342 | /* |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3343 | * ecm_interface_multicast_get_next_node_mac_address() |
| 3344 | * Get the MAC address of the next node for multicast flows |
| 3345 | * |
| 3346 | * TODO: This function will be removed when the multicast flow code |
| 3347 | * is fixed to use the new interface hierarchy construction model. |
| 3348 | * |
Murat Sezgin | 3aea6c9 | 2015-11-13 13:14:12 -0800 | [diff] [blame] | 3349 | */ |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3350 | static bool ecm_interface_multicast_get_next_node_mac_address( |
Murat Sezgin | 3aea6c9 | 2015-11-13 13:14:12 -0800 | [diff] [blame] | 3351 | ip_addr_t dest_addr, struct net_device *dest_dev, int ip_version, |
| 3352 | uint8_t *mac_addr) |
| 3353 | { |
| 3354 | bool on_link; |
| 3355 | ip_addr_t gw_addr = ECM_IP_ADDR_NULL; |
| 3356 | |
| 3357 | if (!ecm_interface_mac_addr_get(dest_addr, mac_addr, &on_link, gw_addr)) { |
| 3358 | if (ip_version == 4) { |
| 3359 | DEBUG_WARN("Unable to obtain MAC address for " ECM_IP_ADDR_DOT_FMT "\n", |
| 3360 | ECM_IP_ADDR_TO_DOT(dest_addr)); |
| 3361 | ecm_interface_send_arp_request(dest_dev, dest_addr, on_link, gw_addr); |
| 3362 | } |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3363 | #ifdef ECM_IPV6_ENABLE |
Murat Sezgin | 3aea6c9 | 2015-11-13 13:14:12 -0800 | [diff] [blame] | 3364 | if (ip_version == 6) { |
| 3365 | DEBUG_WARN("Unable to obtain MAC address for " ECM_IP_ADDR_OCTAL_FMT "\n", |
| 3366 | ECM_IP_ADDR_TO_OCTAL(dest_addr)); |
| 3367 | ecm_interface_send_neighbour_solicitation(dest_dev, dest_addr); |
| 3368 | } |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3369 | #endif |
| 3370 | return false; |
| 3371 | } |
Murat Sezgin | 3aea6c9 | 2015-11-13 13:14:12 -0800 | [diff] [blame] | 3372 | |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3373 | return true; |
| 3374 | } |
Murat Sezgin | 8f70b31 | 2016-02-02 23:33:10 -0800 | [diff] [blame] | 3375 | #endif |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3376 | |
| 3377 | /* |
| 3378 | * ecm_interface_get_next_node_mac_address() |
| 3379 | * Get the MAC address of the next node |
| 3380 | */ |
Suman Ghosh | 37af264 | 2018-03-22 13:05:33 +0530 | [diff] [blame] | 3381 | static bool ecm_interface_get_next_node_mac_address(ip_addr_t dest_addr, |
| 3382 | struct net_device *dest_dev, |
| 3383 | int ip_version, uint8_t *mac_addr) |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3384 | { |
Suman Ghosh | 37af264 | 2018-03-22 13:05:33 +0530 | [diff] [blame] | 3385 | ip_addr_t gw_addr = ECM_IP_ADDR_NULL; |
| 3386 | bool on_link = true; |
Murat Sezgin | 00627c1 | 2016-02-05 16:53:21 -0800 | [diff] [blame] | 3387 | |
Suman Ghosh | 37af264 | 2018-03-22 13:05:33 +0530 | [diff] [blame] | 3388 | if (ecm_interface_mac_addr_get_no_route(dest_dev, dest_addr, mac_addr)) { |
| 3389 | return true; |
Murat Sezgin | 3aea6c9 | 2015-11-13 13:14:12 -0800 | [diff] [blame] | 3390 | } |
| 3391 | |
Suman Ghosh | 37af264 | 2018-03-22 13:05:33 +0530 | [diff] [blame] | 3392 | /* |
| 3393 | * MAC address look up failed. The host IP address may not be in the |
| 3394 | * neighbour table. So, let's send an ARP or neighbour solicitation |
| 3395 | * request to this host IP address, so in the subsequent lookups it can be |
| 3396 | * found. |
| 3397 | * |
| 3398 | * If we have a gateway address, try one more time with that address. |
| 3399 | * If it fails, send the request with the current dest_addr or |
| 3400 | * found gateway address. |
| 3401 | */ |
| 3402 | if (ecm_interface_find_gateway(dest_addr, gw_addr)) { |
| 3403 | on_link = false; |
| 3404 | if (ecm_interface_mac_addr_get_no_route(dest_dev, gw_addr, mac_addr)) { |
| 3405 | DEBUG_TRACE("Found the mac address for the gateway\n"); |
| 3406 | return true; |
| 3407 | } |
| 3408 | } |
| 3409 | |
| 3410 | if (ip_version == 4) { |
| 3411 | DEBUG_WARN("Unable to obtain MAC address for " ECM_IP_ADDR_DOT_FMT " send ARP request\n", |
| 3412 | ECM_IP_ADDR_TO_DOT(dest_addr)); |
| 3413 | ecm_interface_send_arp_request(dest_dev, dest_addr, on_link, gw_addr); |
| 3414 | } |
| 3415 | |
| 3416 | #ifdef ECM_IPV6_ENABLE |
| 3417 | if (ip_version == 6) { |
| 3418 | DEBUG_WARN("Unable to obtain MAC address for " ECM_IP_ADDR_OCTAL_FMT " send solicitation request\n", |
| 3419 | ECM_IP_ADDR_TO_OCTAL(dest_addr)); |
| 3420 | ecm_interface_send_neighbour_solicitation(dest_dev, dest_addr); |
| 3421 | } |
| 3422 | #endif |
| 3423 | |
| 3424 | return false; |
Murat Sezgin | 3aea6c9 | 2015-11-13 13:14:12 -0800 | [diff] [blame] | 3425 | } |
| 3426 | |
| 3427 | /* |
| 3428 | * ecm_interface_should_update_egress_device_bridged() |
| 3429 | * Determine if the egress port should be re-evaluated in the bridged case |
| 3430 | * |
| 3431 | * This will be done if: |
| 3432 | * - The egress port is the one provided from the front-end |
| 3433 | * - The egress port is not a bridge, but is a slave of the bridge |
| 3434 | * - Not routed |
| 3435 | * |
| 3436 | * If these conditions hold, this function will hold a reference to the bridge |
| 3437 | * port and return it to the caller. Otherwise no reference will be held and |
| 3438 | * it will return NULL. |
| 3439 | */ |
| 3440 | static struct net_device *ecm_interface_should_update_egress_device_bridged( |
| 3441 | struct net_device *given_dest_dev, struct net_device *dest_dev, |
| 3442 | bool is_routed) |
| 3443 | { |
| 3444 | struct net_device *bridge; |
| 3445 | |
| 3446 | /* |
| 3447 | * Determine if we should attempt to fetch the bridge device |
| 3448 | */ |
| 3449 | if (!given_dest_dev || is_routed || (dest_dev != given_dest_dev) || |
| 3450 | ecm_front_end_is_bridge_device(given_dest_dev)) |
| 3451 | return NULL; |
| 3452 | |
| 3453 | bridge = ecm_interface_get_and_hold_dev_master(given_dest_dev); |
| 3454 | |
| 3455 | if (!bridge) |
| 3456 | return NULL; |
| 3457 | |
Murat Sezgin | 3aea6c9 | 2015-11-13 13:14:12 -0800 | [diff] [blame] | 3458 | if (!ecm_front_end_is_bridge_device(bridge)) { |
| 3459 | /* |
| 3460 | * Master is not a bridge - free the reference and return |
| 3461 | */ |
| 3462 | dev_put(bridge); |
| 3463 | return NULL; |
| 3464 | } |
| 3465 | |
| 3466 | /* |
| 3467 | * Reference is held to bridge and must be freed by caller |
| 3468 | */ |
| 3469 | return bridge; |
| 3470 | } |
| 3471 | |
| 3472 | /* |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 3473 | * ecm_interface_heirarchy_construct() |
| 3474 | * Construct an interface heirarchy. |
| 3475 | * |
| 3476 | * Using the given addressing, locate the interface heirarchy used to emit packets to that destination. |
| 3477 | * This is the heirarchy of interfaces a packet would transit to emit from the device. |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 3478 | * |
| 3479 | * We will use the given src/dest devices when is_routed is false. |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3480 | * When is_routed is true we will use the construct and the other devices (which is the src device of the |
| 3481 | * construct device) whcih were obtained from the skb's route field and passed to this function.. |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 3482 | * |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 3483 | * For example, with this network arrangement: |
| 3484 | * |
| 3485 | * PPPoE--VLAN--BRIDGE--BRIDGE_PORT(LAG_MASTER)--LAG_SLAVE_0--10.22.33.11 |
| 3486 | * |
Gareth Williams | 43fc085 | 2014-05-26 19:10:00 +0100 | [diff] [blame] | 3487 | * Given the packet_dest_addr IP address 10.22.33.11 this will create an interface heirarchy (in interracfes[]) of: |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 3488 | * LAG_SLAVE_0 @ [ECM_DB_IFACE_HEIRARCHY_MAX - 5] |
| 3489 | * LAG_MASTER @ [ECM_DB_IFACE_HEIRARCHY_MAX - 4] |
| 3490 | * BRIDGE @ [ECM_DB_IFACE_HEIRARCHY_MAX - 3] |
| 3491 | * VLAN @ [ECM_DB_IFACE_HEIRARCHY_MAX - 2] |
| 3492 | * PPPOE @ [ECM_DB_IFACE_HEIRARCHY_MAX - 1] |
| 3493 | * The value returned is (ECM_DB_IFACE_HEIRARCHY_MAX - 5) |
| 3494 | * |
| 3495 | * IMPORTANT: This function will return any known interfaces in the database, when interfaces do not exist in the database |
| 3496 | * they will be created and added automatically to the database. |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 3497 | */ |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 3498 | int32_t ecm_interface_heirarchy_construct(struct ecm_front_end_connection_instance *feci, |
| 3499 | struct ecm_db_iface_instance *interfaces[], |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3500 | struct net_device *const_if, struct net_device *other_if, |
Murat Sezgin | f92db49 | 2016-07-15 11:33:15 -0700 | [diff] [blame] | 3501 | ip_addr_t lookup_src_addr, |
| 3502 | ip_addr_t lookup_dest_addr, |
| 3503 | ip_addr_t real_dest_addr, |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3504 | int ip_version, int packet_protocol, |
| 3505 | struct net_device *given_dest_dev, |
| 3506 | bool is_routed, struct net_device *given_src_dev, |
| 3507 | uint8_t *dest_node_addr, uint8_t *src_node_addr, |
| 3508 | __be16 *layer4hdr, struct sk_buff *skb) |
| 3509 | { |
| 3510 | int protocol; |
| 3511 | ip_addr_t src_addr; |
| 3512 | ip_addr_t dest_addr; |
| 3513 | struct net_device *dest_dev; |
| 3514 | char *dest_dev_name; |
| 3515 | int32_t dest_dev_type; |
| 3516 | struct net_device *src_dev; |
| 3517 | char *src_dev_name; |
| 3518 | int32_t src_dev_type; |
| 3519 | int32_t current_interface_index; |
| 3520 | bool from_local_addr; |
| 3521 | bool next_dest_addr_valid; |
| 3522 | bool next_dest_node_addr_valid = false; |
| 3523 | ip_addr_t next_dest_addr; |
| 3524 | uint8_t next_dest_node_addr[ETH_ALEN] = {0}; |
Murat Sezgin | 70c44cd | 2016-03-02 11:32:10 -0800 | [diff] [blame] | 3525 | struct net_device *bridge; |
Suman Ghosh | 9bb0abb | 2018-03-19 01:08:54 +0530 | [diff] [blame] | 3526 | struct net_device *top_dev = NULL; |
Murat Sezgin | 545cf7d | 2016-03-04 09:48:21 -0800 | [diff] [blame] | 3527 | uint32_t serial = ecm_db_connection_serial_get(feci->ci); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3528 | |
| 3529 | /* |
| 3530 | * Get a big endian of the IPv4 address we have been given as our starting point. |
| 3531 | */ |
| 3532 | protocol = packet_protocol; |
Murat Sezgin | f92db49 | 2016-07-15 11:33:15 -0700 | [diff] [blame] | 3533 | ECM_IP_ADDR_COPY(src_addr, lookup_src_addr); |
| 3534 | ECM_IP_ADDR_COPY(dest_addr, lookup_dest_addr); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3535 | |
| 3536 | if (ip_version == 4) { |
Murat Sezgin | 545cf7d | 2016-03-04 09:48:21 -0800 | [diff] [blame] | 3537 | DEBUG_TRACE("Construct interface heirarchy for from src_addr: " ECM_IP_ADDR_DOT_FMT " to dest_addr: " ECM_IP_ADDR_DOT_FMT ", protocol: %d (serial %u)\n", |
| 3538 | ECM_IP_ADDR_TO_DOT(src_addr), ECM_IP_ADDR_TO_DOT(dest_addr), protocol, |
| 3539 | serial); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3540 | #ifdef ECM_IPV6_ENABLE |
| 3541 | } else if (ip_version == 6) { |
Murat Sezgin | 545cf7d | 2016-03-04 09:48:21 -0800 | [diff] [blame] | 3542 | DEBUG_TRACE("Construct interface heirarchy for from src_addr: " ECM_IP_ADDR_OCTAL_FMT " to dest_addr: " ECM_IP_ADDR_OCTAL_FMT ", protocol: %d (serial %u)\n", |
| 3543 | ECM_IP_ADDR_TO_OCTAL(src_addr), ECM_IP_ADDR_TO_OCTAL(dest_addr), protocol, |
| 3544 | serial); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3545 | #endif |
| 3546 | } else { |
| 3547 | DEBUG_WARN("Wrong IP protocol: %d\n", ip_version); |
| 3548 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 3549 | } |
| 3550 | |
| 3551 | /* |
| 3552 | * Get device to reach the given destination address. |
| 3553 | * If the heirarchy is for a routed connection we must use the devices obtained from the skb's route information.. |
| 3554 | * If the heirarchy is NOT for a routed connection we try the given_dest_dev. |
| 3555 | */ |
| 3556 | from_local_addr = false; |
| 3557 | if (!is_routed) { |
| 3558 | dest_dev = given_dest_dev; |
| 3559 | dev_hold(dest_dev); |
| 3560 | } else { |
| 3561 | dest_dev = ecm_interface_dev_find_by_local_addr(dest_addr); |
| 3562 | if (dest_dev) { |
| 3563 | from_local_addr = true; |
| 3564 | } else { |
| 3565 | dest_dev = const_if; |
| 3566 | dev_hold(dest_dev); |
| 3567 | } |
| 3568 | } |
| 3569 | |
| 3570 | /* |
| 3571 | * If the address is a local address and protocol is an IP tunnel |
| 3572 | * then this connection is a tunnel endpoint made to this device. |
| 3573 | * In which case we circumvent all proper procedure and just hack the devices to make stuff work. |
| 3574 | * |
| 3575 | * TODO THIS MUST BE FIXED - WE MUST USE THE INTERFACE HIERARCHY FOR ITS INTENDED PURPOSE TO |
| 3576 | * PARSE THE DEVICES AND WORK OUT THE PROPER INTERFACES INVOLVED. |
| 3577 | * E.G. IF WE TRIED TO RUN A TUNNEL OVER A VLAN OR QINQ THIS WILL BREAK AS WE DON'T DISCOVER THAT HIERARCHY |
| 3578 | */ |
| 3579 | if (dest_dev && from_local_addr) { |
| 3580 | if (((ip_version == 4) && (protocol == IPPROTO_IPV6)) || |
Murat Sezgin | 31effef | 2017-11-13 15:09:34 -0800 | [diff] [blame] | 3581 | ((ip_version == 6) && (protocol == IPPROTO_IPIP)) |
Suman Ghosh | 9e4245f | 2018-04-11 01:11:41 +0530 | [diff] [blame] | 3582 | #if defined(ECM_INTERFACE_GRE_TAP_ENABLE) || defined(ECM_INTERFACE_GRE_TUN_ENABLE) |
| 3583 | || ((protocol == IPPROTO_GRE))) { |
Murat Sezgin | 31effef | 2017-11-13 15:09:34 -0800 | [diff] [blame] | 3584 | #else |
Suman Ghosh | 9e4245f | 2018-04-11 01:11:41 +0530 | [diff] [blame] | 3585 | ) { |
Murat Sezgin | 31effef | 2017-11-13 15:09:34 -0800 | [diff] [blame] | 3586 | #endif |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3587 | dev_put(dest_dev); |
| 3588 | dest_dev = given_dest_dev; |
| 3589 | if (dest_dev) { |
| 3590 | dev_hold(dest_dev); |
| 3591 | if (ip_version == 4) { |
Suman Ghosh | 9e4245f | 2018-04-11 01:11:41 +0530 | [diff] [blame] | 3592 | DEBUG_TRACE("HACK: %s tunnel packet with dest_addr: " ECM_IP_ADDR_DOT_FMT " uses dev: %p(%s)\n", "IPV4", ECM_IP_ADDR_TO_DOT(dest_addr), dest_dev, dest_dev->name); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3593 | } else { |
Suman Ghosh | 9e4245f | 2018-04-11 01:11:41 +0530 | [diff] [blame] | 3594 | DEBUG_TRACE("HACK: %s tunnel packet with dest_addr: " ECM_IP_ADDR_OCTAL_FMT " uses dev: %p(%s)\n", "IPV6", ECM_IP_ADDR_TO_OCTAL(dest_addr), dest_dev, dest_dev->name); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3595 | } |
| 3596 | } |
| 3597 | } |
| 3598 | } |
| 3599 | |
| 3600 | #ifdef ECM_INTERFACE_L2TPV2_ENABLE |
ratheesh kannoth | f4801a0 | 2016-12-09 22:46:39 +0530 | [diff] [blame] | 3601 | |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3602 | /* |
| 3603 | * if the address is a local address and indev=l2tp. |
| 3604 | */ |
ratheesh kannoth | f4801a0 | 2016-12-09 22:46:39 +0530 | [diff] [blame] | 3605 | if ((given_src_dev->type == ARPHRD_PPP) && (given_src_dev->priv_flags & IFF_PPP_L2TPV2) && ppp_is_xmit_locked(given_src_dev)) { |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3606 | dev_put(dest_dev); |
| 3607 | dest_dev = given_dest_dev; |
| 3608 | if (dest_dev) { |
| 3609 | dev_hold(dest_dev); |
| 3610 | DEBUG_TRACE("l2tp packet tunnel packet with dest_addr: " ECM_IP_ADDR_OCTAL_FMT " uses dev: %p(%s)\n", ECM_IP_ADDR_TO_OCTAL(dest_addr), dest_dev, dest_dev->name); |
| 3611 | } |
| 3612 | } |
| 3613 | #endif |
| 3614 | |
| 3615 | #ifdef ECM_INTERFACE_PPTP_ENABLE |
| 3616 | /* |
| 3617 | * if the address is a local address and indev=PPTP. |
| 3618 | */ |
Suman Ghosh | 4273a8e | 2018-05-03 16:21:14 +0530 | [diff] [blame] | 3619 | if (protocol == IPPROTO_GRE && given_dest_dev && (given_dest_dev->priv_flags & IFF_PPP_PPTP)){ |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3620 | dev_put(dest_dev); |
| 3621 | dest_dev = given_dest_dev; |
| 3622 | if (dest_dev) { |
| 3623 | dev_hold(dest_dev); |
| 3624 | DEBUG_TRACE("PPTP packet tunnel packet with dest_addr: " ECM_IP_ADDR_OCTAL_FMT " uses dev: %p(%s)\n", ECM_IP_ADDR_TO_OCTAL(dest_addr), dest_dev, dest_dev->name); |
| 3625 | } |
| 3626 | } |
| 3627 | #endif |
| 3628 | |
| 3629 | if (!dest_dev) { |
| 3630 | DEBUG_WARN("dest_addr: " ECM_IP_ADDR_OCTAL_FMT " - cannot locate device\n", ECM_IP_ADDR_TO_OCTAL(dest_addr)); |
| 3631 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 3632 | } |
| 3633 | dest_dev_name = dest_dev->name; |
| 3634 | dest_dev_type = dest_dev->type; |
| 3635 | |
| 3636 | /* |
| 3637 | * Get device to reach the given source address. |
| 3638 | * If the heirarchy is for a routed connection we must use the devices obtained from the skb's route information.. |
| 3639 | * If the heirarchy is NOT for a routed connection we try the given_src_dev. |
| 3640 | */ |
| 3641 | from_local_addr = false; |
| 3642 | if (!is_routed) { |
| 3643 | src_dev = given_src_dev; |
| 3644 | dev_hold(src_dev); |
| 3645 | } else { |
| 3646 | src_dev = ecm_interface_dev_find_by_local_addr(src_addr); |
| 3647 | if (src_dev) { |
| 3648 | from_local_addr = true; |
| 3649 | } else { |
| 3650 | src_dev = other_if; |
| 3651 | dev_hold(src_dev); |
| 3652 | } |
| 3653 | } |
| 3654 | |
| 3655 | /* |
| 3656 | * If the address is a local address and protocol is an IP tunnel |
| 3657 | * then this connection is a tunnel endpoint made to this device. |
| 3658 | * In which case we circumvent all proper procedure and just hack the devices to make stuff work. |
| 3659 | * |
| 3660 | * TODO THIS MUST BE FIXED - WE MUST USE THE INTERFACE HIERARCHY FOR ITS INTENDED PURPOSE TO |
| 3661 | * PARSE THE DEVICES AND WORK OUT THE PROPER INTERFACES INVOLVED. |
| 3662 | * E.G. IF WE TRIED TO RUN A TUNNEL OVER A VLAN OR QINQ THIS WILL BREAK AS WE DON'T DISCOVER THAT HIERARCHY |
| 3663 | */ |
| 3664 | if (src_dev && from_local_addr) { |
| 3665 | if (((ip_version == 4) && (protocol == IPPROTO_IPV6)) || |
Murat Sezgin | 31effef | 2017-11-13 15:09:34 -0800 | [diff] [blame] | 3666 | ((ip_version == 6) && (protocol == IPPROTO_IPIP)) |
Suman Ghosh | 9e4245f | 2018-04-11 01:11:41 +0530 | [diff] [blame] | 3667 | #if defined(ECM_INTERFACE_GRE_TAP_ENABLE) || defined(ECM_INTERFACE_GRE_TUN_ENABLE) |
| 3668 | || ((protocol == IPPROTO_GRE))) { |
Murat Sezgin | 31effef | 2017-11-13 15:09:34 -0800 | [diff] [blame] | 3669 | #else |
Suman Ghosh | 9e4245f | 2018-04-11 01:11:41 +0530 | [diff] [blame] | 3670 | ) { |
Murat Sezgin | 31effef | 2017-11-13 15:09:34 -0800 | [diff] [blame] | 3671 | #endif |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3672 | dev_put(src_dev); |
| 3673 | src_dev = given_src_dev; |
| 3674 | if (src_dev) { |
| 3675 | dev_hold(src_dev); |
| 3676 | if (ip_version == 4) { |
Suman Ghosh | 9e4245f | 2018-04-11 01:11:41 +0530 | [diff] [blame] | 3677 | DEBUG_TRACE("HACK: %s tunnel packet with src_addr: " ECM_IP_ADDR_DOT_FMT " uses dev: %p(%s)\n", "IPV4", ECM_IP_ADDR_TO_DOT(src_addr), src_dev, src_dev->name); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3678 | } else { |
Suman Ghosh | 9e4245f | 2018-04-11 01:11:41 +0530 | [diff] [blame] | 3679 | DEBUG_TRACE("HACK: %s tunnel packet with src_addr: " ECM_IP_ADDR_OCTAL_FMT " uses dev: %p(%s)\n", "IPV6", ECM_IP_ADDR_TO_OCTAL(src_addr), src_dev, src_dev->name); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3680 | } |
| 3681 | } |
| 3682 | } |
| 3683 | } |
| 3684 | |
| 3685 | if (!src_dev) { |
| 3686 | DEBUG_WARN("src_addr: " ECM_IP_ADDR_OCTAL_FMT " - cannot locate device\n", ECM_IP_ADDR_TO_OCTAL(src_addr)); |
| 3687 | dev_put(dest_dev); |
| 3688 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 3689 | } |
| 3690 | src_dev_name = src_dev->name; |
| 3691 | src_dev_type = src_dev->type; |
| 3692 | |
| 3693 | /* |
| 3694 | * Check if source and dest dev are same. |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3695 | */ |
| 3696 | if (src_dev == dest_dev) { |
ratheesh kannoth | a6d2595 | 2016-04-11 12:23:26 +0530 | [diff] [blame] | 3697 | bool skip = false; |
| 3698 | |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3699 | DEBUG_TRACE("Protocol is :%d source dev and dest dev are same\n", protocol); |
ratheesh kannoth | a6d2595 | 2016-04-11 12:23:26 +0530 | [diff] [blame] | 3700 | |
| 3701 | switch (ip_version) { |
| 3702 | case 4: |
| 3703 | if ((protocol == IPPROTO_IPV6) || (protocol == IPPROTO_ESP)) { |
| 3704 | skip = true; |
| 3705 | break; |
| 3706 | } |
| 3707 | |
| 3708 | if ((protocol == IPPROTO_UDP) && (udp_hdr(skb)->dest == htons(4500))) { |
| 3709 | skip = true; |
| 3710 | break; |
| 3711 | } |
| 3712 | |
| 3713 | break; |
| 3714 | |
| 3715 | case 6: |
ratheesh kannoth | a6d2595 | 2016-04-11 12:23:26 +0530 | [diff] [blame] | 3716 | if ((protocol == IPPROTO_IPIP) || (protocol == IPPROTO_ESP)) { |
| 3717 | skip = true; |
| 3718 | break; |
| 3719 | } |
| 3720 | |
| 3721 | break; |
| 3722 | |
| 3723 | default: |
| 3724 | DEBUG_WARN("IP version = %d, Protocol = %d: Corrupted packet entered ecm\n", ip_version, protocol); |
| 3725 | skip = true; |
| 3726 | break; |
| 3727 | } |
| 3728 | |
| 3729 | if (skip) { |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3730 | /* |
| 3731 | * This happens from the input hook |
| 3732 | * We do not want to create a connection entry for this |
| 3733 | * TODO YES WE DO. |
| 3734 | * TODO THIS CONCERNS ME AS THIS SHOULD BE CAUGHT MUCH |
| 3735 | * EARLIER IN THE FRONT END IF POSSIBLE TO AVOID PERFORMANCE PENALTIES. |
| 3736 | * WE HAVE DONE A TREMENDOUS AMOUT OF WORK TO GET TO THIS POINT. |
| 3737 | * WE WILL ABORT HERE AND THIS WILL BE REPEATED FOR EVERY PACKET. |
| 3738 | * IN KEEPING WITH THE ECM DESIGN IT IS BETTER TO CREATE A CONNECTION AND RECORD IN THE HIERARCHY |
| 3739 | * ENOUGH INFORMATION TO ENSURE THAT ACCELERATION IS NOT BROKEN / DOES NOT OCCUR AT ALL. |
| 3740 | * THAT WAY WE DO A HEAVYWEIGHT ESTABLISHING OF A CONNECTION ONCE AND NEVER AGAIN... |
| 3741 | */ |
| 3742 | dev_put(src_dev); |
| 3743 | dev_put(dest_dev); |
| 3744 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 3745 | } |
Murat Sezgin | 70c44cd | 2016-03-02 11:32:10 -0800 | [diff] [blame] | 3746 | } |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3747 | |
Murat Sezgin | 70c44cd | 2016-03-02 11:32:10 -0800 | [diff] [blame] | 3748 | bridge = ecm_interface_should_update_egress_device_bridged( |
| 3749 | given_dest_dev, dest_dev, is_routed); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3750 | |
Murat Sezgin | 70c44cd | 2016-03-02 11:32:10 -0800 | [diff] [blame] | 3751 | if (bridge) { |
Murat Sezgin | 70c44cd | 2016-03-02 11:32:10 -0800 | [diff] [blame] | 3752 | struct net_device *new_dest_dev; |
Murat Sezgin | b9bd5e0 | 2016-08-05 14:55:07 -0700 | [diff] [blame] | 3753 | new_dest_dev = br_port_dev_get(bridge, dest_node_addr, skb, serial); |
| 3754 | if (new_dest_dev) { |
| 3755 | dev_put(dest_dev); |
| 3756 | if (new_dest_dev != given_dest_dev) { |
| 3757 | DEBUG_INFO("Adjusted port for %pM is %s (given was %s)\n", |
| 3758 | dest_node_addr, new_dest_dev->name, |
| 3759 | given_dest_dev->name); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3760 | |
Murat Sezgin | b9bd5e0 | 2016-08-05 14:55:07 -0700 | [diff] [blame] | 3761 | dest_dev = new_dest_dev; |
| 3762 | dest_dev_name = dest_dev->name; |
| 3763 | dest_dev_type = dest_dev->type; |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3764 | } |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3765 | } |
Murat Sezgin | 70c44cd | 2016-03-02 11:32:10 -0800 | [diff] [blame] | 3766 | dev_put(bridge); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3767 | } |
| 3768 | |
| 3769 | next_dest_addr_valid = true; |
| 3770 | ECM_IP_ADDR_COPY(next_dest_addr, dest_addr); |
| 3771 | |
| 3772 | /* |
| 3773 | * Iterate until we are done or get to the max number of interfaces we can record. |
| 3774 | * NOTE: current_interface_index tracks the position of the first interface position in interfaces[] |
| 3775 | * because we add from the end first_interface grows downwards. |
| 3776 | */ |
| 3777 | current_interface_index = ECM_DB_IFACE_HEIRARCHY_MAX; |
| 3778 | while (current_interface_index > 0) { |
| 3779 | struct ecm_db_iface_instance *ii; |
| 3780 | struct net_device *next_dev; |
| 3781 | /* |
| 3782 | * Get the ecm db interface instance for the device at hand |
| 3783 | */ |
| 3784 | ii = ecm_interface_establish_and_ref(feci, dest_dev, skb); |
| 3785 | |
| 3786 | /* |
| 3787 | * If the interface could not be established then we abort |
| 3788 | */ |
| 3789 | if (!ii) { |
| 3790 | DEBUG_WARN("Failed to establish interface: %p, name: %s\n", dest_dev, dest_dev_name); |
| 3791 | dev_put(src_dev); |
| 3792 | dev_put(dest_dev); |
| 3793 | |
| 3794 | /* |
| 3795 | * Release the interfaces heirarchy we constructed to this point. |
| 3796 | */ |
| 3797 | ecm_db_connection_interfaces_deref(interfaces, current_interface_index); |
| 3798 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 3799 | } |
| 3800 | |
| 3801 | /* |
| 3802 | * Record the interface instance into the interfaces[] |
| 3803 | */ |
| 3804 | current_interface_index--; |
| 3805 | interfaces[current_interface_index] = ii; |
| 3806 | |
| 3807 | /* |
| 3808 | * Now we have to figure out what the next device will be (in the transmission path) the skb |
| 3809 | * will use to emit to the destination address. |
| 3810 | */ |
| 3811 | do { |
| 3812 | #ifdef ECM_INTERFACE_PPP_ENABLE |
| 3813 | int channel_count; |
| 3814 | struct ppp_channel *ppp_chan[1]; |
| 3815 | int channel_protocol; |
| 3816 | #ifdef ECM_INTERFACE_PPPOE_ENABLE |
| 3817 | struct pppoe_opt addressing; |
| 3818 | #endif |
| 3819 | #endif |
| 3820 | |
| 3821 | DEBUG_TRACE("Net device: %p is type: %d, name: %s\n", dest_dev, dest_dev_type, dest_dev_name); |
| 3822 | next_dev = NULL; |
| 3823 | |
| 3824 | if (dest_dev_type == ARPHRD_ETHER) { |
| 3825 | /* |
| 3826 | * Ethernet - but what sub type? |
| 3827 | */ |
| 3828 | |
| 3829 | #ifdef ECM_INTERFACE_VLAN_ENABLE |
| 3830 | /* |
| 3831 | * VLAN? |
| 3832 | */ |
| 3833 | if (is_vlan_dev(dest_dev)) { |
| 3834 | /* |
| 3835 | * VLAN master |
| 3836 | * No locking needed here, ASSUMPTION is that real_dev is held for as long as we have dev. |
| 3837 | */ |
Shyam Sunder | 9db2085 | 2016-03-09 19:04:49 +0530 | [diff] [blame] | 3838 | next_dev = ecm_interface_vlan_real_dev(dest_dev); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3839 | dev_hold(next_dev); |
| 3840 | DEBUG_TRACE("Net device: %p is VLAN, slave dev: %p (%s)\n", |
| 3841 | dest_dev, next_dev, next_dev->name); |
Shyam Sunder | 2e9528b | 2016-07-05 14:45:55 +0530 | [diff] [blame] | 3842 | if (current_interface_index == (ECM_DB_IFACE_HEIRARCHY_MAX - 1)) { |
Suman Ghosh | 9bb0abb | 2018-03-19 01:08:54 +0530 | [diff] [blame] | 3843 | top_dev = dest_dev; |
Shyam Sunder | 2e9528b | 2016-07-05 14:45:55 +0530 | [diff] [blame] | 3844 | } |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3845 | break; |
| 3846 | } |
| 3847 | #endif |
| 3848 | |
| 3849 | /* |
| 3850 | * BRIDGE? |
| 3851 | */ |
| 3852 | if (ecm_front_end_is_bridge_device(dest_dev)) { |
| 3853 | /* |
| 3854 | * Bridge |
| 3855 | * Figure out which port device the skb will go to using the dest_addr. |
| 3856 | */ |
| 3857 | uint8_t mac_addr[ETH_ALEN]; |
| 3858 | |
| 3859 | if (next_dest_node_addr_valid) { |
| 3860 | memcpy(mac_addr, next_dest_node_addr, ETH_ALEN); |
| 3861 | } else if (!next_dest_addr_valid) { |
| 3862 | dev_put(src_dev); |
| 3863 | dev_put(dest_dev); |
| 3864 | |
| 3865 | /* |
| 3866 | * Release the interfaces heirarchy we constructed to this point. |
| 3867 | */ |
| 3868 | ecm_db_connection_interfaces_deref(interfaces, current_interface_index); |
| 3869 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 3870 | } else { |
| 3871 | if (!ecm_interface_get_next_node_mac_address(dest_addr, dest_dev, ip_version, mac_addr)) { |
| 3872 | dev_put(src_dev); |
| 3873 | dev_put(dest_dev); |
| 3874 | |
| 3875 | /* |
| 3876 | * Release the interfaces heirarchy we constructed to this point. |
| 3877 | */ |
| 3878 | ecm_db_connection_interfaces_deref(interfaces, current_interface_index); |
| 3879 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 3880 | } |
| 3881 | } |
| 3882 | |
Murat Sezgin | 545cf7d | 2016-03-04 09:48:21 -0800 | [diff] [blame] | 3883 | next_dev = br_port_dev_get(dest_dev, |
| 3884 | mac_addr, skb, serial); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3885 | |
| 3886 | if (!next_dev) { |
| 3887 | DEBUG_WARN("Unable to obtain output port for: %pM\n", mac_addr); |
| 3888 | dev_put(src_dev); |
| 3889 | dev_put(dest_dev); |
| 3890 | |
| 3891 | /* |
| 3892 | * Release the interfaces heirarchy we constructed to this point. |
| 3893 | */ |
| 3894 | ecm_db_connection_interfaces_deref(interfaces, current_interface_index); |
| 3895 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 3896 | } |
| 3897 | DEBUG_TRACE("Net device: %p is BRIDGE, next_dev: %p (%s)\n", dest_dev, next_dev, next_dev->name); |
Suman Ghosh | 9bb0abb | 2018-03-19 01:08:54 +0530 | [diff] [blame] | 3898 | if (current_interface_index == (ECM_DB_IFACE_HEIRARCHY_MAX - 1)) { |
| 3899 | top_dev = dest_dev; |
| 3900 | } |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3901 | break; |
| 3902 | } |
| 3903 | |
| 3904 | #ifdef ECM_INTERFACE_BOND_ENABLE |
| 3905 | /* |
| 3906 | * LAG? |
| 3907 | */ |
| 3908 | if (ecm_front_end_is_lag_master(dest_dev)) { |
| 3909 | /* |
| 3910 | * Link aggregation |
| 3911 | * Figure out whiich slave device of the link aggregation will be used to reach the destination. |
| 3912 | */ |
| 3913 | uint32_t src_addr_32 = 0; |
| 3914 | uint32_t dest_addr_32 = 0; |
| 3915 | struct in6_addr src_addr6; |
| 3916 | struct in6_addr dest_addr6; |
| 3917 | uint8_t src_mac_addr[ETH_ALEN]; |
| 3918 | uint8_t dest_mac_addr[ETH_ALEN]; |
| 3919 | |
| 3920 | memset(src_mac_addr, 0, ETH_ALEN); |
| 3921 | memset(dest_mac_addr, 0, ETH_ALEN); |
| 3922 | |
| 3923 | if (ip_version == 4) { |
| 3924 | ECM_IP_ADDR_TO_NIN4_ADDR(src_addr_32, src_addr); |
Murat Sezgin | f92db49 | 2016-07-15 11:33:15 -0700 | [diff] [blame] | 3925 | ECM_IP_ADDR_TO_NIN4_ADDR(dest_addr_32, real_dest_addr); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3926 | } |
| 3927 | |
| 3928 | if (!is_routed) { |
| 3929 | memcpy(src_mac_addr, src_node_addr, ETH_ALEN); |
| 3930 | memcpy(dest_mac_addr, dest_node_addr, ETH_ALEN); |
| 3931 | } else { |
Murat Sezgin | 7be87d2 | 2016-01-29 17:41:37 -0800 | [diff] [blame] | 3932 | struct net_device *master_dev; |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3933 | |
| 3934 | /* |
Murat Sezgin | 7be87d2 | 2016-01-29 17:41:37 -0800 | [diff] [blame] | 3935 | * Use appropriate source MAC address for routed packets and |
| 3936 | * find proper interface to find the destination mac address and |
| 3937 | * from which to issue ARP or neighbour solicitation packet. |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3938 | */ |
Murat Sezgin | 7be87d2 | 2016-01-29 17:41:37 -0800 | [diff] [blame] | 3939 | master_dev = ecm_interface_get_and_hold_dev_master(dest_dev); |
| 3940 | if (master_dev) { |
| 3941 | memcpy(src_mac_addr, master_dev->dev_addr, ETH_ALEN); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3942 | } else { |
Murat Sezgin | 7be87d2 | 2016-01-29 17:41:37 -0800 | [diff] [blame] | 3943 | master_dev = dest_dev; |
Suman Ghosh | 9bb0abb | 2018-03-19 01:08:54 +0530 | [diff] [blame] | 3944 | if (top_dev) { |
| 3945 | master_dev = top_dev; |
Shyam Sunder | 2e9528b | 2016-07-05 14:45:55 +0530 | [diff] [blame] | 3946 | } |
Suman Ghosh | 9bb0abb | 2018-03-19 01:08:54 +0530 | [diff] [blame] | 3947 | memcpy(src_mac_addr, master_dev->dev_addr, ETH_ALEN); |
Murat Sezgin | 7be87d2 | 2016-01-29 17:41:37 -0800 | [diff] [blame] | 3948 | dev_hold(master_dev); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3949 | } |
| 3950 | |
| 3951 | /* |
| 3952 | * Determine destination MAC address for this routed packet |
| 3953 | */ |
| 3954 | if (next_dest_node_addr_valid) { |
| 3955 | memcpy(dest_mac_addr, next_dest_node_addr, ETH_ALEN); |
| 3956 | } else if (!next_dest_addr_valid) { |
| 3957 | dev_put(src_dev); |
| 3958 | dev_put(dest_dev); |
Murat Sezgin | 7be87d2 | 2016-01-29 17:41:37 -0800 | [diff] [blame] | 3959 | dev_put(master_dev); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3960 | ecm_db_connection_interfaces_deref(interfaces, current_interface_index); |
| 3961 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 3962 | } else { |
Murat Sezgin | 7be87d2 | 2016-01-29 17:41:37 -0800 | [diff] [blame] | 3963 | if (!ecm_interface_mac_addr_get_no_route(master_dev, dest_addr, dest_mac_addr)) { |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3964 | ip_addr_t gw_addr = ECM_IP_ADDR_NULL; |
| 3965 | /* |
| 3966 | * Try one more time with gateway ip address if it exists. |
| 3967 | */ |
| 3968 | if (!ecm_interface_find_gateway(dest_addr, gw_addr)) { |
| 3969 | goto lag_fail; |
| 3970 | } |
| 3971 | |
| 3972 | if (ip_version == 4) { |
| 3973 | DEBUG_TRACE("Have a gw address " ECM_IP_ADDR_DOT_FMT "\n", ECM_IP_ADDR_TO_DOT(gw_addr)); |
| 3974 | } |
| 3975 | #ifdef ECM_IPV6_ENABLE |
| 3976 | |
| 3977 | if (ip_version == 6) { |
| 3978 | DEBUG_TRACE("Have a gw address " ECM_IP_ADDR_OCTAL_FMT "\n", ECM_IP_ADDR_TO_OCTAL(gw_addr)); |
| 3979 | } |
| 3980 | #endif |
Murat Sezgin | 7be87d2 | 2016-01-29 17:41:37 -0800 | [diff] [blame] | 3981 | if (ecm_interface_mac_addr_get_no_route(master_dev, gw_addr, dest_mac_addr)) { |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3982 | DEBUG_TRACE("Found the mac address for gateway\n"); |
Murat Sezgin | 7be87d2 | 2016-01-29 17:41:37 -0800 | [diff] [blame] | 3983 | dev_put(master_dev); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3984 | goto lag_success; |
| 3985 | } |
| 3986 | |
| 3987 | if (ip_version == 4) { |
Murat Sezgin | 7be87d2 | 2016-01-29 17:41:37 -0800 | [diff] [blame] | 3988 | ecm_interface_send_arp_request(master_dev, dest_addr, false, gw_addr); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3989 | |
| 3990 | DEBUG_WARN("Unable to obtain any MAC address for " ECM_IP_ADDR_DOT_FMT "\n", ECM_IP_ADDR_TO_DOT(dest_addr)); |
| 3991 | } |
| 3992 | #ifdef ECM_IPV6_ENABLE |
| 3993 | if (ip_version == 6) { |
Murat Sezgin | 7be87d2 | 2016-01-29 17:41:37 -0800 | [diff] [blame] | 3994 | ecm_interface_send_neighbour_solicitation(master_dev, dest_addr); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 3995 | |
| 3996 | DEBUG_WARN("Unable to obtain any MAC address for " ECM_IP_ADDR_OCTAL_FMT "\n", ECM_IP_ADDR_TO_OCTAL(dest_addr)); |
| 3997 | } |
| 3998 | #endif |
| 3999 | lag_fail: |
| 4000 | dev_put(src_dev); |
| 4001 | dev_put(dest_dev); |
Murat Sezgin | 7be87d2 | 2016-01-29 17:41:37 -0800 | [diff] [blame] | 4002 | dev_put(master_dev); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 4003 | |
| 4004 | ecm_db_connection_interfaces_deref(interfaces, current_interface_index); |
| 4005 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 4006 | } |
| 4007 | } |
Suman Ghosh | 11c6f9e | 2018-03-01 20:40:39 +0530 | [diff] [blame] | 4008 | dev_put(master_dev); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 4009 | } |
| 4010 | lag_success: |
| 4011 | if (ip_version == 4) { |
| 4012 | next_dev = bond_get_tx_dev(NULL, src_mac_addr, dest_mac_addr, |
| 4013 | &src_addr_32, &dest_addr_32, |
| 4014 | htons((uint16_t)ETH_P_IP), dest_dev, layer4hdr); |
| 4015 | } else if (ip_version == 6) { |
| 4016 | ECM_IP_ADDR_TO_NIN6_ADDR(src_addr6, src_addr); |
Murat Sezgin | f92db49 | 2016-07-15 11:33:15 -0700 | [diff] [blame] | 4017 | ECM_IP_ADDR_TO_NIN6_ADDR(dest_addr6, real_dest_addr); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 4018 | next_dev = bond_get_tx_dev(NULL, src_mac_addr, dest_mac_addr, |
| 4019 | src_addr6.s6_addr, dest_addr6.s6_addr, |
Shyam Sunder | e60540c | 2016-04-29 15:06:35 +0530 | [diff] [blame] | 4020 | htons((uint16_t)ETH_P_IPV6), dest_dev, layer4hdr); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 4021 | } |
| 4022 | |
| 4023 | if (next_dev && netif_carrier_ok(next_dev)) { |
| 4024 | dev_hold(next_dev); |
| 4025 | } else { |
| 4026 | DEBUG_WARN("Unable to obtain LAG output slave device\n"); |
| 4027 | dev_put(src_dev); |
| 4028 | dev_put(dest_dev); |
| 4029 | |
| 4030 | /* |
| 4031 | * Release the interfaces heirarchy we constructed to this point. |
| 4032 | */ |
| 4033 | ecm_db_connection_interfaces_deref(interfaces, current_interface_index); |
| 4034 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 4035 | } |
| 4036 | |
| 4037 | DEBUG_TRACE("Net device: %p is LAG, slave dev: %p (%s)\n", dest_dev, next_dev, next_dev->name); |
| 4038 | break; |
| 4039 | } |
| 4040 | #endif |
| 4041 | |
| 4042 | /* |
| 4043 | * ETHERNET! |
| 4044 | * Just plain ethernet it seems. |
| 4045 | */ |
| 4046 | DEBUG_TRACE("Net device: %p is ETHERNET\n", dest_dev); |
| 4047 | break; |
| 4048 | } |
| 4049 | |
Suman Ghosh | 9e4245f | 2018-04-11 01:11:41 +0530 | [diff] [blame] | 4050 | #ifdef ECM_INTERFACE_GRE_TUN_ENABLE |
| 4051 | /* |
| 4052 | * GRE Tunnel? |
| 4053 | */ |
| 4054 | if ((dest_dev_type == ARPHRD_IPGRE) || (dest_dev_type == ARPHRD_IP6GRE)) { |
| 4055 | DEBUG_TRACE("Net device: %p is GRE Tunnel type: %d\n", dest_dev, dest_dev_type); |
| 4056 | break; |
| 4057 | } |
| 4058 | #endif |
| 4059 | |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 4060 | /* |
| 4061 | * LOOPBACK? |
| 4062 | */ |
| 4063 | if (dest_dev_type == ARPHRD_LOOPBACK) { |
| 4064 | DEBUG_TRACE("Net device: %p is LOOPBACK type: %d\n", dest_dev, dest_dev_type); |
| 4065 | break; |
| 4066 | } |
| 4067 | |
| 4068 | /* |
| 4069 | * IPSEC? |
| 4070 | */ |
| 4071 | if (dest_dev_type == ECM_ARPHRD_IPSEC_TUNNEL_TYPE) { |
| 4072 | DEBUG_TRACE("Net device: %p is IPSec tunnel type: %d\n", dest_dev, dest_dev_type); |
| 4073 | /* TODO Figure out the next device the tunnel is using... */ |
| 4074 | break; |
| 4075 | } |
| 4076 | |
| 4077 | /* |
| 4078 | * SIT (6-in-4)? |
| 4079 | */ |
| 4080 | if (dest_dev_type == ARPHRD_SIT) { |
| 4081 | DEBUG_TRACE("Net device: %p is SIT (6-in-4) type: %d\n", dest_dev, dest_dev_type); |
| 4082 | /* TODO Figure out the next device the tunnel is using... */ |
| 4083 | break; |
| 4084 | } |
| 4085 | |
| 4086 | /* |
| 4087 | * IPIP6 Tunnel? |
| 4088 | */ |
| 4089 | if (dest_dev_type == ARPHRD_TUNNEL6) { |
| 4090 | DEBUG_TRACE("Net device: %p is TUNIPIP6 type: %d\n", dest_dev, dest_dev_type); |
| 4091 | /* TODO Figure out the next device the tunnel is using... */ |
| 4092 | break; |
| 4093 | } |
| 4094 | |
ratheesh kannoth | cfdcb33 | 2015-12-24 07:19:18 +0530 | [diff] [blame] | 4095 | #ifdef ECM_INTERFACE_MAP_T_ENABLE |
| 4096 | /* |
| 4097 | * MAP-T xlate ? |
| 4098 | */ |
| 4099 | if (dest_dev_type == ARPHRD_NONE) { |
| 4100 | if (is_map_t_dev(dest_dev)) { |
| 4101 | DEBUG_TRACE("Net device: %p is MAP-T type: %d\n", dest_dev, dest_dev_type); |
| 4102 | break; |
| 4103 | } |
| 4104 | } |
| 4105 | #endif |
| 4106 | |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 4107 | /* |
| 4108 | * If this is NOT PPP then it is unknown to the ecm and we cannot figure out it's next device. |
| 4109 | */ |
| 4110 | if (dest_dev_type != ARPHRD_PPP) { |
| 4111 | DEBUG_TRACE("Net device: %p is UNKNOWN type: %d\n", dest_dev, dest_dev_type); |
| 4112 | break; |
| 4113 | } |
| 4114 | |
| 4115 | #ifndef ECM_INTERFACE_PPP_ENABLE |
| 4116 | DEBUG_TRACE("Net device: %p is UNKNOWN (PPP Unsupported) type: %d\n", dest_dev, dest_dev_type); |
| 4117 | #else |
| 4118 | DEBUG_TRACE("Net device: %p is PPP\n", dest_dev); |
| 4119 | |
| 4120 | #ifdef ECM_INTERFACE_L2TPV2_ENABLE |
ratheesh kannoth | f4801a0 | 2016-12-09 22:46:39 +0530 | [diff] [blame] | 4121 | if ((given_src_dev->priv_flags & IFF_PPP_L2TPV2) && ppp_is_xmit_locked(given_src_dev)) { |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 4122 | if (skb->skb_iif == dest_dev->ifindex) { |
| 4123 | DEBUG_TRACE("Net device: %p PPP channel is PPPoL2TPV2\n", dest_dev); |
| 4124 | break; |
| 4125 | } |
| 4126 | } |
| 4127 | #endif |
| 4128 | |
| 4129 | #ifdef ECM_INTERFACE_PPTP_ENABLE |
Suman Ghosh | 4273a8e | 2018-05-03 16:21:14 +0530 | [diff] [blame] | 4130 | if (protocol == IPPROTO_GRE && dest_dev && (dest_dev->priv_flags & IFF_PPP_PPTP)) { |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 4131 | DEBUG_TRACE("Net device: %p PPP channel is PPTP\n", dest_dev); |
| 4132 | break; |
| 4133 | } |
| 4134 | #endif |
| 4135 | /* |
| 4136 | * PPP - but what is the channel type? |
| 4137 | * First: If this is multi-link then we do not support it |
| 4138 | */ |
| 4139 | if (ppp_is_multilink(dest_dev) > 0) { |
| 4140 | DEBUG_TRACE("Net device: %p is MULTILINK PPP - Unknown to the ECM\n", dest_dev); |
| 4141 | break; |
| 4142 | } |
| 4143 | |
| 4144 | /* |
| 4145 | * Get the PPP channel and then enquire what kind of channel it is |
| 4146 | * NOTE: Not multilink so only one channel to get. |
| 4147 | */ |
| 4148 | channel_count = ppp_hold_channels(dest_dev, ppp_chan, 1); |
| 4149 | if (channel_count != 1) { |
| 4150 | DEBUG_TRACE("Net device: %p PPP has %d channels - Unknown to the ECM\n", |
| 4151 | dest_dev, channel_count); |
| 4152 | break; |
| 4153 | } |
| 4154 | |
| 4155 | /* |
| 4156 | * Get channel protocol type |
| 4157 | * NOTE: Not all PPP channels support channel specific methods. |
| 4158 | */ |
| 4159 | channel_protocol = ppp_channel_get_protocol(ppp_chan[0]); |
| 4160 | |
| 4161 | #ifdef ECM_INTERFACE_L2TPV2_ENABLE |
| 4162 | if (channel_protocol == PX_PROTO_OL2TP) { |
| 4163 | |
| 4164 | /* |
| 4165 | * PPPoL2TPV2 channel |
| 4166 | */ |
| 4167 | ppp_release_channels(ppp_chan, 1); |
| 4168 | DEBUG_TRACE("Net device: %p PPP channel is PPPoL2TPV2\n", dest_dev); |
| 4169 | |
| 4170 | /* |
| 4171 | * Release the channel. Note that next_dev not held. |
| 4172 | */ |
| 4173 | break; |
| 4174 | } |
| 4175 | #endif |
| 4176 | #ifdef ECM_INTERFACE_PPPOE_ENABLE |
| 4177 | if (channel_protocol == PX_PROTO_OE) { |
| 4178 | /* |
| 4179 | * PPPoE channel |
| 4180 | */ |
| 4181 | DEBUG_TRACE("Net device: %p PPP channel is PPPoE\n", dest_dev); |
| 4182 | |
| 4183 | /* |
| 4184 | * Get PPPoE session information and the underlying device it is using. |
| 4185 | */ |
| 4186 | pppoe_channel_addressing_get(ppp_chan[0], &addressing); |
| 4187 | |
| 4188 | /* |
| 4189 | * Copy the dev hold into this, we will release the hold later |
| 4190 | */ |
| 4191 | next_dev = addressing.dev; |
| 4192 | next_dest_addr_valid = false; |
| 4193 | next_dest_node_addr_valid = true; |
| 4194 | memcpy(next_dest_node_addr, addressing.pa.remote, ETH_ALEN); |
| 4195 | |
| 4196 | /* |
| 4197 | * Release the channel. Note that next_dev is still (correctly) held. |
| 4198 | */ |
| 4199 | ppp_release_channels(ppp_chan, 1); |
| 4200 | break; |
| 4201 | } |
| 4202 | #endif |
| 4203 | |
| 4204 | DEBUG_TRACE("Net device: %p PPP channel protocol: %d - Unknown to the ECM\n", |
| 4205 | dest_dev, channel_protocol); |
| 4206 | |
| 4207 | /* |
| 4208 | * Release the channel |
| 4209 | */ |
| 4210 | ppp_release_channels(ppp_chan, 1); |
| 4211 | |
| 4212 | #endif |
| 4213 | } while (false); |
| 4214 | |
| 4215 | /* |
| 4216 | * No longer need dest_dev as it may become next_dev |
| 4217 | */ |
| 4218 | dev_put(dest_dev); |
| 4219 | |
| 4220 | /* |
| 4221 | * Check out the next_dev, if any |
| 4222 | */ |
| 4223 | if (!next_dev) { |
| 4224 | int32_t i __attribute__((unused)); |
| 4225 | DEBUG_INFO("Completed interface heirarchy construct with first interface @: %d\n", current_interface_index); |
| 4226 | #if DEBUG_LEVEL > 1 |
| 4227 | for (i = current_interface_index; i < ECM_DB_IFACE_HEIRARCHY_MAX; ++i) { |
| 4228 | DEBUG_TRACE("\tInterface @ %d: %p, type: %d, name: %s\n", |
Murat Sezgin | 3d9a764 | 2018-05-15 16:24:09 -0700 | [diff] [blame] | 4229 | i, interfaces[i], ecm_db_iface_type_get(interfaces[i]), ecm_db_interface_type_to_string(ecm_db_iface_type_get(interfaces[i]))); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 4230 | |
| 4231 | } |
| 4232 | #endif |
| 4233 | |
| 4234 | /* |
| 4235 | * Release src_dev now |
| 4236 | */ |
| 4237 | dev_put(src_dev); |
| 4238 | return current_interface_index; |
| 4239 | } |
| 4240 | |
| 4241 | /* |
| 4242 | * dest_dev becomes next_dev |
| 4243 | */ |
| 4244 | dest_dev = next_dev; |
| 4245 | dest_dev_name = dest_dev->name; |
| 4246 | dest_dev_type = dest_dev->type; |
| 4247 | } |
| 4248 | |
| 4249 | DEBUG_WARN("Too many interfaces: %d\n", current_interface_index); |
| 4250 | DEBUG_ASSERT(current_interface_index == 0, "Bad logic handling current_interface_index: %d\n", current_interface_index); |
| 4251 | dev_put(src_dev); |
| 4252 | dev_put(dest_dev); |
| 4253 | |
| 4254 | /* |
| 4255 | * Release the interfaces heirarchy we constructed to this point. |
| 4256 | */ |
| 4257 | ecm_db_connection_interfaces_deref(interfaces, current_interface_index); |
| 4258 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 4259 | } |
| 4260 | EXPORT_SYMBOL(ecm_interface_heirarchy_construct); |
| 4261 | |
| 4262 | #ifdef ECM_MULTICAST_ENABLE |
| 4263 | /* |
| 4264 | * ecm_interface_multicast_from_heirarchy_construct() |
| 4265 | * Construct an interface heirarchy. |
| 4266 | * |
| 4267 | * TODO: This function will be removed later and ecm_interface_heirarchy_construct() function |
| 4268 | * will be used when the multicast code is fixed to use the new interface hierarchy |
| 4269 | * construction model which uses the skb's route information instead of doing |
| 4270 | * the route lookup based on the IP addresses. |
| 4271 | * |
| 4272 | * Using the given addressing, locate the interface heirarchy used to emit packets to that destination. |
| 4273 | * This is the heirarchy of interfaces a packet would transit to emit from the device. |
| 4274 | * |
| 4275 | * We will use the given src/dest devices when is_routed is false. |
| 4276 | * When is_routed is true we will try routing tables first, failing back to any given. |
| 4277 | * |
| 4278 | * For example, with this network arrangement: |
| 4279 | * |
| 4280 | * PPPoE--VLAN--BRIDGE--BRIDGE_PORT(LAG_MASTER)--LAG_SLAVE_0--10.22.33.11 |
| 4281 | * |
| 4282 | * Given the packet_dest_addr IP address 10.22.33.11 this will create an interface heirarchy (in interracfes[]) of: |
| 4283 | * LAG_SLAVE_0 @ [ECM_DB_IFACE_HEIRARCHY_MAX - 5] |
| 4284 | * LAG_MASTER @ [ECM_DB_IFACE_HEIRARCHY_MAX - 4] |
| 4285 | * BRIDGE @ [ECM_DB_IFACE_HEIRARCHY_MAX - 3] |
| 4286 | * VLAN @ [ECM_DB_IFACE_HEIRARCHY_MAX - 2] |
| 4287 | * PPPOE @ [ECM_DB_IFACE_HEIRARCHY_MAX - 1] |
| 4288 | * The value returned is (ECM_DB_IFACE_HEIRARCHY_MAX - 5) |
| 4289 | * |
| 4290 | * IMPORTANT: This function will return any known interfaces in the database, when interfaces do not exist in the database |
| 4291 | * they will be created and added automatically to the database. |
| 4292 | */ |
| 4293 | int32_t ecm_interface_multicast_from_heirarchy_construct(struct ecm_front_end_connection_instance *feci, |
| 4294 | struct ecm_db_iface_instance *interfaces[], |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 4295 | ip_addr_t packet_src_addr, |
| 4296 | ip_addr_t packet_dest_addr, |
| 4297 | int ip_version, int packet_protocol, |
| 4298 | struct net_device *given_dest_dev, |
| 4299 | bool is_routed, struct net_device *given_src_dev, |
Suman Ghosh | fb8e770 | 2015-08-20 15:27:57 +0530 | [diff] [blame] | 4300 | uint8_t *dest_node_addr, uint8_t *src_node_addr, |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 4301 | __be16 *layer4hdr, struct sk_buff *skb) |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4302 | { |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4303 | int protocol; |
| 4304 | ip_addr_t src_addr; |
| 4305 | ip_addr_t dest_addr; |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4306 | struct net_device *dest_dev; |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4307 | char *dest_dev_name; |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4308 | int32_t dest_dev_type; |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 4309 | struct net_device *src_dev; |
| 4310 | char *src_dev_name; |
| 4311 | int32_t src_dev_type; |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4312 | int32_t current_interface_index; |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 4313 | bool from_local_addr; |
Murat Sezgin | 7ef2996 | 2015-08-14 10:53:24 -0700 | [diff] [blame] | 4314 | bool next_dest_addr_valid; |
Murat Sezgin | 3aea6c9 | 2015-11-13 13:14:12 -0800 | [diff] [blame] | 4315 | bool next_dest_node_addr_valid = false; |
Murat Sezgin | 7ef2996 | 2015-08-14 10:53:24 -0700 | [diff] [blame] | 4316 | ip_addr_t next_dest_addr; |
| 4317 | uint8_t next_dest_node_addr[ETH_ALEN] = {0}; |
Murat Sezgin | 70c44cd | 2016-03-02 11:32:10 -0800 | [diff] [blame] | 4318 | struct net_device *bridge; |
Murat Sezgin | 545cf7d | 2016-03-04 09:48:21 -0800 | [diff] [blame] | 4319 | uint32_t serial = ecm_db_connection_serial_get(feci->ci); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4320 | |
| 4321 | /* |
| 4322 | * Get a big endian of the IPv4 address we have been given as our starting point. |
| 4323 | */ |
| 4324 | protocol = packet_protocol; |
| 4325 | ECM_IP_ADDR_COPY(src_addr, packet_src_addr); |
| 4326 | ECM_IP_ADDR_COPY(dest_addr, packet_dest_addr); |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 4327 | |
| 4328 | if (ip_version == 4) { |
Murat Sezgin | 545cf7d | 2016-03-04 09:48:21 -0800 | [diff] [blame] | 4329 | DEBUG_TRACE("Construct interface heirarchy for from src_addr: " ECM_IP_ADDR_DOT_FMT " to dest_addr: " ECM_IP_ADDR_DOT_FMT ", protocol: %d (serial %u)\n", |
| 4330 | ECM_IP_ADDR_TO_DOT(src_addr), ECM_IP_ADDR_TO_DOT(dest_addr), protocol, |
| 4331 | serial); |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 4332 | #ifdef ECM_IPV6_ENABLE |
| 4333 | } else if (ip_version == 6) { |
Murat Sezgin | 545cf7d | 2016-03-04 09:48:21 -0800 | [diff] [blame] | 4334 | DEBUG_TRACE("Construct interface heirarchy for from src_addr: " ECM_IP_ADDR_OCTAL_FMT " to dest_addr: " ECM_IP_ADDR_OCTAL_FMT ", protocol: %d (serial %u)\n", |
| 4335 | ECM_IP_ADDR_TO_OCTAL(src_addr), ECM_IP_ADDR_TO_OCTAL(dest_addr), protocol, |
| 4336 | serial); |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 4337 | #endif |
| 4338 | } else { |
| 4339 | DEBUG_WARN("Wrong IP protocol: %d\n", ip_version); |
| 4340 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 4341 | } |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4342 | |
| 4343 | /* |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 4344 | * Get device to reach the given destination address. |
| 4345 | * If the heirarchy is for a routed connection we must try route lookup first, falling back to any given_dest_dev. |
| 4346 | * If the heirarchy is NOT for a routed connection we try the given_dest_dev first, followed by routed lookup. |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4347 | */ |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 4348 | from_local_addr = false; |
| 4349 | if (is_routed) { |
| 4350 | dest_dev = ecm_interface_dev_find_by_addr(dest_addr, &from_local_addr); |
| 4351 | if (!dest_dev && given_dest_dev) { |
| 4352 | /* |
| 4353 | * Fall back to any given |
| 4354 | */ |
| 4355 | dest_dev = given_dest_dev; |
| 4356 | dev_hold(dest_dev); |
Gareth Williams | 43fc085 | 2014-05-26 19:10:00 +0100 | [diff] [blame] | 4357 | } |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 4358 | } else if (given_dest_dev) { |
| 4359 | dest_dev = given_dest_dev; |
| 4360 | dev_hold(dest_dev); |
Radha krishna Simha Jiguru | e9d46fd | 2014-06-03 22:17:19 +0530 | [diff] [blame] | 4361 | } else { |
| 4362 | /* |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 4363 | * Fall back to routed look up |
Radha krishna Simha Jiguru | e9d46fd | 2014-06-03 22:17:19 +0530 | [diff] [blame] | 4364 | */ |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 4365 | dest_dev = ecm_interface_dev_find_by_addr(dest_addr, &from_local_addr); |
Gareth Williams | 43fc085 | 2014-05-26 19:10:00 +0100 | [diff] [blame] | 4366 | } |
Radha krishna Simha Jiguru | e9d46fd | 2014-06-03 22:17:19 +0530 | [diff] [blame] | 4367 | |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 4368 | /* |
| 4369 | * GGG ALERT: If the address is a local address and protocol is an IP tunnel |
| 4370 | * then this connection is a tunnel endpoint made to this device. |
| 4371 | * In which case we circumvent all proper procedure and just hack the devices to make stuff work. |
| 4372 | * GGG TODO THIS MUST BE FIXED - WE MUST USE THE INTERFACE HIERARCHY FOR ITS INTENDED PURPOSE TO |
| 4373 | * PARSE THE DEVICES AND WORK OUT THE PROPER INTERFACES INVOLVED. |
| 4374 | * E.G. IF WE TRIED TO RUN A TUNNEL OVER A VLAN OR QINQ THIS WILL BREAK AS WE DON'T DISCOVER THAT HIERARCHY |
| 4375 | */ |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 4376 | if (dest_dev && from_local_addr) { |
| 4377 | if (((ip_version == 4) && (protocol == IPPROTO_IPV6)) || |
| 4378 | ((ip_version == 6) && (protocol == IPPROTO_IPIP))) { |
| 4379 | dev_put(dest_dev); |
| 4380 | dest_dev = given_dest_dev; |
| 4381 | if (dest_dev) { |
| 4382 | dev_hold(dest_dev); |
Tushar Mathur | bac0324 | 2015-09-15 18:41:59 +0530 | [diff] [blame] | 4383 | if (ip_version == 4) { |
| 4384 | DEBUG_TRACE("HACK: %s tunnel packet with dest_addr: " ECM_IP_ADDR_DOT_FMT " uses dev: %p(%s)\n", "IPV6", ECM_IP_ADDR_TO_DOT(dest_addr), dest_dev, dest_dev->name); |
| 4385 | } else { |
| 4386 | DEBUG_TRACE("HACK: %s tunnel packet with dest_addr: " ECM_IP_ADDR_OCTAL_FMT " uses dev: %p(%s)\n", "IPIP", ECM_IP_ADDR_TO_OCTAL(dest_addr), dest_dev, dest_dev->name); |
| 4387 | } |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 4388 | } |
Radha krishna Simha Jiguru | e9d46fd | 2014-06-03 22:17:19 +0530 | [diff] [blame] | 4389 | } |
Gareth Williams | 43fc085 | 2014-05-26 19:10:00 +0100 | [diff] [blame] | 4390 | } |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 4391 | |
| 4392 | #ifdef ECM_INTERFACE_L2TPV2_ENABLE |
| 4393 | /* |
| 4394 | * if the address is a local address and indev=l2tp. |
| 4395 | */ |
ratheesh kannoth | f4801a0 | 2016-12-09 22:46:39 +0530 | [diff] [blame] | 4396 | if ((given_src_dev->type == ARPHRD_PPP) && (given_src_dev->priv_flags & IFF_PPP_L2TPV2) && ppp_is_xmit_locked(given_src_dev)) { |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 4397 | dev_put(dest_dev); |
| 4398 | dest_dev = given_dest_dev; |
| 4399 | if (dest_dev) { |
| 4400 | dev_hold(dest_dev); |
| 4401 | DEBUG_TRACE("l2tp packet tunnel packet with dest_addr: " ECM_IP_ADDR_OCTAL_FMT " uses dev: %p(%s)\n", ECM_IP_ADDR_TO_OCTAL(dest_addr), dest_dev, dest_dev->name); |
| 4402 | } |
| 4403 | } |
| 4404 | #endif |
| 4405 | |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 4406 | #ifdef ECM_INTERFACE_PPTP_ENABLE |
| 4407 | /* |
| 4408 | * if the address is a local address and indev=PPTP. |
| 4409 | */ |
| 4410 | if (protocol == IPPROTO_GRE && given_dest_dev && given_dest_dev->type == ARPHRD_PPP) { |
| 4411 | dev_put(dest_dev); |
| 4412 | dest_dev = given_dest_dev; |
| 4413 | if (dest_dev) { |
| 4414 | dev_hold(dest_dev); |
| 4415 | DEBUG_TRACE("PPTP packet tunnel packet with dest_addr: " ECM_IP_ADDR_OCTAL_FMT " uses dev: %p(%s)\n", ECM_IP_ADDR_TO_OCTAL(dest_addr), dest_dev, dest_dev->name); |
| 4416 | } |
| 4417 | } |
| 4418 | #endif |
| 4419 | |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 4420 | if (!dest_dev) { |
| 4421 | DEBUG_WARN("dest_addr: " ECM_IP_ADDR_OCTAL_FMT " - cannot locate device\n", ECM_IP_ADDR_TO_OCTAL(dest_addr)); |
| 4422 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 4423 | } |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4424 | dest_dev_name = dest_dev->name; |
| 4425 | dest_dev_type = dest_dev->type; |
| 4426 | |
| 4427 | /* |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 4428 | * Get device to reach the given source address. |
| 4429 | * If the heirarchy is for a routed connection we must try route lookup first, falling back to any given_src_dev. |
| 4430 | * If the heirarchy is NOT for a routed connection we try the given_src_dev first, followed by routed lookup. |
| 4431 | */ |
| 4432 | from_local_addr = false; |
| 4433 | if (is_routed) { |
| 4434 | src_dev = ecm_interface_dev_find_by_addr(src_addr, &from_local_addr); |
| 4435 | if (!src_dev && given_src_dev) { |
| 4436 | /* |
| 4437 | * Fall back to any given |
| 4438 | */ |
| 4439 | src_dev = given_src_dev; |
| 4440 | dev_hold(src_dev); |
| 4441 | } |
| 4442 | } else if (given_src_dev) { |
| 4443 | src_dev = given_src_dev; |
| 4444 | dev_hold(src_dev); |
| 4445 | } else { |
| 4446 | /* |
| 4447 | * Fall back to routed look up |
| 4448 | */ |
| 4449 | src_dev = ecm_interface_dev_find_by_addr(src_addr, &from_local_addr); |
| 4450 | } |
| 4451 | |
| 4452 | /* |
| 4453 | * GGG ALERT: If the address is a local address and protocol is an IP tunnel |
| 4454 | * then this connection is a tunnel endpoint made to this device. |
| 4455 | * In which case we circumvent all proper procedure and just hack the devices to make stuff work. |
| 4456 | * GGG TODO THIS MUST BE FIXED - WE MUST USE THE INTERFACE HIERARCHY FOR ITS INTENDED PURPOSE TO |
| 4457 | * PARSE THE DEVICES AND WORK OUT THE PROPER INTERFACES INVOLVED. |
| 4458 | * E.G. IF WE TRIED TO RUN A TUNNEL OVER A VLAN OR QINQ THIS WILL BREAK AS WE DON'T DISCOVER THAT HIERARCHY |
| 4459 | */ |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 4460 | if (src_dev && from_local_addr) { |
| 4461 | if (((ip_version == 4) && (protocol == IPPROTO_IPV6)) || |
| 4462 | ((ip_version == 6) && (protocol == IPPROTO_IPIP))) { |
| 4463 | dev_put(src_dev); |
| 4464 | src_dev = given_src_dev; |
| 4465 | if (src_dev) { |
| 4466 | dev_hold(src_dev); |
Tushar Mathur | bac0324 | 2015-09-15 18:41:59 +0530 | [diff] [blame] | 4467 | if (ip_version == 4) { |
| 4468 | DEBUG_TRACE("HACK: %s tunnel packet with src_addr: " ECM_IP_ADDR_DOT_FMT " uses dev: %p(%s)\n", "IPV6", ECM_IP_ADDR_TO_DOT(src_addr), src_dev, src_dev->name); |
| 4469 | } else { |
| 4470 | DEBUG_TRACE("HACK: %s tunnel packet with src_addr: " ECM_IP_ADDR_OCTAL_FMT " uses dev: %p(%s)\n", "IPIP", ECM_IP_ADDR_TO_OCTAL(src_addr), src_dev, src_dev->name); |
| 4471 | } |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 4472 | } |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 4473 | } |
| 4474 | } |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 4475 | |
ratheesh kannoth | ed72185 | 2015-09-28 12:39:52 +0530 | [diff] [blame] | 4476 | #ifdef ECM_INTERFACE_L2TPV2_ENABLE |
| 4477 | /* |
| 4478 | * if the address is a local address and indev=l2tp. |
| 4479 | */ |
| 4480 | if (skb && skb->sk && (skb->sk->sk_protocol == IPPROTO_UDP) && (udp_sk(skb->sk)->encap_type == UDP_ENCAP_L2TPINUDP)) { |
| 4481 | if (dest_dev != given_src_dev) { |
| 4482 | dev_put(src_dev); |
| 4483 | src_dev = given_src_dev; |
| 4484 | if (src_dev) { |
| 4485 | dev_hold(src_dev); |
| 4486 | DEBUG_TRACE("l2tp tunnel packet with src_addr: " ECM_IP_ADDR_OCTAL_FMT " uses dev: %p(%s)\n", ECM_IP_ADDR_TO_OCTAL(src_addr), src_dev, src_dev->name); |
| 4487 | } |
| 4488 | } |
| 4489 | } |
| 4490 | #endif |
| 4491 | |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 4492 | if (!src_dev) { |
| 4493 | DEBUG_WARN("src_addr: " ECM_IP_ADDR_OCTAL_FMT " - cannot locate device\n", ECM_IP_ADDR_TO_OCTAL(src_addr)); |
| 4494 | dev_put(dest_dev); |
| 4495 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 4496 | } |
| 4497 | src_dev_name = src_dev->name; |
| 4498 | src_dev_type = src_dev->type; |
| 4499 | |
| 4500 | /* |
| 4501 | * Check if source and dest dev are same. |
| 4502 | * For the forwarded flows which involve tunnels this will happen when called from input hook. |
Radha krishna Simha Jiguru | e9d46fd | 2014-06-03 22:17:19 +0530 | [diff] [blame] | 4503 | */ |
| 4504 | if (src_dev == dest_dev) { |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 4505 | DEBUG_TRACE("Protocol is :%d source dev and dest dev are same\n", protocol); |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 4506 | if (((ip_version == 4) && ((protocol == IPPROTO_IPV6) || (protocol == IPPROTO_ESP))) |
| 4507 | || ((ip_version == 6) && (protocol == IPPROTO_IPIP))) { |
Radha krishna Simha Jiguru | e9d46fd | 2014-06-03 22:17:19 +0530 | [diff] [blame] | 4508 | /* |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 4509 | * This happens from the input hook |
Radha krishna Simha Jiguru | e9d46fd | 2014-06-03 22:17:19 +0530 | [diff] [blame] | 4510 | * We do not want to create a connection entry for this |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 4511 | * GGG TODO YES WE DO. |
| 4512 | * GGG TODO THIS CONCERNS ME AS THIS SHOULD BE CAUGHT MUCH |
| 4513 | * EARLIER IN THE FRONT END IF POSSIBLE TO AVOID PERFORMANCE PENALTIES. |
| 4514 | * WE HAVE DONE A TREMENDOUS AMOUT OF WORK TO GET TO THIS POINT. |
| 4515 | * WE WILL ABORT HERE AND THIS WILL BE REPEATED FOR EVERY PACKET. |
| 4516 | * IN KEEPING WITH THE ECM DESIGN IT IS BETTER TO CREATE A CONNECTION AND RECORD IN THE HIERARCHY |
| 4517 | * ENOUGH INFORMATION TO ENSURE THAT ACCELERATION IS NOT BROKEN / DOES NOT OCCUR AT ALL. |
| 4518 | * THAT WAY WE DO A HEAVYWEIGHT ESTABLISHING OF A CONNECTION ONCE AND NEVER AGAIN... |
Radha krishna Simha Jiguru | e9d46fd | 2014-06-03 22:17:19 +0530 | [diff] [blame] | 4519 | */ |
| 4520 | dev_put(src_dev); |
| 4521 | dev_put(dest_dev); |
| 4522 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 4523 | } |
Murat Sezgin | 70c44cd | 2016-03-02 11:32:10 -0800 | [diff] [blame] | 4524 | } |
Murat Sezgin | 3aea6c9 | 2015-11-13 13:14:12 -0800 | [diff] [blame] | 4525 | |
Murat Sezgin | 70c44cd | 2016-03-02 11:32:10 -0800 | [diff] [blame] | 4526 | bridge = ecm_interface_should_update_egress_device_bridged( |
| 4527 | given_dest_dev, dest_dev, is_routed); |
Murat Sezgin | 3aea6c9 | 2015-11-13 13:14:12 -0800 | [diff] [blame] | 4528 | |
Murat Sezgin | 70c44cd | 2016-03-02 11:32:10 -0800 | [diff] [blame] | 4529 | if (bridge) { |
Murat Sezgin | 70c44cd | 2016-03-02 11:32:10 -0800 | [diff] [blame] | 4530 | struct net_device *new_dest_dev; |
Murat Sezgin | b9bd5e0 | 2016-08-05 14:55:07 -0700 | [diff] [blame] | 4531 | new_dest_dev = br_port_dev_get(bridge, dest_node_addr, skb, serial); |
| 4532 | if (new_dest_dev) { |
| 4533 | dev_put(dest_dev); |
| 4534 | if (new_dest_dev != given_dest_dev) { |
| 4535 | DEBUG_INFO("Adjusted port for %pM is %s (given was %s)\n", |
| 4536 | dest_node_addr, new_dest_dev->name, |
| 4537 | given_dest_dev->name); |
Murat Sezgin | 3aea6c9 | 2015-11-13 13:14:12 -0800 | [diff] [blame] | 4538 | |
Murat Sezgin | b9bd5e0 | 2016-08-05 14:55:07 -0700 | [diff] [blame] | 4539 | dest_dev = new_dest_dev; |
| 4540 | dest_dev_name = dest_dev->name; |
| 4541 | dest_dev_type = dest_dev->type; |
Murat Sezgin | 3aea6c9 | 2015-11-13 13:14:12 -0800 | [diff] [blame] | 4542 | } |
Murat Sezgin | 3aea6c9 | 2015-11-13 13:14:12 -0800 | [diff] [blame] | 4543 | } |
Murat Sezgin | 70c44cd | 2016-03-02 11:32:10 -0800 | [diff] [blame] | 4544 | dev_put(bridge); |
Radha krishna Simha Jiguru | e9d46fd | 2014-06-03 22:17:19 +0530 | [diff] [blame] | 4545 | } |
| 4546 | |
Murat Sezgin | 7ef2996 | 2015-08-14 10:53:24 -0700 | [diff] [blame] | 4547 | next_dest_addr_valid = true; |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 4548 | next_dest_node_addr_valid = false; |
Murat Sezgin | 7ef2996 | 2015-08-14 10:53:24 -0700 | [diff] [blame] | 4549 | ECM_IP_ADDR_COPY(next_dest_addr, dest_addr); |
| 4550 | |
Radha krishna Simha Jiguru | e9d46fd | 2014-06-03 22:17:19 +0530 | [diff] [blame] | 4551 | /* |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4552 | * Iterate until we are done or get to the max number of interfaces we can record. |
| 4553 | * NOTE: current_interface_index tracks the position of the first interface position in interfaces[] |
| 4554 | * because we add from the end first_interface grows downwards. |
| 4555 | */ |
| 4556 | current_interface_index = ECM_DB_IFACE_HEIRARCHY_MAX; |
| 4557 | while (current_interface_index > 0) { |
| 4558 | struct ecm_db_iface_instance *ii; |
| 4559 | struct net_device *next_dev; |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4560 | /* |
| 4561 | * Get the ecm db interface instance for the device at hand |
| 4562 | */ |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 4563 | ii = ecm_interface_establish_and_ref(feci, dest_dev, skb); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4564 | |
| 4565 | /* |
| 4566 | * If the interface could not be established then we abort |
| 4567 | */ |
| 4568 | if (!ii) { |
| 4569 | DEBUG_WARN("Failed to establish interface: %p, name: %s\n", dest_dev, dest_dev_name); |
| 4570 | dev_put(src_dev); |
| 4571 | dev_put(dest_dev); |
| 4572 | |
| 4573 | /* |
| 4574 | * Release the interfaces heirarchy we constructed to this point. |
| 4575 | */ |
| 4576 | ecm_db_connection_interfaces_deref(interfaces, current_interface_index); |
| 4577 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 4578 | } |
| 4579 | |
| 4580 | /* |
| 4581 | * Record the interface instance into the interfaces[] |
| 4582 | */ |
| 4583 | current_interface_index--; |
| 4584 | interfaces[current_interface_index] = ii; |
| 4585 | |
| 4586 | /* |
| 4587 | * Now we have to figure out what the next device will be (in the transmission path) the skb |
| 4588 | * will use to emit to the destination address. |
| 4589 | */ |
| 4590 | do { |
Gareth Williams | dbb2bfd | 2014-11-20 16:42:09 -0800 | [diff] [blame] | 4591 | #ifdef ECM_INTERFACE_PPP_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4592 | int channel_count; |
| 4593 | struct ppp_channel *ppp_chan[1]; |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4594 | int channel_protocol; |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 4595 | #ifdef ECM_INTERFACE_PPPOE_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4596 | struct pppoe_opt addressing; |
Gareth Williams | c5b9d71 | 2014-05-09 20:40:07 +0100 | [diff] [blame] | 4597 | #endif |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 4598 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4599 | |
| 4600 | DEBUG_TRACE("Net device: %p is type: %d, name: %s\n", dest_dev, dest_dev_type, dest_dev_name); |
| 4601 | next_dev = NULL; |
| 4602 | |
| 4603 | if (dest_dev_type == ARPHRD_ETHER) { |
| 4604 | /* |
| 4605 | * Ethernet - but what sub type? |
| 4606 | */ |
| 4607 | |
Gareth Williams | 141d238 | 2014-11-25 11:35:19 -0800 | [diff] [blame] | 4608 | #ifdef ECM_INTERFACE_VLAN_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4609 | /* |
| 4610 | * VLAN? |
| 4611 | */ |
| 4612 | if (is_vlan_dev(dest_dev)) { |
| 4613 | /* |
| 4614 | * VLAN master |
| 4615 | * No locking needed here, ASSUMPTION is that real_dev is held for as long as we have dev. |
| 4616 | */ |
Shyam Sunder | 9db2085 | 2016-03-09 19:04:49 +0530 | [diff] [blame] | 4617 | next_dev = ecm_interface_vlan_real_dev(dest_dev); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4618 | dev_hold(next_dev); |
| 4619 | DEBUG_TRACE("Net device: %p is VLAN, slave dev: %p (%s)\n", |
| 4620 | dest_dev, next_dev, next_dev->name); |
| 4621 | break; |
| 4622 | } |
Gareth Williams | 141d238 | 2014-11-25 11:35:19 -0800 | [diff] [blame] | 4623 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4624 | |
| 4625 | /* |
| 4626 | * BRIDGE? |
| 4627 | */ |
| 4628 | if (ecm_front_end_is_bridge_device(dest_dev)) { |
| 4629 | /* |
| 4630 | * Bridge |
| 4631 | * Figure out which port device the skb will go to using the dest_addr. |
| 4632 | */ |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4633 | uint8_t mac_addr[ETH_ALEN]; |
Murat Sezgin | 7ef2996 | 2015-08-14 10:53:24 -0700 | [diff] [blame] | 4634 | |
| 4635 | if (next_dest_node_addr_valid) { |
| 4636 | memcpy(mac_addr, next_dest_node_addr, ETH_ALEN); |
| 4637 | } else if (!next_dest_addr_valid) { |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4638 | dev_put(src_dev); |
| 4639 | dev_put(dest_dev); |
| 4640 | |
| 4641 | /* |
| 4642 | * Release the interfaces heirarchy we constructed to this point. |
| 4643 | */ |
| 4644 | ecm_db_connection_interfaces_deref(interfaces, current_interface_index); |
| 4645 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
Murat Sezgin | 7ef2996 | 2015-08-14 10:53:24 -0700 | [diff] [blame] | 4646 | } else { |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 4647 | if (!ecm_interface_multicast_get_next_node_mac_address(next_dest_addr, dest_dev, ip_version, mac_addr)) { |
Murat Sezgin | 7ef2996 | 2015-08-14 10:53:24 -0700 | [diff] [blame] | 4648 | dev_put(src_dev); |
| 4649 | dev_put(dest_dev); |
| 4650 | |
| 4651 | /* |
| 4652 | * Release the interfaces heirarchy we constructed to this point. |
| 4653 | */ |
| 4654 | ecm_db_connection_interfaces_deref(interfaces, current_interface_index); |
| 4655 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 4656 | } |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4657 | } |
Murat Sezgin | 545cf7d | 2016-03-04 09:48:21 -0800 | [diff] [blame] | 4658 | next_dev = br_port_dev_get(dest_dev, |
| 4659 | mac_addr, skb, serial); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4660 | if (!next_dev) { |
| 4661 | DEBUG_WARN("Unable to obtain output port for: %pM\n", mac_addr); |
| 4662 | dev_put(src_dev); |
| 4663 | dev_put(dest_dev); |
| 4664 | |
| 4665 | /* |
| 4666 | * Release the interfaces heirarchy we constructed to this point. |
| 4667 | */ |
| 4668 | ecm_db_connection_interfaces_deref(interfaces, current_interface_index); |
| 4669 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 4670 | } |
| 4671 | DEBUG_TRACE("Net device: %p is BRIDGE, next_dev: %p (%s)\n", dest_dev, next_dev, next_dev->name); |
| 4672 | break; |
| 4673 | } |
Gareth Williams | 8ac3429 | 2015-03-17 14:06:58 +0000 | [diff] [blame] | 4674 | |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 4675 | #ifdef ECM_INTERFACE_BOND_ENABLE |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4676 | /* |
| 4677 | * LAG? |
| 4678 | */ |
| 4679 | if (ecm_front_end_is_lag_master(dest_dev)) { |
| 4680 | /* |
| 4681 | * Link aggregation |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 4682 | * Figure out whiich slave device of the link aggregation will be used to reach the destination. |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4683 | */ |
Tushar Mathur | 4ab0bf9 | 2014-06-10 20:37:07 +0530 | [diff] [blame] | 4684 | bool dest_on_link = false; |
| 4685 | ip_addr_t dest_gw_addr = ECM_IP_ADDR_NULL; |
| 4686 | uint32_t src_addr_32 = 0; |
| 4687 | uint32_t dest_addr_32 = 0; |
Suman Ghosh | f14d217 | 2015-07-31 14:38:10 +0530 | [diff] [blame] | 4688 | struct in6_addr src_addr6; |
| 4689 | struct in6_addr dest_addr6; |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4690 | uint8_t src_mac_addr[ETH_ALEN]; |
| 4691 | uint8_t dest_mac_addr[ETH_ALEN]; |
Tushar Mathur | 4ab0bf9 | 2014-06-10 20:37:07 +0530 | [diff] [blame] | 4692 | struct net_device *master_dev = NULL; |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4693 | |
Tushar Mathur | 4ab0bf9 | 2014-06-10 20:37:07 +0530 | [diff] [blame] | 4694 | memset(src_mac_addr, 0, ETH_ALEN); |
| 4695 | memset(dest_mac_addr, 0, ETH_ALEN); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4696 | |
Gareth Williams | 341df38 | 2015-07-20 16:44:17 +0100 | [diff] [blame] | 4697 | if (ip_version == 4) { |
| 4698 | ECM_IP_ADDR_TO_NIN4_ADDR(src_addr_32, src_addr); |
| 4699 | ECM_IP_ADDR_TO_NIN4_ADDR(dest_addr_32, dest_addr); |
| 4700 | } |
Tushar Mathur | 4ab0bf9 | 2014-06-10 20:37:07 +0530 | [diff] [blame] | 4701 | |
| 4702 | if (!is_routed) { |
| 4703 | memcpy(src_mac_addr, src_node_addr, ETH_ALEN); |
| 4704 | memcpy(dest_mac_addr, dest_node_addr, ETH_ALEN); |
| 4705 | } else { |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 4706 | struct net_device *dest_dev_master; |
| 4707 | |
Tushar Mathur | 4ab0bf9 | 2014-06-10 20:37:07 +0530 | [diff] [blame] | 4708 | /* |
| 4709 | * Use appropriate source MAC address for routed packets |
| 4710 | */ |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 4711 | dest_dev_master = ecm_interface_get_and_hold_dev_master(dest_dev); |
| 4712 | if (dest_dev_master) { |
| 4713 | memcpy(src_mac_addr, dest_dev_master->dev_addr, ETH_ALEN); |
Tushar Mathur | 4ab0bf9 | 2014-06-10 20:37:07 +0530 | [diff] [blame] | 4714 | } else { |
| 4715 | memcpy(src_mac_addr, dest_dev->dev_addr, ETH_ALEN); |
| 4716 | } |
| 4717 | |
| 4718 | /* |
| 4719 | * Determine destination MAC address for this routed packet |
| 4720 | */ |
Tushar Mathur | 78b5f43 | 2015-09-18 20:13:31 +0530 | [diff] [blame] | 4721 | if (next_dest_node_addr_valid) { |
| 4722 | memcpy(dest_mac_addr, next_dest_node_addr, ETH_ALEN); |
| 4723 | } else if (!next_dest_addr_valid) { |
| 4724 | dev_put(src_dev); |
| 4725 | dev_put(dest_dev); |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 4726 | if (dest_dev_master) { |
| 4727 | dev_put(dest_dev_master); |
| 4728 | } |
| 4729 | |
Tushar Mathur | 4ab0bf9 | 2014-06-10 20:37:07 +0530 | [diff] [blame] | 4730 | ecm_db_connection_interfaces_deref(interfaces, current_interface_index); |
| 4731 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
Tushar Mathur | 78b5f43 | 2015-09-18 20:13:31 +0530 | [diff] [blame] | 4732 | } else { |
| 4733 | if (!ecm_interface_mac_addr_get(dest_addr, dest_mac_addr, |
| 4734 | &dest_on_link, dest_gw_addr)) { |
| 4735 | |
| 4736 | /* |
| 4737 | * Find proper interfce from which to issue ARP |
| 4738 | * or neighbour solicitation packet. |
| 4739 | */ |
| 4740 | if (dest_dev_master) { |
| 4741 | master_dev = dest_dev_master; |
| 4742 | } else { |
| 4743 | master_dev = dest_dev; |
| 4744 | } |
| 4745 | |
| 4746 | dev_hold(master_dev); |
| 4747 | |
| 4748 | if (dest_dev_master) { |
| 4749 | dev_put(dest_dev_master); |
| 4750 | } |
| 4751 | |
| 4752 | if (ip_version == 4) { |
| 4753 | DEBUG_WARN("Unable to obtain MAC address for " ECM_IP_ADDR_DOT_FMT "\n", ECM_IP_ADDR_TO_DOT(dest_addr)); |
| 4754 | ecm_interface_send_arp_request(dest_dev, dest_addr, dest_on_link, dest_gw_addr); |
| 4755 | } |
| 4756 | #ifdef ECM_IPV6_ENABLE |
| 4757 | if (ip_version == 6) { |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 4758 | DEBUG_WARN("Unable to obtain MAC address for " ECM_IP_ADDR_OCTAL_FMT "\n", ECM_IP_ADDR_TO_OCTAL(dest_addr)); |
Tushar Mathur | 78b5f43 | 2015-09-18 20:13:31 +0530 | [diff] [blame] | 4759 | ecm_interface_send_neighbour_solicitation(master_dev, dest_addr); |
| 4760 | } |
| 4761 | #endif |
| 4762 | dev_put(src_dev); |
| 4763 | dev_put(dest_dev); |
| 4764 | dev_put(master_dev); |
| 4765 | ecm_db_connection_interfaces_deref(interfaces, current_interface_index); |
| 4766 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 4767 | } |
Tushar Mathur | 4ab0bf9 | 2014-06-10 20:37:07 +0530 | [diff] [blame] | 4768 | } |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 4769 | |
| 4770 | if (dest_dev_master) { |
| 4771 | dev_put(dest_dev_master); |
| 4772 | } |
Tushar Mathur | 4ab0bf9 | 2014-06-10 20:37:07 +0530 | [diff] [blame] | 4773 | } |
| 4774 | |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 4775 | if (ip_version == 4) { |
| 4776 | next_dev = bond_get_tx_dev(NULL, src_mac_addr, dest_mac_addr, |
| 4777 | &src_addr_32, &dest_addr_32, |
Suman Ghosh | fb8e770 | 2015-08-20 15:27:57 +0530 | [diff] [blame] | 4778 | htons((uint16_t)ETH_P_IP), dest_dev, layer4hdr); |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 4779 | } else if (ip_version == 6) { |
Suman Ghosh | f14d217 | 2015-07-31 14:38:10 +0530 | [diff] [blame] | 4780 | ECM_IP_ADDR_TO_NIN6_ADDR(src_addr6, src_addr); |
| 4781 | ECM_IP_ADDR_TO_NIN6_ADDR(dest_addr6, dest_addr); |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 4782 | next_dev = bond_get_tx_dev(NULL, src_mac_addr, dest_mac_addr, |
Suman Ghosh | f14d217 | 2015-07-31 14:38:10 +0530 | [diff] [blame] | 4783 | src_addr6.s6_addr, dest_addr6.s6_addr, |
Shyam Sunder | e60540c | 2016-04-29 15:06:35 +0530 | [diff] [blame] | 4784 | htons((uint16_t)ETH_P_IPV6), dest_dev, layer4hdr); |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 4785 | } |
| 4786 | |
Tushar Mathur | 933907c | 2014-06-24 17:06:14 +0530 | [diff] [blame] | 4787 | if (next_dev && netif_carrier_ok(next_dev)) { |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4788 | dev_hold(next_dev); |
| 4789 | } else { |
| 4790 | DEBUG_WARN("Unable to obtain LAG output slave device\n"); |
| 4791 | dev_put(src_dev); |
| 4792 | dev_put(dest_dev); |
| 4793 | |
| 4794 | /* |
| 4795 | * Release the interfaces heirarchy we constructed to this point. |
| 4796 | */ |
| 4797 | ecm_db_connection_interfaces_deref(interfaces, current_interface_index); |
| 4798 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 4799 | } |
| 4800 | |
| 4801 | DEBUG_TRACE("Net device: %p is LAG, slave dev: %p (%s)\n", dest_dev, next_dev, next_dev->name); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4802 | break; |
| 4803 | } |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 4804 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4805 | |
| 4806 | /* |
| 4807 | * ETHERNET! |
| 4808 | * Just plain ethernet it seems. |
| 4809 | */ |
| 4810 | DEBUG_TRACE("Net device: %p is ETHERNET\n", dest_dev); |
| 4811 | break; |
Radha krishna Simha Jiguru | f7dc34c | 2014-05-12 18:59:07 +0530 | [diff] [blame] | 4812 | } |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4813 | |
| 4814 | /* |
| 4815 | * LOOPBACK? |
| 4816 | */ |
| 4817 | if (dest_dev_type == ARPHRD_LOOPBACK) { |
| 4818 | DEBUG_TRACE("Net device: %p is LOOPBACK type: %d\n", dest_dev, dest_dev_type); |
| 4819 | break; |
| 4820 | } |
| 4821 | |
| 4822 | /* |
| 4823 | * IPSEC? |
| 4824 | */ |
| 4825 | if (dest_dev_type == ECM_ARPHRD_IPSEC_TUNNEL_TYPE) { |
| 4826 | DEBUG_TRACE("Net device: %p is IPSec tunnel type: %d\n", dest_dev, dest_dev_type); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 4827 | /* TODO Figure out the next device the tunnel is using... */ |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4828 | break; |
| 4829 | } |
| 4830 | |
| 4831 | /* |
| 4832 | * SIT (6-in-4)? |
| 4833 | */ |
| 4834 | if (dest_dev_type == ARPHRD_SIT) { |
| 4835 | DEBUG_TRACE("Net device: %p is SIT (6-in-4) type: %d\n", dest_dev, dest_dev_type); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 4836 | /* TODO Figure out the next device the tunnel is using... */ |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4837 | break; |
| 4838 | } |
| 4839 | |
| 4840 | /* |
| 4841 | * IPIP6 Tunnel? |
| 4842 | */ |
| 4843 | if (dest_dev_type == ARPHRD_TUNNEL6) { |
| 4844 | DEBUG_TRACE("Net device: %p is TUNIPIP6 type: %d\n", dest_dev, dest_dev_type); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 4845 | /* TODO Figure out the next device the tunnel is using... */ |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4846 | break; |
| 4847 | } |
| 4848 | |
| 4849 | /* |
| 4850 | * If this is NOT PPP then it is unknown to the ecm and we cannot figure out it's next device. |
| 4851 | */ |
| 4852 | if (dest_dev_type != ARPHRD_PPP) { |
| 4853 | DEBUG_TRACE("Net device: %p is UNKNOWN type: %d\n", dest_dev, dest_dev_type); |
| 4854 | break; |
| 4855 | } |
| 4856 | |
Gareth Williams | dbb2bfd | 2014-11-20 16:42:09 -0800 | [diff] [blame] | 4857 | #ifndef ECM_INTERFACE_PPP_ENABLE |
Gareth Williams | c5b9d71 | 2014-05-09 20:40:07 +0100 | [diff] [blame] | 4858 | DEBUG_TRACE("Net device: %p is UNKNOWN (PPP Unsupported) type: %d\n", dest_dev, dest_dev_type); |
| 4859 | #else |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 4860 | DEBUG_TRACE("Net device: %p is PPP\n", dest_dev); |
| 4861 | |
| 4862 | #ifdef ECM_INTERFACE_L2TPV2_ENABLE |
ratheesh kannoth | f4801a0 | 2016-12-09 22:46:39 +0530 | [diff] [blame] | 4863 | if ((given_src_dev->priv_flags & IFF_PPP_L2TPV2) && ppp_is_xmit_locked(given_src_dev)) { |
ratheesh kannoth | ed72185 | 2015-09-28 12:39:52 +0530 | [diff] [blame] | 4864 | if (skb->skb_iif == dest_dev->ifindex) { |
| 4865 | DEBUG_TRACE("Net device: %p PPP channel is PPPoL2TPV2\n", dest_dev); |
| 4866 | break; |
| 4867 | } |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 4868 | } |
| 4869 | #endif |
Shyam Sunder | 23f2e54 | 2015-09-28 14:56:49 +0530 | [diff] [blame] | 4870 | |
| 4871 | #ifdef ECM_INTERFACE_PPTP_ENABLE |
| 4872 | if (protocol == IPPROTO_GRE && dest_dev && dest_dev->type == ARPHRD_PPP) { |
| 4873 | DEBUG_TRACE("Net device: %p PPP channel is PPTP\n", dest_dev); |
| 4874 | break; |
| 4875 | } |
| 4876 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4877 | /* |
| 4878 | * PPP - but what is the channel type? |
| 4879 | * First: If this is multi-link then we do not support it |
| 4880 | */ |
| 4881 | if (ppp_is_multilink(dest_dev) > 0) { |
| 4882 | DEBUG_TRACE("Net device: %p is MULTILINK PPP - Unknown to the ECM\n", dest_dev); |
| 4883 | break; |
| 4884 | } |
| 4885 | |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4886 | /* |
| 4887 | * Get the PPP channel and then enquire what kind of channel it is |
| 4888 | * NOTE: Not multilink so only one channel to get. |
| 4889 | */ |
| 4890 | channel_count = ppp_hold_channels(dest_dev, ppp_chan, 1); |
| 4891 | if (channel_count != 1) { |
| 4892 | DEBUG_TRACE("Net device: %p PPP has %d channels - Unknown to the ECM\n", |
| 4893 | dest_dev, channel_count); |
| 4894 | break; |
| 4895 | } |
| 4896 | |
| 4897 | /* |
| 4898 | * Get channel protocol type |
Gareth Williams | 6f96a4b | 2014-05-29 19:41:21 +0100 | [diff] [blame] | 4899 | * NOTE: Not all PPP channels support channel specific methods. |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4900 | */ |
Gareth Williams | 6f96a4b | 2014-05-29 19:41:21 +0100 | [diff] [blame] | 4901 | channel_protocol = ppp_channel_get_protocol(ppp_chan[0]); |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 4902 | |
| 4903 | #ifdef ECM_INTERFACE_L2TPV2_ENABLE |
| 4904 | if (channel_protocol == PX_PROTO_OL2TP) { |
Radha krishna Simha Jiguru | f7dc34c | 2014-05-12 18:59:07 +0530 | [diff] [blame] | 4905 | |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4906 | /* |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 4907 | * PPPoL2TPV2 channel |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4908 | */ |
| 4909 | ppp_release_channels(ppp_chan, 1); |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 4910 | DEBUG_TRACE("Net device: %p PPP channel is PPPoL2TPV2\n", dest_dev); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4911 | |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 4912 | /* |
| 4913 | * Release the channel. Note that next_dev not held. |
| 4914 | */ |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4915 | break; |
| 4916 | } |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 4917 | #endif |
| 4918 | #ifdef ECM_INTERFACE_PPPOE_ENABLE |
| 4919 | if (channel_protocol == PX_PROTO_OE) { |
| 4920 | /* |
| 4921 | * PPPoE channel |
| 4922 | */ |
| 4923 | DEBUG_TRACE("Net device: %p PPP channel is PPPoE\n", dest_dev); |
| 4924 | |
| 4925 | /* |
| 4926 | * Get PPPoE session information and the underlying device it is using. |
| 4927 | */ |
| 4928 | pppoe_channel_addressing_get(ppp_chan[0], &addressing); |
| 4929 | |
| 4930 | /* |
| 4931 | * Copy the dev hold into this, we will release the hold later |
| 4932 | */ |
| 4933 | next_dev = addressing.dev; |
| 4934 | next_dest_addr_valid = false; |
| 4935 | next_dest_node_addr_valid = true; |
| 4936 | memcpy(next_dest_node_addr, addressing.pa.remote, ETH_ALEN); |
| 4937 | |
| 4938 | /* |
| 4939 | * Release the channel. Note that next_dev is still (correctly) held. |
| 4940 | */ |
| 4941 | ppp_release_channels(ppp_chan, 1); |
| 4942 | break; |
| 4943 | } |
| 4944 | #endif |
| 4945 | |
| 4946 | DEBUG_TRACE("Net device: %p PPP channel protocol: %d - Unknown to the ECM\n", |
| 4947 | dest_dev, channel_protocol); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4948 | |
| 4949 | /* |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 4950 | * Release the channel |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4951 | */ |
| 4952 | ppp_release_channels(ppp_chan, 1); |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 4953 | |
Gareth Williams | c5b9d71 | 2014-05-09 20:40:07 +0100 | [diff] [blame] | 4954 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4955 | } while (false); |
| 4956 | |
| 4957 | /* |
Gareth Williams | a11d435 | 2014-05-14 18:25:49 +0100 | [diff] [blame] | 4958 | * No longer need dest_dev as it may become next_dev |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4959 | */ |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4960 | dev_put(dest_dev); |
| 4961 | |
| 4962 | /* |
| 4963 | * Check out the next_dev, if any |
| 4964 | */ |
| 4965 | if (!next_dev) { |
| 4966 | int32_t i __attribute__((unused)); |
| 4967 | DEBUG_INFO("Completed interface heirarchy construct with first interface @: %d\n", current_interface_index); |
| 4968 | #if DEBUG_LEVEL > 1 |
| 4969 | for (i = current_interface_index; i < ECM_DB_IFACE_HEIRARCHY_MAX; ++i) { |
| 4970 | DEBUG_TRACE("\tInterface @ %d: %p, type: %d, name: %s\n", |
Murat Sezgin | 3d9a764 | 2018-05-15 16:24:09 -0700 | [diff] [blame] | 4971 | i, interfaces[i], ecm_db_iface_type_get(interfaces[i]), ecm_db_interface_type_to_string(ecm_db_iface_type_get(interfaces[i]))); |
Tushar Mathur | 4ab0bf9 | 2014-06-10 20:37:07 +0530 | [diff] [blame] | 4972 | |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4973 | } |
| 4974 | #endif |
Gareth Williams | a11d435 | 2014-05-14 18:25:49 +0100 | [diff] [blame] | 4975 | |
| 4976 | /* |
| 4977 | * Release src_dev now |
| 4978 | */ |
| 4979 | dev_put(src_dev); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4980 | return current_interface_index; |
| 4981 | } |
| 4982 | |
Gareth Williams | a11d435 | 2014-05-14 18:25:49 +0100 | [diff] [blame] | 4983 | /* |
| 4984 | * dest_dev becomes next_dev |
| 4985 | */ |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 4986 | dest_dev = next_dev; |
| 4987 | dest_dev_name = dest_dev->name; |
| 4988 | dest_dev_type = dest_dev->type; |
| 4989 | } |
| 4990 | |
| 4991 | DEBUG_WARN("Too many interfaces: %d\n", current_interface_index); |
| 4992 | DEBUG_ASSERT(current_interface_index == 0, "Bad logic handling current_interface_index: %d\n", current_interface_index); |
| 4993 | dev_put(src_dev); |
| 4994 | dev_put(dest_dev); |
| 4995 | |
| 4996 | /* |
| 4997 | * Release the interfaces heirarchy we constructed to this point. |
| 4998 | */ |
| 4999 | ecm_db_connection_interfaces_deref(interfaces, current_interface_index); |
| 5000 | return ECM_DB_IFACE_HEIRARCHY_MAX; |
| 5001 | } |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 5002 | EXPORT_SYMBOL(ecm_interface_multicast_from_heirarchy_construct); |
| 5003 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 5004 | |
| 5005 | /* |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 5006 | * ecm_interface_list_stats_update() |
| 5007 | * Given an interface list, walk the interfaces and update the stats for certain types. |
| 5008 | */ |
| 5009 | static void ecm_interface_list_stats_update(int iface_list_first, struct ecm_db_iface_instance *iface_list[], uint8_t *mac_addr, |
Suman Ghosh | 812ad30 | 2018-05-09 21:07:50 +0530 | [diff] [blame] | 5010 | bool is_mcast_flow, uint32_t tx_packets, uint32_t tx_bytes, uint32_t rx_packets, uint32_t rx_bytes, |
| 5011 | bool is_ported) |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 5012 | { |
| 5013 | int list_index; |
| 5014 | |
| 5015 | for (list_index = iface_list_first; (list_index < ECM_DB_IFACE_HEIRARCHY_MAX); list_index++) { |
| 5016 | struct ecm_db_iface_instance *ii; |
| 5017 | ecm_db_iface_type_t ii_type; |
| 5018 | char *ii_name; |
| 5019 | struct net_device *dev; |
| 5020 | |
| 5021 | ii = iface_list[list_index]; |
Murat Sezgin | 3d9a764 | 2018-05-15 16:24:09 -0700 | [diff] [blame] | 5022 | ii_type = ecm_db_iface_type_get(ii); |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 5023 | ii_name = ecm_db_interface_type_to_string(ii_type); |
| 5024 | DEBUG_TRACE("list_index: %d, ii: %p, type: %d (%s)\n", list_index, ii, ii_type, ii_name); |
| 5025 | |
| 5026 | /* |
| 5027 | * Locate real device in system |
| 5028 | */ |
| 5029 | dev = dev_get_by_index(&init_net, ecm_db_iface_interface_identifier_get(ii)); |
| 5030 | if (!dev) { |
| 5031 | DEBUG_WARN("Could not locate interface\n"); |
| 5032 | continue; |
| 5033 | } |
| 5034 | DEBUG_TRACE("found dev: %p (%s)\n", dev, dev->name); |
| 5035 | |
Shyam Sunder | bf40d0e | 2015-06-23 15:56:37 +0530 | [diff] [blame] | 5036 | if (likely(!is_mcast_flow)) { |
| 5037 | /* |
| 5038 | * Refresh the bridge forward table entry if the port is a bridge port |
| 5039 | * Note: A bridge port can be of different interface type, e.g VLAN, ethernet. |
| 5040 | * This check, therefore, should be performed for all interface types. |
| 5041 | */ |
Suman Ghosh | 812ad30 | 2018-05-09 21:07:50 +0530 | [diff] [blame] | 5042 | if (is_ported && is_valid_ether_addr(mac_addr) && ecm_front_end_is_bridge_port(dev) && rx_packets) { |
Shyam Sunder | bf40d0e | 2015-06-23 15:56:37 +0530 | [diff] [blame] | 5043 | DEBUG_TRACE("Update bridge fdb entry for mac: %pM\n", mac_addr); |
| 5044 | br_refresh_fdb_entry(dev, mac_addr); |
| 5045 | } |
Selin Dag | 1af781a | 2014-06-10 10:37:54 -0700 | [diff] [blame] | 5046 | } |
| 5047 | |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 5048 | switch (ii_type) { |
| 5049 | struct rtnl_link_stats64 stats; |
| 5050 | |
Gareth Williams | 141d238 | 2014-11-25 11:35:19 -0800 | [diff] [blame] | 5051 | #ifdef ECM_INTERFACE_VLAN_ENABLE |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 5052 | case ECM_DB_IFACE_TYPE_VLAN: |
Radha krishna Simha Jiguru | e9d46fd | 2014-06-03 22:17:19 +0530 | [diff] [blame] | 5053 | DEBUG_INFO("VLAN\n"); |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 5054 | stats.rx_packets = rx_packets; |
| 5055 | stats.rx_bytes = rx_bytes; |
| 5056 | stats.tx_packets = tx_packets; |
| 5057 | stats.tx_bytes = tx_bytes; |
| 5058 | __vlan_dev_update_accel_stats(dev, &stats); |
| 5059 | break; |
Gareth Williams | 141d238 | 2014-11-25 11:35:19 -0800 | [diff] [blame] | 5060 | #endif |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 5061 | case ECM_DB_IFACE_TYPE_BRIDGE: |
| 5062 | DEBUG_INFO("BRIDGE\n"); |
| 5063 | stats.rx_packets = rx_packets; |
| 5064 | stats.rx_bytes = rx_bytes; |
| 5065 | stats.tx_packets = tx_packets; |
| 5066 | stats.tx_bytes = tx_bytes; |
| 5067 | br_dev_update_stats(dev, &stats); |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 5068 | break; |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 5069 | #ifdef ECM_INTERFACE_PPPOE_ENABLE |
Murat Sezgin | a683edd | 2015-01-20 10:48:30 -0800 | [diff] [blame] | 5070 | case ECM_DB_IFACE_TYPE_PPPOE: |
| 5071 | DEBUG_INFO("PPPOE\n"); |
ratheesh kannoth | b1b753a | 2015-09-28 11:17:35 +0530 | [diff] [blame] | 5072 | ppp_update_stats(dev, rx_packets, rx_bytes, tx_packets, tx_bytes, 0, 0, 0, 0); |
Murat Sezgin | a683edd | 2015-01-20 10:48:30 -0800 | [diff] [blame] | 5073 | break; |
| 5074 | #endif |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 5075 | default: |
| 5076 | /* |
| 5077 | * TODO: Extend it accordingly |
| 5078 | */ |
| 5079 | break; |
| 5080 | } |
| 5081 | |
| 5082 | dev_put(dev); |
| 5083 | } |
| 5084 | } |
| 5085 | |
| 5086 | /* |
| 5087 | * ecm_interface_stats_update() |
| 5088 | * Using the interface lists for the given connection, update the interface statistics for each. |
| 5089 | * |
| 5090 | * 'from' here is wrt the connection 'from' side. Likewise with 'to'. |
| 5091 | * TX is wrt what the interface has transmitted. RX is what the interface has received. |
| 5092 | */ |
| 5093 | void ecm_interface_stats_update(struct ecm_db_connection_instance *ci, |
| 5094 | uint32_t from_tx_packets, uint32_t from_tx_bytes, uint32_t from_rx_packets, uint32_t from_rx_bytes, |
| 5095 | uint32_t to_tx_packets, uint32_t to_tx_bytes, uint32_t to_rx_packets, uint32_t to_rx_bytes) |
| 5096 | { |
| 5097 | struct ecm_db_iface_instance *from_ifaces[ECM_DB_IFACE_HEIRARCHY_MAX]; |
| 5098 | struct ecm_db_iface_instance *to_ifaces[ECM_DB_IFACE_HEIRARCHY_MAX]; |
| 5099 | int from_ifaces_first; |
| 5100 | int to_ifaces_first; |
| 5101 | uint8_t mac_addr[ETH_ALEN]; |
Suman Ghosh | 812ad30 | 2018-05-09 21:07:50 +0530 | [diff] [blame] | 5102 | bool is_ported = false; |
| 5103 | uint8_t protocol = ecm_db_connection_protocol_get(ci); |
| 5104 | |
| 5105 | /* |
| 5106 | * Set is_ported flag based on protocol |
| 5107 | */ |
| 5108 | if ((protocol == IPPROTO_UDP) || (protocol == IPPROTO_TCP)) { |
| 5109 | is_ported = true; |
| 5110 | } |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 5111 | |
| 5112 | /* |
| 5113 | * Iterate the 'from' side interfaces and update statistics and state for the real HLOS interfaces |
| 5114 | * from_tx_packets / bytes: the amount transmitted by the 'from' interface |
| 5115 | * from_rx_packets / bytes: the amount received by the 'from' interface |
| 5116 | */ |
| 5117 | DEBUG_INFO("%p: Update from interface stats\n", ci); |
Murat Sezgin | 3d9a764 | 2018-05-15 16:24:09 -0700 | [diff] [blame] | 5118 | from_ifaces_first = ecm_db_connection_interfaces_get_and_ref(ci, from_ifaces, ECM_DB_OBJ_DIR_FROM); |
| 5119 | ecm_db_connection_node_address_get(ci, ECM_DB_OBJ_DIR_FROM, mac_addr); |
Suman Ghosh | 812ad30 | 2018-05-09 21:07:50 +0530 | [diff] [blame] | 5120 | ecm_interface_list_stats_update(from_ifaces_first, from_ifaces, mac_addr, false, from_tx_packets, from_tx_bytes, from_rx_packets, from_rx_bytes, is_ported); |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 5121 | ecm_db_connection_interfaces_deref(from_ifaces, from_ifaces_first); |
| 5122 | |
| 5123 | /* |
| 5124 | * Iterate the 'to' side interfaces and update statistics and state for the real HLOS interfaces |
| 5125 | * to_tx_packets / bytes: the amount transmitted by the 'to' interface |
| 5126 | * to_rx_packets / bytes: the amount received by the 'to' interface |
| 5127 | */ |
| 5128 | DEBUG_INFO("%p: Update to interface stats\n", ci); |
Murat Sezgin | 3d9a764 | 2018-05-15 16:24:09 -0700 | [diff] [blame] | 5129 | to_ifaces_first = ecm_db_connection_interfaces_get_and_ref(ci, to_ifaces, ECM_DB_OBJ_DIR_TO); |
| 5130 | ecm_db_connection_node_address_get(ci, ECM_DB_OBJ_DIR_TO, mac_addr); |
Suman Ghosh | 812ad30 | 2018-05-09 21:07:50 +0530 | [diff] [blame] | 5131 | ecm_interface_list_stats_update(to_ifaces_first, to_ifaces, mac_addr, false, to_tx_packets, to_tx_bytes, to_rx_packets, to_rx_bytes, is_ported); |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 5132 | ecm_db_connection_interfaces_deref(to_ifaces, to_ifaces_first); |
| 5133 | } |
| 5134 | EXPORT_SYMBOL(ecm_interface_stats_update); |
| 5135 | |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 5136 | #ifdef ECM_MULTICAST_ENABLE |
| 5137 | /* |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 5138 | * ecm_interface_multicast_stats_update() |
| 5139 | * Using the interface lists for the given connection, update the interface statistics for each. |
| 5140 | * |
| 5141 | * 'from interface' here is the connection 'from' side. Likewise with 'to interface'. |
| 5142 | * TX is wrt what the interface has transmitted. RX is what the interface has received. |
| 5143 | */ |
| 5144 | void ecm_interface_multicast_stats_update(struct ecm_db_connection_instance *ci, uint32_t from_tx_packets, uint32_t from_tx_bytes, |
| 5145 | uint32_t from_rx_packets, uint32_t from_rx_bytes, uint32_t to_tx_packets, uint32_t to_tx_bytes, |
| 5146 | uint32_t to_rx_packets, uint32_t to_rx_bytes) |
| 5147 | { |
| 5148 | struct ecm_db_iface_instance *from_ifaces[ECM_DB_IFACE_HEIRARCHY_MAX]; |
Shyam Sunder | bf40d0e | 2015-06-23 15:56:37 +0530 | [diff] [blame] | 5149 | struct ecm_db_iface_instance *to_list_single[ECM_DB_IFACE_HEIRARCHY_MAX]; |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 5150 | struct ecm_db_iface_instance *to_ifaces; |
| 5151 | struct ecm_db_iface_instance *ii_temp; |
| 5152 | int from_ifaces_first; |
| 5153 | int *to_ifaces_first; |
| 5154 | int if_index; |
| 5155 | int ret; |
| 5156 | uint8_t mac_addr[ETH_ALEN]; |
Suman Ghosh | 812ad30 | 2018-05-09 21:07:50 +0530 | [diff] [blame] | 5157 | bool is_ported = false; |
| 5158 | uint8_t protocol = ecm_db_connection_protocol_get(ci); |
| 5159 | |
| 5160 | /* |
| 5161 | * Set is_ported flag based on protocol |
| 5162 | */ |
| 5163 | if (protocol == IPPROTO_UDP) { |
| 5164 | is_ported = true; |
| 5165 | } |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 5166 | |
| 5167 | /* |
| 5168 | * Iterate the 'from' side interfaces and update statistics and state for the real HLOS interfaces |
| 5169 | * from_tx_packets / bytes: the amount transmitted by the 'from' interface |
| 5170 | * from_rx_packets / bytes: the amount received by the 'from' interface |
| 5171 | */ |
| 5172 | DEBUG_INFO("%p: Update from interface stats\n", ci); |
Murat Sezgin | 3d9a764 | 2018-05-15 16:24:09 -0700 | [diff] [blame] | 5173 | from_ifaces_first = ecm_db_connection_interfaces_get_and_ref(ci, from_ifaces, ECM_DB_OBJ_DIR_FROM); |
| 5174 | ecm_db_connection_node_address_get(ci, ECM_DB_OBJ_DIR_FROM, mac_addr); |
Suman Ghosh | 812ad30 | 2018-05-09 21:07:50 +0530 | [diff] [blame] | 5175 | ecm_interface_list_stats_update(from_ifaces_first, from_ifaces, mac_addr, false, from_tx_packets, from_tx_bytes, from_rx_packets, from_rx_bytes, is_ported); |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 5176 | ecm_db_connection_interfaces_deref(from_ifaces, from_ifaces_first); |
| 5177 | |
| 5178 | /* |
| 5179 | * Iterate the 'to' side interfaces and update statistics and state for the real HLOS interfaces |
| 5180 | * to_tx_packets / bytes: the amount transmitted by the 'to' interface |
| 5181 | * to_rx_packets / bytes: the amount received by the 'to' interface |
| 5182 | */ |
| 5183 | DEBUG_INFO("%p: Update to interface stats\n", ci); |
| 5184 | |
| 5185 | /* |
| 5186 | * This function allocates the memory for temporary destination interface heirarchies. |
| 5187 | * This memory needs to be free at the end. |
| 5188 | */ |
| 5189 | ret = ecm_db_multicast_connection_to_interfaces_get_and_ref_all(ci, &to_ifaces, &to_ifaces_first); |
| 5190 | if (ret == 0) { |
| 5191 | DEBUG_WARN("%p: Get and ref to all multicast detination interface heirarchies failed\n", ci); |
| 5192 | return; |
| 5193 | } |
| 5194 | |
| 5195 | for (if_index = 0; if_index < ECM_DB_MULTICAST_IF_MAX; if_index++) { |
| 5196 | if (to_ifaces_first[if_index] < ECM_DB_IFACE_HEIRARCHY_MAX) { |
| 5197 | ii_temp = ecm_db_multicast_if_heirarchy_get(to_ifaces, if_index); |
Shyam Sunder | bf40d0e | 2015-06-23 15:56:37 +0530 | [diff] [blame] | 5198 | ecm_db_multicast_copy_if_heirarchy(to_list_single, ii_temp); |
Suman Ghosh | 812ad30 | 2018-05-09 21:07:50 +0530 | [diff] [blame] | 5199 | ecm_interface_list_stats_update(to_ifaces_first[if_index], to_list_single, mac_addr, true, to_tx_packets, to_tx_bytes, to_rx_packets, to_rx_bytes, is_ported); |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 5200 | } |
| 5201 | } |
| 5202 | |
| 5203 | ecm_db_multicast_connection_to_interfaces_deref_all(to_ifaces, to_ifaces_first); |
| 5204 | } |
| 5205 | EXPORT_SYMBOL(ecm_interface_multicast_stats_update); |
| 5206 | #endif |
| 5207 | |
Gareth Williams | adf425f | 2014-05-26 19:29:02 +0100 | [diff] [blame] | 5208 | /* |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 5209 | * ecm_interface_regenerate_connections() |
| 5210 | * Cause regeneration of all connections that are using the specified interface. |
| 5211 | */ |
| 5212 | static void ecm_interface_regenerate_connections(struct ecm_db_iface_instance *ii) |
| 5213 | { |
Gareth Williams | b590389 | 2015-03-20 15:13:07 +0000 | [diff] [blame] | 5214 | #ifdef ECM_DB_XREF_ENABLE |
Murat Sezgin | 3d9a764 | 2018-05-15 16:24:09 -0700 | [diff] [blame] | 5215 | int dir; |
| 5216 | struct ecm_db_connection_instance *ci[ECM_DB_OBJ_DIR_MAX]; |
Gareth Williams | a439096 | 2015-08-26 12:51:31 +0100 | [diff] [blame] | 5217 | struct ecm_db_connection_instance *ci_mcast __attribute__ ((unused)); |
Gareth Williams | b590389 | 2015-03-20 15:13:07 +0000 | [diff] [blame] | 5218 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 5219 | |
| 5220 | DEBUG_TRACE("Regenerate connections using interface: %p\n", ii); |
| 5221 | |
Gareth Williams | b590389 | 2015-03-20 15:13:07 +0000 | [diff] [blame] | 5222 | #ifndef ECM_DB_XREF_ENABLE |
| 5223 | /* |
| 5224 | * An interface has changed, re-generate the connections to ensure all state is updated. |
| 5225 | */ |
Tushar Mathur | d38cacd | 2015-07-28 12:19:10 +0530 | [diff] [blame] | 5226 | ecm_db_regeneration_needed(); |
Gareth Williams | b590389 | 2015-03-20 15:13:07 +0000 | [diff] [blame] | 5227 | #else |
Murat Sezgin | 3d9a764 | 2018-05-15 16:24:09 -0700 | [diff] [blame] | 5228 | for (dir = 0; dir < ECM_DB_OBJ_DIR_MAX; dir++) { |
| 5229 | ci[dir] = ecm_db_iface_connections_get_and_ref_first(ii, dir); |
| 5230 | } |
| 5231 | |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 5232 | /* |
Gareth Williams | a439096 | 2015-08-26 12:51:31 +0100 | [diff] [blame] | 5233 | * If the interface has NO connections then we re-generate all. |
| 5234 | */ |
Murat Sezgin | 3d9a764 | 2018-05-15 16:24:09 -0700 | [diff] [blame] | 5235 | if (!ci[ECM_DB_OBJ_DIR_FROM] && !ci[ECM_DB_OBJ_DIR_TO] && !ci[ECM_DB_OBJ_DIR_FROM_NAT] && !ci[ECM_DB_OBJ_DIR_TO_NAT]) { |
Gareth Williams | a439096 | 2015-08-26 12:51:31 +0100 | [diff] [blame] | 5236 | ecm_db_regeneration_needed(); |
| 5237 | DEBUG_TRACE("%p: Regenerate (ALL) COMPLETE\n", ii); |
| 5238 | return; |
| 5239 | } |
| 5240 | |
Murat Sezgin | 3d9a764 | 2018-05-15 16:24:09 -0700 | [diff] [blame] | 5241 | for (dir = 0; dir < ECM_DB_OBJ_DIR_MAX; dir++) { |
| 5242 | /* |
| 5243 | * Re-generate all connections associated with this interface |
| 5244 | */ |
| 5245 | DEBUG_TRACE("%p: Regenerate %s direction connections\n", ii, ecm_db_obj_dir_strings[dir]); |
| 5246 | while (ci[dir]) { |
| 5247 | struct ecm_db_connection_instance *cin; |
| 5248 | cin = ecm_db_connection_iface_get_and_ref_next(ci[dir], dir); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 5249 | |
Murat Sezgin | 3d9a764 | 2018-05-15 16:24:09 -0700 | [diff] [blame] | 5250 | DEBUG_TRACE("%p: Regenerate: %p", ii, ci[dir]); |
| 5251 | ecm_db_connection_regenerate(ci[dir]); |
| 5252 | ecm_db_connection_deref(ci[dir]); |
| 5253 | ci[dir] = cin; |
| 5254 | } |
Gareth Williams | a439096 | 2015-08-26 12:51:31 +0100 | [diff] [blame] | 5255 | } |
| 5256 | |
| 5257 | #ifdef ECM_MULTICAST_ENABLE |
| 5258 | /* |
| 5259 | * Multicasts would not have recorded in the lists above. |
| 5260 | * Our only way to re-gen those is to iterate all multicasts. |
| 5261 | * GGG TODO This will be optimised in a future release. |
| 5262 | */ |
| 5263 | ci_mcast = ecm_db_connections_get_and_ref_first(); |
| 5264 | while (ci_mcast) { |
| 5265 | struct ecm_db_connection_instance *cin; |
| 5266 | |
| 5267 | /* |
| 5268 | * Multicast and NOT flagged for re-gen? |
| 5269 | */ |
| 5270 | if (ecm_db_multicast_connection_to_interfaces_set_check(ci_mcast) |
| 5271 | && ecm_db_connection_regeneration_required_peek(ci_mcast)) { |
Xiaoping Fan | ed6d37e | 2015-09-17 14:13:47 -0700 | [diff] [blame] | 5272 | ecm_db_connection_regenerate(ci_mcast); |
Gareth Williams | a439096 | 2015-08-26 12:51:31 +0100 | [diff] [blame] | 5273 | } |
| 5274 | |
| 5275 | cin = ecm_db_connection_get_and_ref_next(ci_mcast); |
| 5276 | ecm_db_connection_deref(ci_mcast); |
| 5277 | ci_mcast = cin; |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 5278 | } |
Gareth Williams | b590389 | 2015-03-20 15:13:07 +0000 | [diff] [blame] | 5279 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 5280 | |
Gareth Williams | a439096 | 2015-08-26 12:51:31 +0100 | [diff] [blame] | 5281 | #endif |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 5282 | DEBUG_TRACE("%p: Regenerate COMPLETE\n", ii); |
| 5283 | } |
| 5284 | |
| 5285 | /* |
| 5286 | * ecm_interface_dev_regenerate_connections() |
| 5287 | * Cause regeneration of all connections that are using the specified interface. |
| 5288 | */ |
Tushar Mathur | cccbf28 | 2015-01-13 01:22:44 +0530 | [diff] [blame] | 5289 | void ecm_interface_dev_regenerate_connections(struct net_device *dev) |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 5290 | { |
| 5291 | struct ecm_db_iface_instance *ii; |
| 5292 | |
| 5293 | DEBUG_INFO("Regenerate connections for: %p (%s)\n", dev, dev->name); |
| 5294 | |
| 5295 | /* |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 5296 | * If the interface is known to us then we will get it returned by this |
| 5297 | * function and process it accordingly. |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 5298 | */ |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 5299 | ii = ecm_db_iface_find_and_ref_by_interface_identifier(dev->ifindex); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 5300 | if (!ii) { |
| 5301 | DEBUG_WARN("%p: No interface instance could be established for this dev\n", dev); |
| 5302 | return; |
| 5303 | } |
| 5304 | ecm_interface_regenerate_connections(ii); |
| 5305 | DEBUG_TRACE("%p: Regenerate for %p: COMPLETE\n", dev, ii); |
| 5306 | ecm_db_iface_deref(ii); |
| 5307 | } |
| 5308 | |
| 5309 | /* |
Suman Ghosh | 7a26171 | 2016-01-12 21:42:55 +0530 | [diff] [blame] | 5310 | * ecm_interface_defunct_connections() |
| 5311 | * Cause defunct of all connections that are using the specified interface. |
| 5312 | */ |
| 5313 | static void ecm_interface_defunct_connections(struct ecm_db_iface_instance *ii) |
| 5314 | { |
| 5315 | #ifndef ECM_DB_XREF_ENABLE |
| 5316 | ecm_db_connection_defunct_all(); |
| 5317 | #else |
Murat Sezgin | 3d9a764 | 2018-05-15 16:24:09 -0700 | [diff] [blame] | 5318 | int dir; |
| 5319 | struct ecm_db_connection_instance *ci[ECM_DB_OBJ_DIR_MAX]; |
Suman Ghosh | 7a26171 | 2016-01-12 21:42:55 +0530 | [diff] [blame] | 5320 | struct ecm_db_connection_instance *ci_mcast __attribute__ ((unused)); |
| 5321 | |
| 5322 | DEBUG_TRACE("defunct connections using interface: %p\n", ii); |
| 5323 | |
Murat Sezgin | 3d9a764 | 2018-05-15 16:24:09 -0700 | [diff] [blame] | 5324 | for (dir = 0; dir < ECM_DB_OBJ_DIR_MAX; dir++) { |
| 5325 | ci[dir] = ecm_db_iface_connections_get_and_ref_first(ii, dir); |
| 5326 | } |
Suman Ghosh | 7a26171 | 2016-01-12 21:42:55 +0530 | [diff] [blame] | 5327 | |
| 5328 | /* |
Bhaskar Valaboju | 35d2a8b | 2018-01-16 18:35:10 +0530 | [diff] [blame] | 5329 | * Defunct ALL if all the four connection instances are NULL |
| 5330 | */ |
Murat Sezgin | 3d9a764 | 2018-05-15 16:24:09 -0700 | [diff] [blame] | 5331 | if (!ci[ECM_DB_OBJ_DIR_FROM] && !ci[ECM_DB_OBJ_DIR_TO] && !ci[ECM_DB_OBJ_DIR_FROM_NAT] && !ci[ECM_DB_OBJ_DIR_TO_NAT]) { |
| 5332 | ecm_db_regeneration_needed(); |
| 5333 | DEBUG_TRACE("%p: Regenerate (ALL) COMPLETE\n", ii); |
Bhaskar Valaboju | 35d2a8b | 2018-01-16 18:35:10 +0530 | [diff] [blame] | 5334 | return; |
| 5335 | } |
| 5336 | |
| 5337 | /* |
Suman Ghosh | 7a26171 | 2016-01-12 21:42:55 +0530 | [diff] [blame] | 5338 | * Defunct all connections associated with this interface |
| 5339 | */ |
Murat Sezgin | 3d9a764 | 2018-05-15 16:24:09 -0700 | [diff] [blame] | 5340 | for (dir = 0; dir < ECM_DB_OBJ_DIR_MAX; dir++) { |
| 5341 | DEBUG_TRACE("%p: Defunct %s direction connections\n", ii, ecm_db_obj_dir_strings[dir]); |
| 5342 | while (ci[dir]) { |
| 5343 | struct ecm_db_connection_instance *cin; |
| 5344 | cin = ecm_db_connection_iface_get_and_ref_next(ci[dir], dir); |
Suman Ghosh | 7a26171 | 2016-01-12 21:42:55 +0530 | [diff] [blame] | 5345 | |
Murat Sezgin | 3d9a764 | 2018-05-15 16:24:09 -0700 | [diff] [blame] | 5346 | DEBUG_TRACE("%p: Defunct: %p", ii, ci[dir]); |
| 5347 | ecm_db_connection_make_defunct(ci[dir]); |
| 5348 | ecm_db_connection_deref(ci[dir]); |
| 5349 | ci[dir] = cin; |
| 5350 | } |
Suman Ghosh | 7a26171 | 2016-01-12 21:42:55 +0530 | [diff] [blame] | 5351 | } |
| 5352 | #endif |
| 5353 | DEBUG_TRACE("%p: Defunct COMPLETE\n", ii); |
| 5354 | } |
| 5355 | |
| 5356 | /* |
| 5357 | * ecm_interface_dev_defunct_connections() |
| 5358 | * Cause defunct of all connections that are using the specified interface. |
| 5359 | */ |
| 5360 | void ecm_interface_dev_defunct_connections(struct net_device *dev) |
| 5361 | { |
| 5362 | struct ecm_db_iface_instance *ii; |
| 5363 | |
| 5364 | DEBUG_INFO("defunct connections for: %p (%s)\n", dev, dev->name); |
| 5365 | |
| 5366 | /* |
| 5367 | * If the interface is known to us then we will get it returned by this |
| 5368 | * function and process it accordingly. |
| 5369 | */ |
| 5370 | ii = ecm_db_iface_find_and_ref_by_interface_identifier(dev->ifindex); |
| 5371 | if (!ii) { |
| 5372 | DEBUG_WARN("%p: No interface instance could be established for this dev\n", dev); |
| 5373 | return; |
| 5374 | } |
| 5375 | ecm_interface_defunct_connections(ii); |
| 5376 | DEBUG_TRACE("%p: defunct for %p: COMPLETE\n", dev, ii); |
| 5377 | ecm_db_iface_deref(ii); |
| 5378 | } |
| 5379 | |
| 5380 | /* |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 5381 | * ecm_interface_mtu_change() |
| 5382 | * MTU of interface has changed |
| 5383 | */ |
| 5384 | static void ecm_interface_mtu_change(struct net_device *dev) |
| 5385 | { |
| 5386 | int mtu; |
| 5387 | struct ecm_db_iface_instance *ii; |
| 5388 | |
| 5389 | mtu = dev->mtu; |
| 5390 | DEBUG_INFO("%p (%s): MTU Change to: %d\n", dev, dev->name, mtu); |
| 5391 | |
| 5392 | /* |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 5393 | * Find the interface for the given device. |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 5394 | */ |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 5395 | ii = ecm_db_iface_find_and_ref_by_interface_identifier(dev->ifindex); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 5396 | if (!ii) { |
| 5397 | DEBUG_WARN("%p: No interface instance could be established for this dev\n", dev); |
| 5398 | return; |
| 5399 | } |
| 5400 | |
| 5401 | /* |
| 5402 | * Change the mtu |
| 5403 | */ |
| 5404 | ecm_db_iface_mtu_reset(ii, mtu); |
| 5405 | DEBUG_TRACE("%p (%s): MTU Changed to: %d\n", dev, dev->name, mtu); |
Tushar Mathur | ad534d6 | 2015-06-10 18:37:52 +0530 | [diff] [blame] | 5406 | if (netif_is_bond_slave(dev)) { |
| 5407 | struct net_device *master = NULL; |
| 5408 | master = ecm_interface_get_and_hold_dev_master(dev); |
| 5409 | DEBUG_ASSERT(master, "Expected a master\n"); |
| 5410 | ecm_interface_dev_regenerate_connections(master); |
| 5411 | dev_put(master); |
| 5412 | } else { |
| 5413 | ecm_interface_regenerate_connections(ii); |
| 5414 | } |
| 5415 | |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 5416 | DEBUG_TRACE("%p: Regenerate for %p: COMPLETE\n", dev, ii); |
| 5417 | ecm_db_iface_deref(ii); |
| 5418 | } |
| 5419 | |
| 5420 | /* |
| 5421 | * ecm_interface_netdev_notifier_callback() |
| 5422 | * Netdevice notifier callback to inform us of change of state of a netdevice |
| 5423 | */ |
| 5424 | static int ecm_interface_netdev_notifier_callback(struct notifier_block *this, unsigned long event, void *ptr) |
| 5425 | { |
Stephen Wang | 69379c3 | 2015-02-04 18:37:13 -0800 | [diff] [blame] | 5426 | #if (LINUX_VERSION_CODE <= KERNEL_VERSION(3, 10, 0)) |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 5427 | struct net_device *dev __attribute__ ((unused)) = (struct net_device *)ptr; |
Stephen Wang | 69379c3 | 2015-02-04 18:37:13 -0800 | [diff] [blame] | 5428 | #else |
| 5429 | struct net_device *dev = netdev_notifier_info_to_dev(ptr); |
| 5430 | #endif |
Tushar Mathur | ad534d6 | 2015-06-10 18:37:52 +0530 | [diff] [blame] | 5431 | struct net_device *master = NULL; |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 5432 | |
| 5433 | DEBUG_INFO("Net device notifier for: %p, name: %s, event: %lx\n", dev, dev->name, event); |
| 5434 | |
| 5435 | switch (event) { |
| 5436 | case NETDEV_DOWN: |
| 5437 | DEBUG_INFO("Net device: %p, DOWN\n", dev); |
Tushar Mathur | ad534d6 | 2015-06-10 18:37:52 +0530 | [diff] [blame] | 5438 | if (netif_is_bond_slave(dev)) { |
| 5439 | master = ecm_interface_get_and_hold_dev_master(dev); |
| 5440 | DEBUG_ASSERT(master, "Expected a master\n"); |
Murat Sezgin | a52ce61 | 2017-11-14 17:08:08 -0800 | [diff] [blame] | 5441 | ecm_interface_dev_defunct_connections(master); |
Tushar Mathur | ad534d6 | 2015-06-10 18:37:52 +0530 | [diff] [blame] | 5442 | dev_put(master); |
| 5443 | } else { |
Murat Sezgin | a52ce61 | 2017-11-14 17:08:08 -0800 | [diff] [blame] | 5444 | ecm_interface_dev_defunct_connections(dev); |
Tushar Mathur | ad534d6 | 2015-06-10 18:37:52 +0530 | [diff] [blame] | 5445 | } |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 5446 | break; |
| 5447 | |
| 5448 | case NETDEV_CHANGE: |
| 5449 | DEBUG_INFO("Net device: %p, CHANGE\n", dev); |
| 5450 | if (!netif_carrier_ok(dev)) { |
| 5451 | DEBUG_INFO("Net device: %p, CARRIER BAD\n", dev); |
Tushar Mathur | 933907c | 2014-06-24 17:06:14 +0530 | [diff] [blame] | 5452 | if (netif_is_bond_slave(dev)) { |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 5453 | master = ecm_interface_get_and_hold_dev_master(dev); |
Bhaskar Valaboju | 5cbdf81 | 2018-02-21 09:59:24 +0530 | [diff] [blame] | 5454 | DEBUG_ASSERT(master, "Expected a master.\n"); |
| 5455 | ecm_interface_dev_defunct_connections(master); |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 5456 | dev_put(master); |
Tushar Mathur | 933907c | 2014-06-24 17:06:14 +0530 | [diff] [blame] | 5457 | } else { |
Bhaskar Valaboju | 5cbdf81 | 2018-02-21 09:59:24 +0530 | [diff] [blame] | 5458 | ecm_interface_dev_defunct_connections(dev); |
Tushar Mathur | 933907c | 2014-06-24 17:06:14 +0530 | [diff] [blame] | 5459 | } |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 5460 | } |
| 5461 | break; |
| 5462 | |
| 5463 | case NETDEV_CHANGEMTU: |
| 5464 | DEBUG_INFO("Net device: %p, MTU CHANGE\n", dev); |
| 5465 | ecm_interface_mtu_change(dev); |
| 5466 | break; |
| 5467 | |
| 5468 | default: |
| 5469 | DEBUG_TRACE("Net device: %p, UNHANDLED: %lx\n", dev, event); |
| 5470 | break; |
| 5471 | } |
| 5472 | |
| 5473 | return NOTIFY_DONE; |
| 5474 | } |
| 5475 | |
| 5476 | /* |
Murat Sezgin | 9304d47 | 2017-04-14 10:16:52 -0700 | [diff] [blame] | 5477 | * ecm_interface_node_connections_defunct() |
| 5478 | * Defunct the connections on this node. |
Murat Sezgin | a205b04 | 2016-07-19 14:18:14 -0700 | [diff] [blame] | 5479 | */ |
Murat Sezgin | 9304d47 | 2017-04-14 10:16:52 -0700 | [diff] [blame] | 5480 | void ecm_interface_node_connections_defunct(uint8_t *mac) |
Murat Sezgin | a205b04 | 2016-07-19 14:18:14 -0700 | [diff] [blame] | 5481 | { |
Murat Sezgin | a5f3de1 | 2016-08-02 17:29:30 -0700 | [diff] [blame] | 5482 | struct ecm_db_node_instance *ni = NULL; |
Murat Sezgin | a205b04 | 2016-07-19 14:18:14 -0700 | [diff] [blame] | 5483 | |
| 5484 | if (unlikely(!mac)) { |
| 5485 | DEBUG_WARN("mac address is null\n"); |
| 5486 | return; |
| 5487 | } |
| 5488 | |
Murat Sezgin | a5f3de1 | 2016-08-02 17:29:30 -0700 | [diff] [blame] | 5489 | ni = ecm_db_node_chain_get_and_ref_first(mac); |
| 5490 | while (ni) { |
| 5491 | struct ecm_db_node_instance *nin; |
Murat Sezgin | a205b04 | 2016-07-19 14:18:14 -0700 | [diff] [blame] | 5492 | |
Murat Sezgin | a5f3de1 | 2016-08-02 17:29:30 -0700 | [diff] [blame] | 5493 | if (ecm_db_node_is_mac_addr_equal(ni, mac)) { |
Murat Sezgin | 3d9a764 | 2018-05-15 16:24:09 -0700 | [diff] [blame] | 5494 | int dir; |
| 5495 | for (dir = 0; dir < ECM_DB_OBJ_DIR_MAX; dir++) { |
| 5496 | ecm_db_traverse_node_connection_list_and_defunct(ni, dir); |
| 5497 | } |
Murat Sezgin | a5f3de1 | 2016-08-02 17:29:30 -0700 | [diff] [blame] | 5498 | } |
| 5499 | |
| 5500 | /* |
| 5501 | * Get next node in the chain |
| 5502 | */ |
| 5503 | nin = ecm_db_node_chain_get_and_ref_next(ni); |
| 5504 | ecm_db_node_deref(ni); |
| 5505 | ni = nin; |
Murat Sezgin | a205b04 | 2016-07-19 14:18:14 -0700 | [diff] [blame] | 5506 | } |
Murat Sezgin | a205b04 | 2016-07-19 14:18:14 -0700 | [diff] [blame] | 5507 | } |
Murat Sezgin | 9304d47 | 2017-04-14 10:16:52 -0700 | [diff] [blame] | 5508 | EXPORT_SYMBOL(ecm_interface_node_connections_defunct); |
Murat Sezgin | a205b04 | 2016-07-19 14:18:14 -0700 | [diff] [blame] | 5509 | |
| 5510 | /* |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 5511 | * struct notifier_block ecm_interface_netdev_notifier |
| 5512 | * Registration for net device changes of state. |
| 5513 | */ |
| 5514 | static struct notifier_block ecm_interface_netdev_notifier __read_mostly = { |
| 5515 | .notifier_call = ecm_interface_netdev_notifier_callback, |
| 5516 | }; |
Murat Sezgin | a205b04 | 2016-07-19 14:18:14 -0700 | [diff] [blame] | 5517 | |
Murat Sezgin | 8c34582 | 2015-05-27 15:35:38 -0700 | [diff] [blame] | 5518 | #if defined(ECM_DB_XREF_ENABLE) && defined(ECM_BAND_STEERING_ENABLE) |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 5519 | /* |
ratheesh kannoth | 37e35b0 | 2015-03-26 11:25:02 +0530 | [diff] [blame] | 5520 | * ecm_interfae_node_br_fdb_notify_event() |
| 5521 | * This is a call back for "bridge fdb update event/ageing timer expire |
| 5522 | * event". |
| 5523 | */ |
| 5524 | static int ecm_interface_node_br_fdb_notify_event(struct notifier_block *nb, |
| 5525 | unsigned long val, |
| 5526 | void *data) |
| 5527 | { |
| 5528 | uint8_t *mac = (uint8_t *)data; |
ratheesh kannoth | 37e35b0 | 2015-03-26 11:25:02 +0530 | [diff] [blame] | 5529 | |
Murat Sezgin | 0447003 | 2017-07-07 14:53:32 -0700 | [diff] [blame] | 5530 | if (ECM_FRONT_END_TYPE_NSS == ecm_front_end_type_get()) { |
| 5531 | DEBUG_INFO("FDB updated for node %pM\n", mac); |
| 5532 | ecm_interface_node_connections_defunct(mac); |
| 5533 | } |
ratheesh kannoth | 37e35b0 | 2015-03-26 11:25:02 +0530 | [diff] [blame] | 5534 | |
| 5535 | return NOTIFY_DONE; |
| 5536 | } |
| 5537 | |
| 5538 | static struct notifier_block ecm_interface_node_br_fdb_update_nb = { |
| 5539 | .notifier_call = ecm_interface_node_br_fdb_notify_event, |
| 5540 | }; |
Xiaoping Fan | 8fe3edd | 2016-06-22 16:03:17 -0700 | [diff] [blame] | 5541 | |
| 5542 | static int ecm_interface_node_br_fdb_delete_event(struct notifier_block *nb, |
| 5543 | unsigned long event, |
| 5544 | void *ctx) |
| 5545 | { |
| 5546 | struct br_fdb_event *fe = (struct br_fdb_event *)ctx; |
| 5547 | |
| 5548 | if ((event != BR_FDB_EVENT_DEL) || fe->is_local) { |
| 5549 | DEBUG_WARN("local fdb or not deleting event, ignore\n"); |
| 5550 | return NOTIFY_DONE; |
| 5551 | } |
| 5552 | |
| 5553 | return ecm_interface_node_br_fdb_notify_event(nb, event, fe->addr); |
| 5554 | } |
| 5555 | |
| 5556 | static struct notifier_block ecm_interface_node_br_fdb_delete_nb = { |
| 5557 | .notifier_call = ecm_interface_node_br_fdb_delete_event, |
| 5558 | }; |
Murat Sezgin | 8c34582 | 2015-05-27 15:35:38 -0700 | [diff] [blame] | 5559 | #endif |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 5560 | |
| 5561 | #ifdef ECM_MULTICAST_ENABLE |
| 5562 | /* |
| 5563 | * ecm_interface_multicast_find_outdated_iface_instances() |
| 5564 | * |
| 5565 | * Called in the case of Routing/Bridging Multicast update events. |
| 5566 | * |
| 5567 | * This function takes a list of ifindex for the connection which was received |
| 5568 | * from MFC or bridge snooper, compares it against the existing list of interfaces |
| 5569 | * in the DB connection, and extracts the list of those interfaces that have left |
| 5570 | * the multicast group. |
| 5571 | * |
| 5572 | * ci A DB connection instance. |
| 5573 | * mc_updates Part of return Information. The function will mark the index of those |
| 5574 | * interfaces in the DB connection 'to_mcast_interfaces' array that have |
| 5575 | * left the group, in the mc_updates->if_leave_idx array. The caller uses this |
| 5576 | * information to delete those outdated interface heirarchies from the |
| 5577 | * connection. |
| 5578 | * is_bridged True if the function called due to bridge multicast snooper update event. |
| 5579 | * dst_dev Holds the netdevice ifindex number of the new list of interfaces as reported |
| 5580 | * by the update from MFC or Bridge snooper. |
| 5581 | * max_to_dev Size of the array 'dst_dev' |
| 5582 | * |
| 5583 | * Return true if outdated interfaces found |
| 5584 | */ |
| 5585 | static bool ecm_interface_multicast_find_outdated_iface_instances(struct ecm_db_connection_instance *ci, struct ecm_multicast_if_update *mc_updates, |
| 5586 | uint32_t flags, bool is_br_snooper, uint32_t *mc_dst_if_index, uint32_t max_to_dev) |
| 5587 | { |
| 5588 | struct ecm_db_iface_instance *mc_ifaces; |
| 5589 | struct ecm_db_iface_instance *ii_temp; |
| 5590 | struct ecm_db_iface_instance *ii_single; |
| 5591 | struct ecm_db_iface_instance **ifaces; |
| 5592 | struct ecm_db_iface_instance *to_iface; |
| 5593 | int32_t *to_iface_first; |
| 5594 | int32_t *mc_ifaces_first; |
| 5595 | uint32_t *dst_if_index; |
| 5596 | ecm_db_iface_type_t ii_type; |
| 5597 | int32_t heirarchy_index; |
| 5598 | int32_t if_index; |
| 5599 | int32_t if_cnt = 0; |
| 5600 | int found = 0; |
| 5601 | int ii; |
| 5602 | int ret; |
| 5603 | int32_t ifaces_identifier; |
| 5604 | |
| 5605 | ret = ecm_db_multicast_connection_to_interfaces_get_and_ref_all(ci, &mc_ifaces, &mc_ifaces_first); |
| 5606 | if (ret == 0) { |
| 5607 | DEBUG_WARN("%p: multicast interfaces ref fail!\n", ci); |
| 5608 | return false; |
| 5609 | } |
| 5610 | |
| 5611 | /* |
| 5612 | * Loop through the current interface list in the DB |
| 5613 | * connection 'to_mcast_interfaces' array |
| 5614 | */ |
| 5615 | for (heirarchy_index = 0; heirarchy_index < ECM_DB_MULTICAST_IF_MAX; heirarchy_index++) { |
| 5616 | found = 0; |
| 5617 | to_iface_first = ecm_db_multicast_if_first_get_at_index(mc_ifaces_first, heirarchy_index); |
| 5618 | |
| 5619 | /* |
| 5620 | * Invalid interface entry, skip |
| 5621 | */ |
| 5622 | if (*to_iface_first == ECM_DB_IFACE_HEIRARCHY_MAX) { |
| 5623 | continue; |
| 5624 | } |
| 5625 | |
| 5626 | ii_temp = ecm_db_multicast_if_heirarchy_get(mc_ifaces, heirarchy_index); |
| 5627 | ii_single = ecm_db_multicast_if_instance_get_at_index(ii_temp, ECM_DB_IFACE_HEIRARCHY_MAX - 1); |
| 5628 | ifaces = (struct ecm_db_iface_instance **)ii_single; |
| 5629 | to_iface = *ifaces; |
Murat Sezgin | 3d9a764 | 2018-05-15 16:24:09 -0700 | [diff] [blame] | 5630 | ii_type = ecm_db_iface_type_get(to_iface); |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 5631 | |
| 5632 | /* |
| 5633 | * If the update was received from bridge snooper, do not consider entries in the |
| 5634 | * interface list that are not part of a bridge. |
| 5635 | */ |
| 5636 | if (is_br_snooper && (ii_type != ECM_DB_IFACE_TYPE_BRIDGE)) { |
| 5637 | continue; |
| 5638 | } |
| 5639 | |
| 5640 | /* |
| 5641 | * If the update was received from MFC, do not consider entries in the |
| 5642 | * interface list that are part of a bridge. The bridge entries will be |
| 5643 | * taken care by the Bridge Snooper Callback |
| 5644 | */ |
| 5645 | if (ii_type == ECM_DB_IFACE_TYPE_BRIDGE) { |
| 5646 | if (!is_br_snooper && !(flags & ECM_DB_MULTICAST_CONNECTION_BRIDGE_DEV_SET_FLAG)) { |
| 5647 | continue; |
| 5648 | } |
| 5649 | } |
| 5650 | |
| 5651 | /* |
| 5652 | * Try to find a match in the newly received interface list, for any of |
| 5653 | * the interface instance in the heirarchy. If found, it means that this |
| 5654 | * interface has not left the group. If not found, it means that this |
| 5655 | * interface has left the group. |
| 5656 | */ |
| 5657 | for (ii = ECM_DB_IFACE_HEIRARCHY_MAX - 1; ii >= *to_iface_first; ii--) { |
| 5658 | ii_single = ecm_db_multicast_if_instance_get_at_index(ii_temp, ii); |
| 5659 | ifaces = (struct ecm_db_iface_instance **)ii_single; |
| 5660 | to_iface = *ifaces; |
| 5661 | |
Murat Sezgin | 3d9a764 | 2018-05-15 16:24:09 -0700 | [diff] [blame] | 5662 | ii_type = ecm_db_iface_type_get(to_iface); |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 5663 | ifaces_identifier = ecm_db_iface_interface_identifier_get(to_iface); |
| 5664 | for (if_index = 0; if_index < max_to_dev; if_index++) { |
| 5665 | dst_if_index = ecm_db_multicast_if_num_get_at_index(mc_dst_if_index, if_index); |
| 5666 | if (*dst_if_index == ifaces_identifier) { |
| 5667 | found = 1; |
| 5668 | break; |
| 5669 | } |
| 5670 | } |
| 5671 | if (found) { |
| 5672 | break; |
| 5673 | } |
| 5674 | } |
| 5675 | |
| 5676 | /* |
| 5677 | * We did not find a match for the interface in the present list. So mark |
| 5678 | * if as one that has left the group. |
| 5679 | */ |
| 5680 | if (!found) { |
| 5681 | if_cnt++; |
| 5682 | mc_updates->if_leave_idx[heirarchy_index] = 1; |
| 5683 | } |
| 5684 | } |
| 5685 | |
| 5686 | ecm_db_multicast_connection_to_interfaces_deref_all(mc_ifaces, mc_ifaces_first); |
| 5687 | mc_updates->if_leave_cnt = if_cnt; |
| 5688 | return (if_cnt > 0); |
| 5689 | } |
| 5690 | |
| 5691 | /* |
| 5692 | * ecm_interface_multicast_find_new_iface_instances() |
| 5693 | * |
| 5694 | * Called in the case of Routing/Bridging Multicast update events. |
| 5695 | * |
| 5696 | * This function takes a list of ifindex for the connection which was received |
| 5697 | * from MFC or bridge snooper, compares it against the existing list of interfaces |
| 5698 | * in the DB connection, and extracts the list of the new joinees for the multicast |
| 5699 | * group. |
| 5700 | * |
| 5701 | * ci A DB connection instance. |
| 5702 | * mc_updates Part of return Information. The function will mark the index of those |
| 5703 | * interfaces in the 'dst_dev' array that have joined the group, in the |
| 5704 | * mc_updates->if_join_idx array. The caller uses this information to add the new |
| 5705 | * interface heirarchies into the connection. |
| 5706 | * dst_dev Holds the netdevice ifindex number of the new list of interfaces as reported |
| 5707 | * by the update from MFC or Bridge snooper. |
| 5708 | * max_to_dev Size of the array 'dst_dev' |
| 5709 | * |
| 5710 | * Return true if new joinees found |
| 5711 | */ |
| 5712 | static bool ecm_interface_multicast_find_new_iface_instances(struct ecm_db_connection_instance *ci, |
| 5713 | struct ecm_multicast_if_update *mc_updates, uint32_t *mc_dst_if_index, uint32_t max_to_dev) |
| 5714 | { |
| 5715 | struct ecm_db_iface_instance *mc_ifaces; |
| 5716 | struct ecm_db_iface_instance *ii_temp; |
| 5717 | struct ecm_db_iface_instance *ii_single; |
| 5718 | struct ecm_db_iface_instance **ifaces; |
| 5719 | int32_t *mc_ifaces_first; |
| 5720 | int32_t *to_list_first; |
| 5721 | int32_t heirarchy_index; |
| 5722 | int32_t if_index; |
| 5723 | int32_t if_cnt = 0; |
| 5724 | int found = 0; |
| 5725 | int ii; |
| 5726 | int ret; |
| 5727 | uint32_t *dst_if_index; |
| 5728 | int32_t ifaces_identifier; |
| 5729 | struct ecm_db_iface_instance *to_list; |
| 5730 | |
| 5731 | ret = ecm_db_multicast_connection_to_interfaces_get_and_ref_all(ci, &mc_ifaces, &mc_ifaces_first); |
| 5732 | if (ret == 0) { |
| 5733 | DEBUG_WARN("%p: multicast interfaces ref fail!\n", ci); |
| 5734 | return false; |
| 5735 | } |
| 5736 | |
| 5737 | /* |
| 5738 | * Loop through the new interface list 'dst_dev' |
| 5739 | */ |
| 5740 | for (if_index = 0; if_index < max_to_dev; if_index++) { |
| 5741 | found = 0; |
| 5742 | dst_if_index = ecm_db_multicast_if_num_get_at_index(mc_dst_if_index, if_index); |
| 5743 | if (*dst_if_index == 0) { |
| 5744 | continue; |
| 5745 | } |
| 5746 | |
| 5747 | for (heirarchy_index = 0; heirarchy_index < ECM_DB_MULTICAST_IF_MAX ; heirarchy_index++) { |
| 5748 | to_list_first = ecm_db_multicast_if_first_get_at_index(mc_ifaces_first, heirarchy_index); |
| 5749 | |
| 5750 | /* |
| 5751 | * Invalid interface entry, skip |
| 5752 | */ |
| 5753 | if (*to_list_first == ECM_DB_IFACE_HEIRARCHY_MAX) { |
| 5754 | continue; |
| 5755 | } |
| 5756 | |
| 5757 | ii_temp = ecm_db_multicast_if_heirarchy_get(mc_ifaces, heirarchy_index); |
| 5758 | |
| 5759 | /* |
| 5760 | * Try to find a match for this ifindex (dst_dev[if_index]), in any of the |
| 5761 | * interface instance in the heirarchy. If not found, it means that this |
| 5762 | * ifindex has joined the group. If found, it means that this ifindex was |
| 5763 | * already part of the list of destination interfaces. |
| 5764 | */ |
| 5765 | for (ii = ECM_DB_IFACE_HEIRARCHY_MAX - 1; ii >= *to_list_first; ii--) { |
| 5766 | ii_single = ecm_db_multicast_if_instance_get_at_index(ii_temp, ii); |
| 5767 | ifaces = (struct ecm_db_iface_instance **)ii_single; |
| 5768 | to_list = *ifaces; |
| 5769 | ifaces_identifier = ecm_db_iface_interface_identifier_get(to_list); |
| 5770 | if (*dst_if_index == ifaces_identifier) { |
| 5771 | found = 1; |
| 5772 | break; |
| 5773 | } |
| 5774 | } |
| 5775 | |
| 5776 | if (found) { |
| 5777 | break; |
| 5778 | } |
| 5779 | } |
| 5780 | |
| 5781 | /* |
| 5782 | * We did not find a match for the interface in the present list. So mark |
| 5783 | * it as one that has joined the group. |
| 5784 | */ |
| 5785 | if (!found) { |
| 5786 | |
| 5787 | /* |
| 5788 | * Store the if index of the new joinee |
| 5789 | */ |
| 5790 | mc_updates->join_dev[if_cnt] = *dst_if_index; |
| 5791 | |
| 5792 | /* |
| 5793 | * Identify a new vacant slot in the 'to_mcast_interfaces' to place |
| 5794 | * the new interface |
| 5795 | */ |
| 5796 | for (heirarchy_index = 0; heirarchy_index < ECM_DB_MULTICAST_IF_MAX ; heirarchy_index++) { |
| 5797 | to_list_first = ecm_db_multicast_if_first_get_at_index(mc_ifaces_first, heirarchy_index); |
| 5798 | if (*to_list_first == ECM_DB_IFACE_HEIRARCHY_MAX) { |
| 5799 | mc_updates->if_join_idx[heirarchy_index] = 1; |
| 5800 | break; |
| 5801 | } |
| 5802 | } |
| 5803 | |
| 5804 | if_cnt++; |
| 5805 | } |
| 5806 | } |
| 5807 | |
| 5808 | ecm_db_multicast_connection_to_interfaces_deref_all(mc_ifaces, mc_ifaces_first); |
| 5809 | mc_updates->if_join_cnt = if_cnt; |
| 5810 | |
| 5811 | return (if_cnt > 0); |
| 5812 | } |
| 5813 | |
| 5814 | /* |
| 5815 | * ecm_interface_multicast_find_updates_to_iface_list() |
| 5816 | * Process IGMP/MLD updates either from MFC or bridge snooper. Identity the interfaces |
| 5817 | * that have left the group and new interfaces that have joined the group. |
| 5818 | * |
| 5819 | * The function returns true if there was any update necessary to the current destination |
| 5820 | * interface list |
| 5821 | */ |
| 5822 | bool ecm_interface_multicast_find_updates_to_iface_list(struct ecm_db_connection_instance *ci, struct ecm_multicast_if_update *mc_updates, |
| 5823 | uint32_t flags, bool is_br_snooper, uint32_t *mc_dst_if_index, uint32_t max_to_dev) |
| 5824 | { |
| 5825 | bool join; |
| 5826 | bool leave; |
| 5827 | /* |
| 5828 | * Find destination interfaces that have left the group |
| 5829 | */ |
| 5830 | leave = ecm_interface_multicast_find_outdated_iface_instances(ci, mc_updates, flags, is_br_snooper, mc_dst_if_index, max_to_dev); |
| 5831 | /* |
| 5832 | * Find new destination interfaces that have joined the group |
| 5833 | */ |
| 5834 | join = ecm_interface_multicast_find_new_iface_instances(ci, mc_updates, mc_dst_if_index, max_to_dev); |
| 5835 | |
| 5836 | return (leave || join); |
| 5837 | } |
| 5838 | EXPORT_SYMBOL(ecm_interface_multicast_find_updates_to_iface_list); |
| 5839 | #endif |
| 5840 | |
Murat Sezgin | 42a44c2 | 2016-05-05 14:06:39 -0700 | [diff] [blame] | 5841 | #ifdef ECM_DB_XREF_ENABLE |
| 5842 | /* |
| 5843 | * ecm_interface_neigh_mac_update_notify_event() |
| 5844 | * Neighbour mac address change handler. |
| 5845 | */ |
| 5846 | static int ecm_interface_neigh_mac_update_notify_event(struct notifier_block *nb, |
| 5847 | unsigned long val, |
| 5848 | void *data) |
| 5849 | { |
Murat Sezgin | 42a44c2 | 2016-05-05 14:06:39 -0700 | [diff] [blame] | 5850 | struct neigh_mac_update *nmu = (struct neigh_mac_update *)data; |
| 5851 | |
| 5852 | /* |
| 5853 | * If the old and new mac addresses are equal, do nothing. |
| 5854 | * This case shouldn't happen. |
| 5855 | */ |
| 5856 | if (!ecm_mac_addr_equal(nmu->old_mac, nmu->update_mac)) { |
| 5857 | DEBUG_TRACE("old and new mac addresses are equal: %pM\n", nmu->old_mac); |
| 5858 | return NOTIFY_DONE; |
| 5859 | } |
| 5860 | |
| 5861 | /* |
| 5862 | * If the old mac is zero, do nothing. When a host joins the arp table first |
| 5863 | * time, its old mac comes as zero. We shouldn't handle this case, because |
| 5864 | * there is not any connection in ECM db with zero mac. |
| 5865 | */ |
| 5866 | if (is_zero_ether_addr(nmu->old_mac)) { |
| 5867 | DEBUG_WARN("old mac is zero\n"); |
| 5868 | return NOTIFY_DONE; |
| 5869 | } |
| 5870 | |
| 5871 | DEBUG_TRACE("old mac: %pM new mac: %pM\n", nmu->old_mac, nmu->update_mac); |
| 5872 | |
Murat Sezgin | a205b04 | 2016-07-19 14:18:14 -0700 | [diff] [blame] | 5873 | DEBUG_INFO("neigh mac update notify for node %pM\n", nmu->old_mac); |
Murat Sezgin | 9304d47 | 2017-04-14 10:16:52 -0700 | [diff] [blame] | 5874 | ecm_interface_node_connections_defunct((uint8_t *)nmu->old_mac); |
Murat Sezgin | 42a44c2 | 2016-05-05 14:06:39 -0700 | [diff] [blame] | 5875 | |
| 5876 | return NOTIFY_DONE; |
| 5877 | } |
| 5878 | |
| 5879 | /* |
| 5880 | * struct notifier_block ecm_interface_neigh_mac_update_nb |
| 5881 | * Registration for neighbour mac address update. |
| 5882 | */ |
| 5883 | static struct notifier_block ecm_interface_neigh_mac_update_nb = { |
| 5884 | .notifier_call = ecm_interface_neigh_mac_update_notify_event, |
| 5885 | }; |
| 5886 | #endif |
| 5887 | |
Murat Sezgin | 1f38185 | 2014-11-20 09:51:07 -0800 | [diff] [blame] | 5888 | /* |
Murat Sezgin | a205b04 | 2016-07-19 14:18:14 -0700 | [diff] [blame] | 5889 | * ecm_interface_wifi_event_iwevent |
| 5890 | * wireless event handler |
| 5891 | */ |
| 5892 | static int ecm_interface_wifi_event_iwevent(int ifindex, unsigned char *buf, size_t len) |
| 5893 | { |
| 5894 | struct iw_event iwe_buf, *iwe = &iwe_buf; |
| 5895 | char *pos, *end; |
| 5896 | |
| 5897 | pos = buf; |
| 5898 | end = buf + len; |
| 5899 | while (pos + IW_EV_LCP_LEN <= end) { |
| 5900 | |
| 5901 | /* |
| 5902 | * Copy the base data structure to get iwe->len |
| 5903 | */ |
| 5904 | memcpy(&iwe_buf, pos, IW_EV_LCP_LEN); |
| 5905 | |
| 5906 | /* |
| 5907 | * Check that len is valid and that we have that much in the buffer. |
| 5908 | * |
| 5909 | */ |
| 5910 | if (iwe->len < IW_EV_LCP_LEN) { |
| 5911 | return -1; |
| 5912 | } |
| 5913 | |
| 5914 | if ((iwe->len > sizeof (struct iw_event)) || (iwe->len + pos) > end) { |
| 5915 | return -1; |
| 5916 | } |
| 5917 | |
| 5918 | /* |
| 5919 | * Do the copy again with the full length. |
| 5920 | */ |
| 5921 | memcpy(&iwe_buf, pos, iwe->len); |
| 5922 | |
| 5923 | if (iwe->cmd == IWEVREGISTERED) { |
| 5924 | DEBUG_INFO("STA %pM joining\n", (uint8_t *)iwe->u.addr.sa_data); |
| 5925 | } else if (iwe->cmd == IWEVEXPIRED) { |
| 5926 | DEBUG_INFO("STA %pM leaving\n", (uint8_t *)iwe->u.addr.sa_data); |
Murat Sezgin | 9304d47 | 2017-04-14 10:16:52 -0700 | [diff] [blame] | 5927 | ecm_interface_node_connections_defunct((uint8_t *)iwe->u.addr.sa_data); |
Murat Sezgin | a205b04 | 2016-07-19 14:18:14 -0700 | [diff] [blame] | 5928 | } else { |
| 5929 | DEBUG_INFO("iwe->cmd is %d for STA %pM\n", iwe->cmd, (unsigned char *) iwe->u.addr.sa_data); |
| 5930 | } |
| 5931 | |
| 5932 | pos += iwe->len; |
| 5933 | } |
| 5934 | |
| 5935 | return 0; |
| 5936 | } |
| 5937 | |
| 5938 | /* |
| 5939 | * ecm_interface_wifi_event_newlink |
| 5940 | * Link event handler |
| 5941 | */ |
| 5942 | static int ecm_interface_wifi_event_newlink(struct ifinfomsg *ifi, unsigned char *buf, size_t len) |
| 5943 | { |
| 5944 | struct rtattr *attr; |
| 5945 | int attrlen, rta_len; |
| 5946 | |
| 5947 | DEBUG_TRACE("Event from interface %d\n", ifi->ifi_index); |
| 5948 | |
| 5949 | attrlen = len; |
| 5950 | attr = (struct rtattr *) buf; |
| 5951 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); |
| 5952 | |
| 5953 | while (RTA_OK(attr, attrlen)) { |
| 5954 | if (attr->rta_type == IFLA_WIRELESS) { |
| 5955 | ecm_interface_wifi_event_iwevent(ifi->ifi_index, ((char *) attr) + rta_len, attr->rta_len - rta_len); |
| 5956 | } |
| 5957 | attr = RTA_NEXT(attr, attrlen); |
| 5958 | } |
| 5959 | |
| 5960 | return 0; |
| 5961 | } |
| 5962 | |
| 5963 | /* |
| 5964 | * ecm_interface_wifi_event_handler |
| 5965 | * Netlink event handler |
| 5966 | */ |
| 5967 | static int ecm_interface_wifi_event_handler(unsigned char *buf, int len) |
| 5968 | { |
| 5969 | struct nlmsghdr *nlh; |
| 5970 | struct ifinfomsg *ifi; |
| 5971 | int left; |
| 5972 | |
| 5973 | nlh = (struct nlmsghdr *) buf; |
| 5974 | left = len; |
| 5975 | |
| 5976 | while (NLMSG_OK(nlh, left)) { |
| 5977 | switch (nlh->nlmsg_type) { |
| 5978 | case RTM_NEWLINK: |
| 5979 | case RTM_DELLINK: |
| 5980 | if (NLMSG_PAYLOAD(nlh, 0) < sizeof(struct ifinfomsg)) { |
| 5981 | DEBUG_INFO("invalid netlink message\n"); |
| 5982 | break; |
| 5983 | } |
| 5984 | |
| 5985 | ifi = NLMSG_DATA(nlh); |
| 5986 | DEBUG_INFO("ifi->ifi_family: %d\n", ifi->ifi_family); |
| 5987 | if (ifi->ifi_family != AF_BRIDGE) { |
| 5988 | ecm_interface_wifi_event_newlink(ifi, (u8 *)ifi + NLMSG_ALIGN(sizeof(struct ifinfomsg)), |
| 5989 | NLMSG_PAYLOAD(nlh, sizeof(struct ifinfomsg))); |
| 5990 | } |
| 5991 | break; |
| 5992 | } |
| 5993 | |
| 5994 | nlh = NLMSG_NEXT(nlh, left); |
| 5995 | } |
| 5996 | |
| 5997 | return 0; |
| 5998 | } |
| 5999 | |
| 6000 | /* |
| 6001 | * ecm_interface_wifi_event_rx |
| 6002 | * Receive netlink message from socket |
| 6003 | */ |
| 6004 | static int ecm_interface_wifi_event_rx(struct socket *sock, struct sockaddr_nl *addr, unsigned char *buf, int len) |
| 6005 | { |
| 6006 | struct msghdr msg; |
| 6007 | struct iovec iov; |
| 6008 | mm_segment_t oldfs; |
| 6009 | int size; |
| 6010 | |
| 6011 | iov.iov_base = buf; |
| 6012 | iov.iov_len = len; |
| 6013 | |
| 6014 | msg.msg_flags = 0; |
| 6015 | msg.msg_name = addr; |
| 6016 | msg.msg_namelen = sizeof(struct sockaddr_nl); |
| 6017 | msg.msg_control = NULL; |
| 6018 | msg.msg_controllen = 0; |
| 6019 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0)) |
| 6020 | msg.msg_iov = &iov; |
| 6021 | msg.msg_iovlen = 1; |
| 6022 | #else |
| 6023 | iov_iter_init(&msg.msg_iter, READ, &iov, 1, 1); |
| 6024 | #endif |
| 6025 | oldfs = get_fs(); |
| 6026 | set_fs(KERNEL_DS); |
| 6027 | size = sock_recvmsg(sock, &msg, len, msg.msg_flags); |
| 6028 | set_fs(oldfs); |
| 6029 | |
| 6030 | return size; |
| 6031 | } |
| 6032 | |
| 6033 | /* |
| 6034 | * ecm_interface_wifi_event_thread |
| 6035 | */ |
| 6036 | static void ecm_interface_wifi_event_thread(void) |
| 6037 | { |
| 6038 | int err; |
| 6039 | int size; |
| 6040 | struct sockaddr_nl saddr; |
| 6041 | unsigned char buf[512]; |
| 6042 | int len = sizeof(buf); |
| 6043 | |
| 6044 | allow_signal(SIGKILL|SIGSTOP); |
| 6045 | err = sock_create(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE, &__ewn.sock); |
| 6046 | if (err < 0) { |
| 6047 | DEBUG_ERROR("failed to create sock\n"); |
| 6048 | goto exit1; |
| 6049 | } |
| 6050 | |
Murat Sezgin | ac26764 | 2016-11-02 15:55:11 -0700 | [diff] [blame] | 6051 | memset(&saddr, 0, sizeof(saddr)); |
Murat Sezgin | a205b04 | 2016-07-19 14:18:14 -0700 | [diff] [blame] | 6052 | saddr.nl_family = AF_NETLINK; |
| 6053 | saddr.nl_groups = RTNLGRP_LINK; |
| 6054 | saddr.nl_pid = current->pid; |
| 6055 | |
| 6056 | err = __ewn.sock->ops->bind(__ewn.sock, (struct sockaddr *)&saddr, sizeof(struct sockaddr)); |
| 6057 | if (err < 0) { |
| 6058 | DEBUG_ERROR("failed to bind sock\n"); |
| 6059 | goto exit2; |
| 6060 | } |
| 6061 | |
| 6062 | DEBUG_INFO("ecm_interface_wifi_event thread started\n"); |
| 6063 | while (!kthread_should_stop()) { |
| 6064 | size = ecm_interface_wifi_event_rx(__ewn.sock, &saddr, buf, len); |
| 6065 | DEBUG_TRACE("got a netlink msg with len %d\n", size); |
| 6066 | |
| 6067 | if (signal_pending(current)) |
| 6068 | break; |
| 6069 | |
| 6070 | if (size < 0) { |
| 6071 | DEBUG_WARN("netlink rx error\n"); |
| 6072 | } else { |
| 6073 | ecm_interface_wifi_event_handler(buf, size); |
| 6074 | } |
| 6075 | } |
| 6076 | |
| 6077 | DEBUG_INFO("ecm_interface_wifi_event thread stopped\n"); |
| 6078 | exit2: |
| 6079 | sock_release(__ewn.sock); |
| 6080 | exit1: |
| 6081 | __ewn.sock = NULL; |
| 6082 | |
| 6083 | return; |
| 6084 | } |
| 6085 | |
| 6086 | /* |
| 6087 | * ecm_interface_wifi_event_start() |
| 6088 | */ |
| 6089 | int ecm_interface_wifi_event_start(void) |
| 6090 | { |
| 6091 | if (__ewn.thread) { |
| 6092 | return 0; |
| 6093 | } |
| 6094 | |
| 6095 | __ewn.thread = kthread_run((void *)ecm_interface_wifi_event_thread, NULL, "ECM_wifi_event"); |
| 6096 | if (IS_ERR(__ewn.thread)) { |
| 6097 | DEBUG_ERROR("Unable to start kernel thread\n"); |
| 6098 | return -ENOMEM; |
| 6099 | } |
| 6100 | |
| 6101 | return 0; |
| 6102 | } |
| 6103 | |
| 6104 | /* |
| 6105 | * ecm_interface_wifi_event_stop() |
| 6106 | */ |
| 6107 | int ecm_interface_wifi_event_stop(void) |
| 6108 | { |
| 6109 | int err; |
| 6110 | |
| 6111 | if (__ewn.thread == NULL) { |
| 6112 | return 0; |
| 6113 | } |
| 6114 | |
| 6115 | DEBUG_INFO("kill ecm_interface_wifi_event thread\n"); |
| 6116 | force_sig(SIGKILL, __ewn.thread); |
| 6117 | err = kthread_stop(__ewn.thread); |
| 6118 | __ewn.thread = NULL; |
| 6119 | |
| 6120 | return err; |
| 6121 | } |
| 6122 | |
| 6123 | /* |
Murat Sezgin | eebedb9 | 2017-11-17 17:14:32 -0800 | [diff] [blame] | 6124 | * ecm_interface_src_check_handler() |
| 6125 | * Source interface check sysctl node handler. |
| 6126 | */ |
| 6127 | static int ecm_interface_src_check_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
| 6128 | { |
| 6129 | int ret; |
| 6130 | int current_value; |
| 6131 | |
| 6132 | /* |
| 6133 | * Take the current value |
| 6134 | */ |
| 6135 | current_value = ecm_interface_src_check; |
| 6136 | |
| 6137 | /* |
| 6138 | * Write the variable with user input |
| 6139 | */ |
| 6140 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 6141 | if (ret || (!write)) { |
| 6142 | return ret; |
| 6143 | } |
| 6144 | |
| 6145 | if (ECM_FRONT_END_TYPE_NSS != ecm_front_end_type_get()) { |
| 6146 | DEBUG_WARN("Source interface check is for NSS only.\n"); |
| 6147 | return -EINVAL; |
| 6148 | } |
| 6149 | |
| 6150 | if ((ecm_interface_src_check != 1) && (ecm_interface_src_check != 0)) { |
| 6151 | DEBUG_WARN("Invalid input. Valid values 0/1\n"); |
| 6152 | ecm_interface_src_check = current_value; |
| 6153 | return -EINVAL; |
| 6154 | } |
| 6155 | |
| 6156 | return ret; |
| 6157 | } |
| 6158 | |
| 6159 | static struct ctl_table ecm_interface_table[] = { |
| 6160 | { |
| 6161 | .procname = "src_interface_check", |
| 6162 | .data = &ecm_interface_src_check, |
| 6163 | .maxlen = sizeof(int), |
| 6164 | .mode = 0644, |
| 6165 | .proc_handler = &ecm_interface_src_check_handler, |
| 6166 | }, |
| 6167 | { } |
| 6168 | }; |
| 6169 | |
| 6170 | static struct ctl_table ecm_interface_root_dir[] = { |
| 6171 | { |
| 6172 | .procname = "ecm", |
| 6173 | .mode = 0555, |
| 6174 | .child = ecm_interface_table, |
| 6175 | }, |
| 6176 | { } |
| 6177 | }; |
| 6178 | |
| 6179 | static struct ctl_table ecm_interface_root[] = { |
| 6180 | { |
| 6181 | .procname = "net", |
| 6182 | .mode = 0555, |
| 6183 | .child = ecm_interface_root_dir, |
| 6184 | }, |
| 6185 | { } |
| 6186 | }; |
| 6187 | |
| 6188 | /* |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 6189 | * ecm_interface_init() |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 6190 | */ |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 6191 | int ecm_interface_init(void) |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 6192 | { |
| 6193 | int result; |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 6194 | DEBUG_INFO("ECM Interface init\n"); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 6195 | |
Murat Sezgin | eebedb9 | 2017-11-17 17:14:32 -0800 | [diff] [blame] | 6196 | /* |
| 6197 | * Register sysctl table. |
| 6198 | */ |
| 6199 | ecm_interface_ctl_table_header = register_sysctl_table(ecm_interface_root); |
| 6200 | |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 6201 | result = register_netdevice_notifier(&ecm_interface_netdev_notifier); |
| 6202 | if (result != 0) { |
| 6203 | DEBUG_ERROR("Failed to register netdevice notifier %d\n", result); |
Murat Sezgin | eebedb9 | 2017-11-17 17:14:32 -0800 | [diff] [blame] | 6204 | unregister_sysctl_table(ecm_interface_ctl_table_header); |
Murat Sezgin | 908ecb3 | 2015-05-10 20:54:36 -0700 | [diff] [blame] | 6205 | return result; |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 6206 | } |
Murat Sezgin | 8c34582 | 2015-05-27 15:35:38 -0700 | [diff] [blame] | 6207 | #if defined(ECM_DB_XREF_ENABLE) && defined(ECM_BAND_STEERING_ENABLE) |
ratheesh kannoth | 37e35b0 | 2015-03-26 11:25:02 +0530 | [diff] [blame] | 6208 | /* |
| 6209 | * register for bridge fdb database modificationevents |
| 6210 | */ |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 6211 | br_fdb_update_register_notify(&ecm_interface_node_br_fdb_update_nb); |
Xiaoping Fan | 8fe3edd | 2016-06-22 16:03:17 -0700 | [diff] [blame] | 6212 | br_fdb_register_notify(&ecm_interface_node_br_fdb_delete_nb); |
Murat Sezgin | 8c34582 | 2015-05-27 15:35:38 -0700 | [diff] [blame] | 6213 | #endif |
Murat Sezgin | 42a44c2 | 2016-05-05 14:06:39 -0700 | [diff] [blame] | 6214 | #ifdef ECM_DB_XREF_ENABLE |
| 6215 | neigh_mac_update_register_notify(&ecm_interface_neigh_mac_update_nb); |
| 6216 | #endif |
Murat Sezgin | a205b04 | 2016-07-19 14:18:14 -0700 | [diff] [blame] | 6217 | ecm_interface_wifi_event_start(); |
| 6218 | |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 6219 | return 0; |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 6220 | } |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 6221 | EXPORT_SYMBOL(ecm_interface_init); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 6222 | |
| 6223 | /* |
| 6224 | * ecm_interface_exit() |
| 6225 | */ |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 6226 | void ecm_interface_exit(void) |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 6227 | { |
| 6228 | DEBUG_INFO("ECM Interface exit\n"); |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 6229 | |
| 6230 | spin_lock_bh(&ecm_interface_lock); |
| 6231 | ecm_interface_terminate_pending = true; |
| 6232 | spin_unlock_bh(&ecm_interface_lock); |
| 6233 | |
| 6234 | unregister_netdevice_notifier(&ecm_interface_netdev_notifier); |
Murat Sezgin | 42a44c2 | 2016-05-05 14:06:39 -0700 | [diff] [blame] | 6235 | #ifdef ECM_DB_XREF_ENABLE |
| 6236 | neigh_mac_update_unregister_notify(&ecm_interface_neigh_mac_update_nb); |
| 6237 | #endif |
| 6238 | |
Murat Sezgin | 8c34582 | 2015-05-27 15:35:38 -0700 | [diff] [blame] | 6239 | #if defined(ECM_DB_XREF_ENABLE) && defined(ECM_BAND_STEERING_ENABLE) |
ratheesh kannoth | 37e35b0 | 2015-03-26 11:25:02 +0530 | [diff] [blame] | 6240 | /* |
| 6241 | * unregister for bridge fdb update events |
| 6242 | */ |
| 6243 | br_fdb_update_unregister_notify(&ecm_interface_node_br_fdb_update_nb); |
Xiaoping Fan | 8fe3edd | 2016-06-22 16:03:17 -0700 | [diff] [blame] | 6244 | br_fdb_unregister_notify(&ecm_interface_node_br_fdb_delete_nb); |
Murat Sezgin | 8c34582 | 2015-05-27 15:35:38 -0700 | [diff] [blame] | 6245 | #endif |
Murat Sezgin | a205b04 | 2016-07-19 14:18:14 -0700 | [diff] [blame] | 6246 | ecm_interface_wifi_event_stop(); |
Murat Sezgin | eebedb9 | 2017-11-17 17:14:32 -0800 | [diff] [blame] | 6247 | |
| 6248 | /* |
| 6249 | * Unregister sysctl table. |
| 6250 | */ |
| 6251 | if (ecm_interface_ctl_table_header) { |
| 6252 | unregister_sysctl_table(ecm_interface_ctl_table_header); |
| 6253 | } |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 6254 | } |
Nicolas Costa | f46c33b | 2014-05-15 10:02:00 -0500 | [diff] [blame] | 6255 | EXPORT_SYMBOL(ecm_interface_exit); |