Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 1 | /* |
| 2 | * sfe-cm.c |
| 3 | * Shortcut forwarding engine connection manager. |
| 4 | * |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 5 | * Copyright (c) 2013-2015 Qualcomm Atheros, Inc. |
Matthew McClintock | a322194 | 2014-01-16 11:44:26 -0600 | [diff] [blame] | 6 | * |
| 7 | * All Rights Reserved. |
| 8 | * Qualcomm Atheros Confidential and Proprietary. |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 9 | */ |
Matthew McClintock | a322194 | 2014-01-16 11:44:26 -0600 | [diff] [blame] | 10 | |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 11 | #include <linux/module.h> |
| 12 | #include <linux/sysfs.h> |
| 13 | #include <linux/skbuff.h> |
| 14 | #include <net/route.h> |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 15 | #include <net/ip6_route.h> |
| 16 | #include <net/addrconf.h> |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 17 | #include <linux/inetdevice.h> |
| 18 | #include <linux/netfilter_bridge.h> |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 19 | #include <linux/netfilter_ipv6.h> |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 20 | #include <net/netfilter/nf_conntrack_acct.h> |
| 21 | #include <net/netfilter/nf_conntrack_helper.h> |
| 22 | #include <net/netfilter/nf_conntrack_zones.h> |
| 23 | #include <net/netfilter/nf_conntrack_core.h> |
Matthew McClintock | bf6b5bc | 2014-02-24 12:27:14 -0600 | [diff] [blame] | 24 | #include <linux/if_bridge.h> |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 25 | |
| 26 | #include "sfe.h" |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 27 | #include "sfe_cm.h" |
Xiaoping Fan | 3f1fe51 | 2014-11-05 12:14:57 -0800 | [diff] [blame] | 28 | #include "sfe_backport.h" |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 29 | |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 30 | typedef enum sfe_cm_exception { |
| 31 | SFE_CM_EXCEPTION_PACKET_BROADCAST, |
| 32 | SFE_CM_EXCEPTION_PACKET_MULTICAST, |
| 33 | SFE_CM_EXCEPTION_NO_IIF, |
| 34 | SFE_CM_EXCEPTION_NO_CT, |
| 35 | SFE_CM_EXCEPTION_CT_NO_TRACK, |
| 36 | SFE_CM_EXCEPTION_CT_NO_CONFIRM, |
| 37 | SFE_CM_EXCEPTION_CT_IS_ALG, |
| 38 | SFE_CM_EXCEPTION_IS_IPV4_MCAST, |
| 39 | SFE_CM_EXCEPTION_IS_IPV6_MCAST, |
| 40 | SFE_CM_EXCEPTION_TCP_NOT_ASSURED, |
| 41 | SFE_CM_EXCEPTION_TCP_NOT_ESTABLISHED, |
| 42 | SFE_CM_EXCEPTION_UNKNOW_PROTOCOL, |
| 43 | SFE_CM_EXCEPTION_NO_SRC_DEV, |
| 44 | SFE_CM_EXCEPTION_NO_SRC_XLATE_DEV, |
| 45 | SFE_CM_EXCEPTION_NO_DEST_DEV, |
| 46 | SFE_CM_EXCEPTION_NO_DEST_XLATE_DEV, |
| 47 | SFE_CM_EXCEPTION_NO_BRIDGE, |
| 48 | SFE_CM_EXCEPTION_MAX |
| 49 | } sfe_cm_exception_t; |
| 50 | |
| 51 | static char *sfe_cm_exception_events_string[SFE_CM_EXCEPTION_MAX] = { |
| 52 | "PACKET_BROADCAST", |
| 53 | "PACKET_MULTICAST", |
| 54 | "NO_IIF", |
| 55 | "NO_CT", |
| 56 | "CT_NO_TRACK", |
| 57 | "CT_NO_CONFIRM", |
| 58 | "CT_IS_ALG", |
| 59 | "IS_IPV4_MCAST", |
| 60 | "IS_IPV6_MCAST", |
| 61 | "TCP_NOT_ASSURED", |
| 62 | "TCP_NOT_ESTABLISHED", |
| 63 | "UNKNOW_PROTOCOL", |
| 64 | "NO_SRC_DEV", |
| 65 | "NO_SRC_XLATE_DEV", |
| 66 | "NO_DEST_DEV", |
| 67 | "NO_DEST_XLATE_DEV", |
| 68 | "NO_BRIDGE" |
| 69 | }; |
| 70 | |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 71 | /* |
| 72 | * Per-module structure. |
| 73 | */ |
| 74 | struct sfe_cm { |
| 75 | spinlock_t lock; /* Lock for SMP correctness */ |
| 76 | |
| 77 | /* |
| 78 | * Control state. |
| 79 | */ |
| 80 | struct kobject *sys_sfe_cm; /* sysfs linkage */ |
| 81 | |
| 82 | /* |
| 83 | * Callback notifiers. |
| 84 | */ |
| 85 | struct notifier_block dev_notifier; |
| 86 | /* Device notifier */ |
| 87 | struct notifier_block inet_notifier; |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 88 | /* IPv4 notifier */ |
| 89 | struct notifier_block inet6_notifier; |
| 90 | /* IPv6 notifier */ |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 91 | uint32_t exceptions[SFE_CM_EXCEPTION_MAX]; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | struct sfe_cm __sc; |
| 95 | |
| 96 | /* |
| 97 | * Expose the hook for the receive processing. |
| 98 | */ |
| 99 | extern int (*athrs_fast_nat_recv)(struct sk_buff *skb); |
| 100 | |
| 101 | /* |
| 102 | * Expose what should be a static flag in the TCP connection tracker. |
| 103 | */ |
| 104 | extern int nf_ct_tcp_no_window_check; |
| 105 | |
| 106 | /* |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 107 | * sfe_cm_incr_exceptions() |
| 108 | * increase an exception counter. |
| 109 | */ |
| 110 | static inline void sfe_cm_incr_exceptions(sfe_cm_exception_t except) |
| 111 | { |
| 112 | struct sfe_cm *sc = &__sc; |
| 113 | |
| 114 | spin_lock_bh(&sc->lock); |
| 115 | sc->exceptions[except]++; |
| 116 | spin_unlock_bh(&sc->lock); |
| 117 | } |
| 118 | |
| 119 | /* |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 120 | * sfe_cm_recv() |
| 121 | * Handle packet receives. |
| 122 | * |
| 123 | * Returns 1 if the packet is forwarded or 0 if it isn't. |
| 124 | */ |
| 125 | int sfe_cm_recv(struct sk_buff *skb) |
| 126 | { |
| 127 | struct net_device *dev; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 128 | |
| 129 | /* |
| 130 | * We know that for the vast majority of packets we need the transport |
| 131 | * layer header so we may as well start to fetch it now! |
| 132 | */ |
| 133 | prefetch(skb->data + 32); |
| 134 | barrier(); |
| 135 | |
| 136 | dev = skb->dev; |
| 137 | |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 138 | /* |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 139 | * We're only interested in IPv4 and IPv6 packets. |
Xiaoping Fan | 5917642 | 2015-05-22 15:58:10 -0700 | [diff] [blame] | 140 | */ |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 141 | if (likely(htons(ETH_P_IP) == skb->protocol)) { |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 142 | #if (SFE_HOOK_ABOVE_BRIDGE) |
| 143 | struct in_device *in_dev; |
| 144 | |
| 145 | /* |
| 146 | * Does our input device support IP processing? |
| 147 | */ |
| 148 | in_dev = (struct in_device *)dev->ip_ptr; |
| 149 | if (unlikely(!in_dev)) { |
| 150 | DEBUG_TRACE("no IP processing for device: %s\n", dev->name); |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | /* |
| 155 | * Does it have an IP address? If it doesn't then we can't do anything |
| 156 | * interesting here! |
| 157 | */ |
| 158 | if (unlikely(!in_dev->ifa_list)) { |
| 159 | DEBUG_TRACE("no IP address for device: %s\n", dev->name); |
| 160 | return 0; |
| 161 | } |
| 162 | #endif |
| 163 | |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 164 | return sfe_ipv4_recv(dev, skb); |
| 165 | } |
| 166 | |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 167 | if (likely(htons(ETH_P_IPV6) == skb->protocol)) { |
| 168 | #if (SFE_HOOK_ABOVE_BRIDGE) |
| 169 | struct inet6_dev *in_dev; |
| 170 | |
| 171 | /* |
| 172 | * Does our input device support IPv6 processing? |
| 173 | */ |
| 174 | in_dev = (struct inet6_dev *)dev->ip6_ptr; |
| 175 | if (unlikely(!in_dev)) { |
| 176 | DEBUG_TRACE("no IPv6 processing for device: %s\n", dev->name); |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | /* |
| 181 | * Does it have an IPv6 address? If it doesn't then we can't do anything |
| 182 | * interesting here! |
| 183 | */ |
| 184 | if (unlikely(list_empty(&in_dev->addr_list))) { |
| 185 | DEBUG_TRACE("no IPv6 address for device: %s\n", dev->name); |
| 186 | return 0; |
| 187 | } |
| 188 | #endif |
| 189 | |
| 190 | return sfe_ipv6_recv(dev, skb); |
| 191 | } |
| 192 | |
Matthew McClintock | a8ad796 | 2014-01-16 16:49:30 -0600 | [diff] [blame] | 193 | DEBUG_TRACE("not IP packet\n"); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | /* |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 198 | * sfe_cm_find_dev_and_mac_addr() |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 199 | * Find the device and MAC address for a given IPv4/IPv6 address. |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 200 | * |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 201 | * Returns true if we find the device and MAC address, otherwise false. |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 202 | * |
| 203 | * We look up the rtable entry for the address and, from its neighbour |
| 204 | * structure, obtain the hardware address. This means this function also |
| 205 | * works if the neighbours are routers too. |
| 206 | */ |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 207 | static bool sfe_cm_find_dev_and_mac_addr(sfe_ip_addr_t *addr, struct net_device **dev, uint8_t *mac_addr, int is_v4) |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 208 | { |
| 209 | struct neighbour *neigh; |
| 210 | struct rtable *rt; |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 211 | struct rt6_info *rt6; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 212 | struct dst_entry *dst; |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 213 | struct net_device *mac_dev; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 214 | |
| 215 | /* |
| 216 | * Look up the rtable entry for the IP address then get the hardware |
| 217 | * address from its neighbour structure. This means this work when the |
| 218 | * neighbours are routers too. |
| 219 | */ |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 220 | if (likely(is_v4)) { |
| 221 | rt = ip_route_output(&init_net, addr->ip, 0, 0, 0); |
| 222 | if (unlikely(IS_ERR(rt))) { |
| 223 | goto ret_fail; |
| 224 | } |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 225 | |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 226 | dst = (struct dst_entry *)rt; |
| 227 | } else { |
| 228 | rt6 = rt6_lookup(&init_net, (struct in6_addr *)addr->ip6, 0, 0, 0); |
| 229 | if (!rt6) { |
| 230 | goto ret_fail; |
| 231 | } |
| 232 | |
| 233 | dst = (struct dst_entry *)rt6; |
| 234 | } |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 235 | |
| 236 | rcu_read_lock(); |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 237 | neigh = dst_neigh_lookup(dst, addr); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 238 | if (unlikely(!neigh)) { |
| 239 | rcu_read_unlock(); |
| 240 | dst_release(dst); |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 241 | goto ret_fail; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | if (unlikely(!(neigh->nud_state & NUD_VALID))) { |
| 245 | rcu_read_unlock(); |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 246 | neigh_release(neigh); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 247 | dst_release(dst); |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 248 | goto ret_fail; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 249 | } |
| 250 | |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 251 | mac_dev = neigh->dev; |
| 252 | if (!mac_dev) { |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 253 | rcu_read_unlock(); |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 254 | neigh_release(neigh); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 255 | dst_release(dst); |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 256 | goto ret_fail; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 257 | } |
| 258 | |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 259 | memcpy(mac_addr, neigh->ha, (size_t)mac_dev->addr_len); |
| 260 | |
| 261 | dev_hold(mac_dev); |
| 262 | *dev = mac_dev; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 263 | rcu_read_unlock(); |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 264 | neigh_release(neigh); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 265 | dst_release(dst); |
| 266 | |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 267 | return true; |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 268 | |
| 269 | ret_fail: |
| 270 | if (is_v4) { |
| 271 | DEBUG_TRACE("failed to find MAC address for IP: %pI4\n", &addr->ip); |
| 272 | |
| 273 | } else { |
| 274 | DEBUG_TRACE("failed to find MAC address for IP: %pI6\n", addr->ip6); |
| 275 | } |
| 276 | |
| 277 | return false; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | /* |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 281 | * sfe_cm_post_routing() |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 282 | * Called for packets about to leave the box - either locally generated or forwarded from another interface |
| 283 | */ |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 284 | static unsigned int sfe_cm_post_routing(struct sk_buff *skb, int is_v4) |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 285 | { |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 286 | struct sfe_connection_create sic; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 287 | struct net_device *in; |
| 288 | struct nf_conn *ct; |
| 289 | enum ip_conntrack_info ctinfo; |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 290 | struct net_device *dev; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 291 | struct net_device *src_dev; |
| 292 | struct net_device *dest_dev; |
| 293 | struct net_device *src_br_dev = NULL; |
| 294 | struct net_device *dest_br_dev = NULL; |
| 295 | struct nf_conntrack_tuple orig_tuple; |
| 296 | struct nf_conntrack_tuple reply_tuple; |
| 297 | |
| 298 | /* |
| 299 | * Don't process broadcast or multicast packets. |
| 300 | */ |
| 301 | if (unlikely(skb->pkt_type == PACKET_BROADCAST)) { |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 302 | sfe_cm_incr_exceptions(SFE_CM_EXCEPTION_PACKET_BROADCAST); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 303 | DEBUG_TRACE("broadcast, ignoring\n"); |
| 304 | return NF_ACCEPT; |
| 305 | } |
| 306 | if (unlikely(skb->pkt_type == PACKET_MULTICAST)) { |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 307 | sfe_cm_incr_exceptions(SFE_CM_EXCEPTION_PACKET_MULTICAST); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 308 | DEBUG_TRACE("multicast, ignoring\n"); |
| 309 | return NF_ACCEPT; |
| 310 | } |
| 311 | |
Zhi Chen | 8748eb3 | 2015-06-18 12:58:48 -0700 | [diff] [blame] | 312 | #ifdef CONFIG_XFRM |
| 313 | /* |
| 314 | * Packet to xfrm for encapsulation, we can't process it |
| 315 | */ |
| 316 | if (unlikely(skb_dst(skb)->xfrm)) { |
| 317 | DEBUG_TRACE("packet to xfrm, ignoring\n"); |
| 318 | return NF_ACCEPT; |
| 319 | } |
| 320 | #endif |
| 321 | |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 322 | /* |
| 323 | * Don't process packets that are not being forwarded. |
| 324 | */ |
| 325 | in = dev_get_by_index(&init_net, skb->skb_iif); |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 326 | if (!in) { |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 327 | sfe_cm_incr_exceptions(SFE_CM_EXCEPTION_NO_IIF); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 328 | DEBUG_TRACE("packet not forwarding\n"); |
| 329 | return NF_ACCEPT; |
| 330 | } |
| 331 | |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 332 | dev_put(in); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 333 | |
| 334 | /* |
| 335 | * Don't process packets that aren't being tracked by conntrack. |
| 336 | */ |
| 337 | ct = nf_ct_get(skb, &ctinfo); |
| 338 | if (unlikely(!ct)) { |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 339 | sfe_cm_incr_exceptions(SFE_CM_EXCEPTION_NO_CT); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 340 | DEBUG_TRACE("no conntrack connection, ignoring\n"); |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 341 | return NF_ACCEPT; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | /* |
| 345 | * Don't process untracked connections. |
| 346 | */ |
| 347 | if (unlikely(ct == &nf_conntrack_untracked)) { |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 348 | sfe_cm_incr_exceptions(SFE_CM_EXCEPTION_CT_NO_TRACK); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 349 | DEBUG_TRACE("untracked connection\n"); |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 350 | return NF_ACCEPT; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | /* |
Xiaoping Fan | 956461e | 2015-06-25 17:35:13 -0700 | [diff] [blame] | 354 | * Unconfirmed connection may be dropped by Linux at the final step, |
| 355 | * So we don't process unconfirmed connections. |
| 356 | */ |
| 357 | if (!nf_ct_is_confirmed(ct)) { |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 358 | sfe_cm_incr_exceptions(SFE_CM_EXCEPTION_CT_NO_CONFIRM); |
Xiaoping Fan | 956461e | 2015-06-25 17:35:13 -0700 | [diff] [blame] | 359 | DEBUG_TRACE("unconfirmed connection\n"); |
| 360 | return NF_ACCEPT; |
| 361 | } |
| 362 | |
| 363 | /* |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 364 | * Don't process connections that require support from a 'helper' (typically a NAT ALG). |
| 365 | */ |
| 366 | if (unlikely(nfct_help(ct))) { |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 367 | sfe_cm_incr_exceptions(SFE_CM_EXCEPTION_CT_IS_ALG); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 368 | DEBUG_TRACE("connection has helper\n"); |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 369 | return NF_ACCEPT; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | /* |
| 373 | * Look up the details of our connection in conntrack. |
| 374 | * |
| 375 | * Note that the data we get from conntrack is for the "ORIGINAL" direction |
| 376 | * but our packet may actually be in the "REPLY" direction. |
| 377 | */ |
| 378 | orig_tuple = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple; |
| 379 | reply_tuple = ct->tuplehash[IP_CT_DIR_REPLY].tuple; |
| 380 | sic.protocol = (int32_t)orig_tuple.dst.protonum; |
| 381 | |
| 382 | /* |
| 383 | * Get addressing information, non-NAT first |
| 384 | */ |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 385 | if (likely(is_v4)) { |
| 386 | sic.src_ip.ip = (__be32)orig_tuple.src.u3.ip; |
| 387 | sic.dest_ip.ip = (__be32)orig_tuple.dst.u3.ip; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 388 | |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 389 | if (ipv4_is_multicast(sic.src_ip.ip) || ipv4_is_multicast(sic.dest_ip.ip)) { |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 390 | sfe_cm_incr_exceptions(SFE_CM_EXCEPTION_IS_IPV4_MCAST); |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 391 | DEBUG_TRACE("multicast address\n"); |
| 392 | return NF_ACCEPT; |
| 393 | } |
| 394 | |
| 395 | /* |
| 396 | * NAT'ed addresses - note these are as seen from the 'reply' direction |
| 397 | * When NAT does not apply to this connection these will be identical to the above. |
| 398 | */ |
| 399 | sic.src_ip_xlate.ip = (__be32)reply_tuple.dst.u3.ip; |
| 400 | sic.dest_ip_xlate.ip = (__be32)reply_tuple.src.u3.ip; |
| 401 | } else { |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 402 | sic.src_ip.ip6[0] = *((struct sfe_ipv6_addr *)&orig_tuple.src.u3.in6); |
| 403 | sic.dest_ip.ip6[0] = *((struct sfe_ipv6_addr *)&orig_tuple.dst.u3.in6); |
| 404 | |
| 405 | if (ipv6_addr_is_multicast((struct in6_addr *)sic.src_ip.ip6) || |
| 406 | ipv6_addr_is_multicast((struct in6_addr *)sic.dest_ip.ip6)) { |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 407 | sfe_cm_incr_exceptions(SFE_CM_EXCEPTION_IS_IPV6_MCAST); |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 408 | DEBUG_TRACE("multicast address\n"); |
| 409 | return NF_ACCEPT; |
| 410 | } |
| 411 | |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 412 | /* |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 413 | * NAT'ed addresses - note these are as seen from the 'reply' direction |
| 414 | * When NAT does not apply to this connection these will be identical to the above. |
| 415 | */ |
| 416 | sic.src_ip_xlate.ip6[0] = *((struct sfe_ipv6_addr *)&reply_tuple.dst.u3.in6); |
| 417 | sic.dest_ip_xlate.ip6[0] = *((struct sfe_ipv6_addr *)&reply_tuple.src.u3.in6); |
Matthew McClintock | a11c7cd | 2014-08-06 16:41:30 -0500 | [diff] [blame] | 418 | } |
| 419 | |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 420 | sic.flags = 0; |
| 421 | |
| 422 | switch (sic.protocol) { |
| 423 | case IPPROTO_TCP: |
| 424 | sic.src_port = orig_tuple.src.u.tcp.port; |
| 425 | sic.dest_port = orig_tuple.dst.u.tcp.port; |
| 426 | sic.src_port_xlate = reply_tuple.dst.u.tcp.port; |
| 427 | sic.dest_port_xlate = reply_tuple.src.u.tcp.port; |
| 428 | sic.src_td_window_scale = ct->proto.tcp.seen[0].td_scale; |
| 429 | sic.src_td_max_window = ct->proto.tcp.seen[0].td_maxwin; |
| 430 | sic.src_td_end = ct->proto.tcp.seen[0].td_end; |
| 431 | sic.src_td_max_end = ct->proto.tcp.seen[0].td_maxend; |
| 432 | sic.dest_td_window_scale = ct->proto.tcp.seen[1].td_scale; |
| 433 | sic.dest_td_max_window = ct->proto.tcp.seen[1].td_maxwin; |
| 434 | sic.dest_td_end = ct->proto.tcp.seen[1].td_end; |
| 435 | sic.dest_td_max_end = ct->proto.tcp.seen[1].td_maxend; |
| 436 | if (nf_ct_tcp_no_window_check |
| 437 | || (ct->proto.tcp.seen[0].flags & IP_CT_TCP_FLAG_BE_LIBERAL) |
| 438 | || (ct->proto.tcp.seen[1].flags & IP_CT_TCP_FLAG_BE_LIBERAL)) { |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 439 | sic.flags |= SFE_CREATE_FLAG_NO_SEQ_CHECK; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | /* |
| 443 | * Don't try to manage a non-established connection. |
| 444 | */ |
| 445 | if (!test_bit(IPS_ASSURED_BIT, &ct->status)) { |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 446 | sfe_cm_incr_exceptions(SFE_CM_EXCEPTION_TCP_NOT_ASSURED); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 447 | DEBUG_TRACE("non-established connection\n"); |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 448 | return NF_ACCEPT; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | /* |
| 452 | * If the connection is shutting down do not manage it. |
| 453 | * state can not be SYN_SENT, SYN_RECV because connection is assured |
| 454 | * Not managed states: FIN_WAIT, CLOSE_WAIT, LAST_ACK, TIME_WAIT, CLOSE. |
| 455 | */ |
| 456 | spin_lock_bh(&ct->lock); |
| 457 | if (ct->proto.tcp.state != TCP_CONNTRACK_ESTABLISHED) { |
| 458 | spin_unlock_bh(&ct->lock); |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 459 | sfe_cm_incr_exceptions(SFE_CM_EXCEPTION_TCP_NOT_ESTABLISHED); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 460 | DEBUG_TRACE("connection in termination state: %#x, s: %pI4:%u, d: %pI4:%u\n", |
| 461 | ct->proto.tcp.state, &sic.src_ip, ntohs(sic.src_port), |
| 462 | &sic.dest_ip, ntohs(sic.dest_port)); |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 463 | return NF_ACCEPT; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 464 | } |
| 465 | spin_unlock_bh(&ct->lock); |
| 466 | break; |
| 467 | |
| 468 | case IPPROTO_UDP: |
| 469 | sic.src_port = orig_tuple.src.u.udp.port; |
| 470 | sic.dest_port = orig_tuple.dst.u.udp.port; |
| 471 | sic.src_port_xlate = reply_tuple.dst.u.udp.port; |
| 472 | sic.dest_port_xlate = reply_tuple.src.u.udp.port; |
| 473 | break; |
| 474 | |
| 475 | default: |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 476 | sfe_cm_incr_exceptions(SFE_CM_EXCEPTION_UNKNOW_PROTOCOL); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 477 | DEBUG_TRACE("unhandled protocol %d\n", sic.protocol); |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 478 | return NF_ACCEPT; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 479 | } |
| 480 | |
Zhi Chen | 8748eb3 | 2015-06-18 12:58:48 -0700 | [diff] [blame] | 481 | #ifdef CONFIG_XFRM |
| 482 | sic.original_accel = 1; |
| 483 | sic.reply_accel = 1; |
| 484 | |
| 485 | /* |
| 486 | * For packets de-capsulated from xfrm, we still can accelerate it |
| 487 | * on the direction we just received the packet. |
| 488 | */ |
| 489 | if (unlikely(skb->sp)) { |
| 490 | if (sic.protocol == IPPROTO_TCP && |
| 491 | !(sic.flags & SFE_CREATE_FLAG_NO_SEQ_CHECK)) { |
| 492 | return NF_ACCEPT; |
| 493 | } |
| 494 | |
| 495 | if (CTINFO2DIR(ctinfo) == IP_CT_DIR_ORIGINAL) { |
| 496 | sic.reply_accel = 0; |
| 497 | } else { |
| 498 | sic.original_accel = 0; |
| 499 | } |
| 500 | } |
| 501 | #endif |
| 502 | |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 503 | /* |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 504 | * Get the net device and MAC addresses that correspond to the various source and |
| 505 | * destination host addresses. |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 506 | */ |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 507 | if (!sfe_cm_find_dev_and_mac_addr(&sic.src_ip, &src_dev, sic.src_mac, is_v4)) { |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 508 | sfe_cm_incr_exceptions(SFE_CM_EXCEPTION_NO_SRC_DEV); |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 509 | return NF_ACCEPT; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 510 | } |
| 511 | |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 512 | if (!sfe_cm_find_dev_and_mac_addr(&sic.src_ip_xlate, &dev, sic.src_mac_xlate, is_v4)) { |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 513 | sfe_cm_incr_exceptions(SFE_CM_EXCEPTION_NO_SRC_XLATE_DEV); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 514 | goto done1; |
| 515 | } |
| 516 | |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 517 | dev_put(dev); |
| 518 | |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 519 | if (!sfe_cm_find_dev_and_mac_addr(&sic.dest_ip, &dev, sic.dest_mac, is_v4)) { |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 520 | sfe_cm_incr_exceptions(SFE_CM_EXCEPTION_NO_DEST_DEV); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 521 | goto done1; |
| 522 | } |
| 523 | |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 524 | dev_put(dev); |
| 525 | |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 526 | if (!sfe_cm_find_dev_and_mac_addr(&sic.dest_ip_xlate, &dest_dev, sic.dest_mac_xlate, is_v4)) { |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 527 | sfe_cm_incr_exceptions(SFE_CM_EXCEPTION_NO_DEST_XLATE_DEV); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 528 | goto done1; |
| 529 | } |
| 530 | |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 531 | #if (!SFE_HOOK_ABOVE_BRIDGE) |
| 532 | /* |
| 533 | * Now our devices may actually be a bridge interface. If that's |
| 534 | * the case then we need to hunt down the underlying interface. |
| 535 | */ |
| 536 | if (src_dev->priv_flags & IFF_EBRIDGE) { |
| 537 | src_br_dev = br_port_dev_get(src_dev, sic.src_mac); |
| 538 | if (!src_br_dev) { |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 539 | sfe_cm_incr_exceptions(SFE_CM_EXCEPTION_NO_BRIDGE); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 540 | DEBUG_TRACE("no port found on bridge\n"); |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 541 | goto done2; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | src_dev = src_br_dev; |
| 545 | } |
| 546 | |
| 547 | if (dest_dev->priv_flags & IFF_EBRIDGE) { |
| 548 | dest_br_dev = br_port_dev_get(dest_dev, sic.dest_mac_xlate); |
| 549 | if (!dest_br_dev) { |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 550 | sfe_cm_incr_exceptions(SFE_CM_EXCEPTION_NO_BRIDGE); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 551 | DEBUG_TRACE("no port found on bridge\n"); |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 552 | goto done3; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | dest_dev = dest_br_dev; |
| 556 | } |
| 557 | #else |
| 558 | /* |
| 559 | * Our devices may actually be part of a bridge interface. If that's |
| 560 | * the case then find the bridge interface instead. |
| 561 | */ |
| 562 | if (src_dev->priv_flags & IFF_BRIDGE_PORT) { |
Xiaoping Fan | 3f1fe51 | 2014-11-05 12:14:57 -0800 | [diff] [blame] | 563 | src_br_dev = SFE_DEV_MASTER(src_dev); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 564 | if (!src_br_dev) { |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 565 | sfe_cm_incr_exceptions(SFE_CM_EXCEPTION_NO_BRIDGE); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 566 | DEBUG_TRACE("no bridge found for: %s\n", src_dev->name); |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 567 | goto done2; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | dev_hold(src_br_dev); |
| 571 | src_dev = src_br_dev; |
| 572 | } |
| 573 | |
| 574 | if (dest_dev->priv_flags & IFF_BRIDGE_PORT) { |
Xiaoping Fan | 3f1fe51 | 2014-11-05 12:14:57 -0800 | [diff] [blame] | 575 | dest_br_dev = SFE_DEV_MASTER(dest_dev); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 576 | if (!dest_br_dev) { |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 577 | sfe_cm_incr_exceptions(SFE_CM_EXCEPTION_NO_BRIDGE); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 578 | DEBUG_TRACE("no bridge found for: %s\n", dest_dev->name); |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 579 | goto done3; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | dev_hold(dest_br_dev); |
| 583 | dest_dev = dest_br_dev; |
| 584 | } |
| 585 | #endif |
| 586 | |
| 587 | sic.src_dev = src_dev; |
| 588 | sic.dest_dev = dest_dev; |
| 589 | |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 590 | sic.src_mtu = src_dev->mtu; |
| 591 | sic.dest_mtu = dest_dev->mtu; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 592 | |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 593 | if (likely(is_v4)) { |
| 594 | sfe_ipv4_create_rule(&sic); |
| 595 | } else { |
| 596 | sfe_ipv6_create_rule(&sic); |
| 597 | } |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 598 | |
| 599 | /* |
| 600 | * If we had bridge ports then release them too. |
| 601 | */ |
| 602 | if (dest_br_dev) { |
| 603 | dev_put(dest_br_dev); |
| 604 | } |
| 605 | |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 606 | done3: |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 607 | if (src_br_dev) { |
| 608 | dev_put(src_br_dev); |
| 609 | } |
| 610 | |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 611 | done2: |
| 612 | dev_put(dest_dev); |
| 613 | |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 614 | done1: |
Matthew McClintock | db5ac51 | 2014-01-16 17:01:40 -0600 | [diff] [blame] | 615 | dev_put(src_dev); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 616 | |
| 617 | return NF_ACCEPT; |
| 618 | } |
| 619 | |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 620 | /* |
| 621 | * sfe_cm_ipv4_post_routing_hook() |
| 622 | * Called for packets about to leave the box - either locally generated or forwarded from another interface |
| 623 | */ |
| 624 | sfe_cm_ipv4_post_routing_hook(hooknum, ops, skb, in_unused, out, okfn) |
| 625 | { |
| 626 | return sfe_cm_post_routing(skb, true); |
| 627 | } |
| 628 | |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 629 | /* |
| 630 | * sfe_cm_ipv6_post_routing_hook() |
| 631 | * Called for packets about to leave the box - either locally generated or forwarded from another interface |
| 632 | */ |
| 633 | sfe_cm_ipv6_post_routing_hook(hooknum, ops, skb, in_unused, out, okfn) |
| 634 | { |
| 635 | return sfe_cm_post_routing(skb, false); |
| 636 | } |
| 637 | |
| 638 | |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 639 | #ifdef CONFIG_NF_CONNTRACK_EVENTS |
| 640 | /* |
| 641 | * sfe_cm_conntrack_event() |
| 642 | * Callback event invoked when a conntrack connection's state changes. |
| 643 | */ |
Matthew McClintock | 0680e9f | 2013-11-26 15:43:10 -0600 | [diff] [blame] | 644 | #ifdef CONFIG_NF_CONNTRACK_CHAIN_EVENTS |
| 645 | static int sfe_cm_conntrack_event(struct notifier_block *this, |
Matthew McClintock | 0f5c059 | 2014-02-12 11:17:11 -0600 | [diff] [blame] | 646 | unsigned long events, void *ptr) |
Matthew McClintock | 0680e9f | 2013-11-26 15:43:10 -0600 | [diff] [blame] | 647 | #else |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 648 | static int sfe_cm_conntrack_event(unsigned int events, struct nf_ct_event *item) |
Matthew McClintock | 0680e9f | 2013-11-26 15:43:10 -0600 | [diff] [blame] | 649 | #endif |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 650 | { |
Matthew McClintock | 0f5c059 | 2014-02-12 11:17:11 -0600 | [diff] [blame] | 651 | #ifdef CONFIG_NF_CONNTRACK_CHAIN_EVENTS |
| 652 | struct nf_ct_event *item = ptr; |
| 653 | #endif |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 654 | struct sfe_connection_destroy sid; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 655 | struct nf_conn *ct = item->ct; |
| 656 | struct nf_conntrack_tuple orig_tuple; |
| 657 | |
| 658 | /* |
| 659 | * If we don't have a conntrack entry then we're done. |
| 660 | */ |
| 661 | if (unlikely(!ct)) { |
| 662 | DEBUG_WARN("no ct in conntrack event callback\n"); |
| 663 | return NOTIFY_DONE; |
| 664 | } |
| 665 | |
| 666 | /* |
| 667 | * If this is an untracked connection then we can't have any state either. |
| 668 | */ |
| 669 | if (unlikely(ct == &nf_conntrack_untracked)) { |
| 670 | DEBUG_TRACE("ignoring untracked conn\n"); |
| 671 | return NOTIFY_DONE; |
| 672 | } |
| 673 | |
| 674 | /* |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 675 | * We're only interested in destroy events. |
| 676 | */ |
| 677 | if (unlikely(!(events & (1 << IPCT_DESTROY)))) { |
| 678 | DEBUG_TRACE("ignoring non-destroy event\n"); |
| 679 | return NOTIFY_DONE; |
| 680 | } |
| 681 | |
| 682 | orig_tuple = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple; |
| 683 | sid.protocol = (int32_t)orig_tuple.dst.protonum; |
| 684 | |
| 685 | /* |
| 686 | * Extract information from the conntrack connection. We're only interested |
| 687 | * in nominal connection information (i.e. we're ignoring any NAT information). |
| 688 | */ |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 689 | switch (sid.protocol) { |
| 690 | case IPPROTO_TCP: |
| 691 | sid.src_port = orig_tuple.src.u.tcp.port; |
| 692 | sid.dest_port = orig_tuple.dst.u.tcp.port; |
| 693 | break; |
| 694 | |
| 695 | case IPPROTO_UDP: |
| 696 | sid.src_port = orig_tuple.src.u.udp.port; |
| 697 | sid.dest_port = orig_tuple.dst.u.udp.port; |
| 698 | break; |
| 699 | |
| 700 | default: |
| 701 | DEBUG_TRACE("unhandled protocol: %d\n", sid.protocol); |
| 702 | return NOTIFY_DONE; |
| 703 | } |
| 704 | |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 705 | if (likely(nf_ct_l3num(ct) == AF_INET)) { |
| 706 | sid.src_ip.ip = (__be32)orig_tuple.src.u3.ip; |
| 707 | sid.dest_ip.ip = (__be32)orig_tuple.dst.u3.ip; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 708 | |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 709 | sfe_ipv4_destroy_rule(&sid); |
| 710 | } else if (likely(nf_ct_l3num(ct) == AF_INET6)) { |
| 711 | sid.src_ip.ip6[0] = *((struct sfe_ipv6_addr *)&orig_tuple.src.u3.in6); |
| 712 | sid.dest_ip.ip6[0] = *((struct sfe_ipv6_addr *)&orig_tuple.dst.u3.in6); |
| 713 | |
| 714 | sfe_ipv6_destroy_rule(&sid); |
| 715 | } else { |
| 716 | DEBUG_TRACE("ignoring non-IPv4 and non-IPv6 connection\n"); |
| 717 | } |
| 718 | |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 719 | return NOTIFY_DONE; |
| 720 | } |
| 721 | |
| 722 | /* |
| 723 | * Netfilter conntrack event system to monitor connection tracking changes |
| 724 | */ |
Matthew McClintock | 0680e9f | 2013-11-26 15:43:10 -0600 | [diff] [blame] | 725 | #ifdef CONFIG_NF_CONNTRACK_CHAIN_EVENTS |
| 726 | static struct notifier_block sfe_cm_conntrack_notifier = { |
| 727 | .notifier_call = sfe_cm_conntrack_event, |
| 728 | }; |
| 729 | #else |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 730 | static struct nf_ct_event_notifier sfe_cm_conntrack_notifier = { |
| 731 | .fcn = sfe_cm_conntrack_event, |
| 732 | }; |
| 733 | #endif |
Matthew McClintock | 0680e9f | 2013-11-26 15:43:10 -0600 | [diff] [blame] | 734 | #endif |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 735 | |
| 736 | /* |
| 737 | * Structure to establish a hook into the post routing netfilter point - this |
| 738 | * will pick up local outbound and packets going from one interface to another. |
| 739 | * |
| 740 | * Note: see include/linux/netfilter_ipv4.h for info related to priority levels. |
| 741 | * We want to examine packets after NAT translation and any ALG processing. |
| 742 | */ |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 743 | static struct nf_hook_ops sfe_cm_ops_post_routing[] __read_mostly = { |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 744 | { |
Xiaoping Fan | 3f1fe51 | 2014-11-05 12:14:57 -0800 | [diff] [blame] | 745 | .hook = __sfe_cm_ipv4_post_routing_hook, |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 746 | .owner = THIS_MODULE, |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 747 | .pf = NFPROTO_IPV4, |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 748 | .hooknum = NF_INET_POST_ROUTING, |
| 749 | .priority = NF_IP_PRI_NAT_SRC + 1, |
| 750 | }, |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 751 | #ifdef SFE_SUPPORT_IPV6 |
| 752 | { |
| 753 | .hook = __sfe_cm_ipv6_post_routing_hook, |
| 754 | .owner = THIS_MODULE, |
| 755 | .pf = NFPROTO_IPV6, |
| 756 | .hooknum = NF_INET_POST_ROUTING, |
| 757 | .priority = NF_IP6_PRI_NAT_SRC + 1, |
| 758 | }, |
| 759 | #endif |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 760 | }; |
| 761 | |
| 762 | /* |
| 763 | * sfe_cm_sync_rule() |
| 764 | * Synchronize a connection's state. |
| 765 | */ |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 766 | static void sfe_cm_sync_rule(struct sfe_connection_sync *sis) |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 767 | { |
| 768 | struct nf_conntrack_tuple_hash *h; |
| 769 | struct nf_conntrack_tuple tuple; |
| 770 | struct nf_conn *ct; |
Xiaoping Fan | 3f1fe51 | 2014-11-05 12:14:57 -0800 | [diff] [blame] | 771 | SFE_NF_CONN_ACCT(acct); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 772 | |
| 773 | /* |
| 774 | * Create a tuple so as to be able to look up a connection |
| 775 | */ |
| 776 | memset(&tuple, 0, sizeof(tuple)); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 777 | tuple.src.u.all = (__be16)sis->src_port; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 778 | tuple.dst.dir = IP_CT_DIR_ORIGINAL; |
| 779 | tuple.dst.protonum = (uint8_t)sis->protocol; |
| 780 | tuple.dst.u.all = (__be16)sis->dest_port; |
| 781 | |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 782 | if (sis->is_v6) { |
| 783 | tuple.src.u3.in6 = *((struct in6_addr *)sis->src_ip.ip6); |
| 784 | tuple.dst.u3.in6 = *((struct in6_addr *)sis->dest_ip.ip6); |
| 785 | tuple.src.l3num = AF_INET6; |
| 786 | |
| 787 | DEBUG_TRACE("update connection - p: %d, s: %pI6:%u, d: %pI6:%u\n", |
| 788 | (int)tuple.dst.protonum, |
| 789 | &tuple.src.u3.in6, (unsigned int)ntohs(tuple.src.u.all), |
| 790 | &tuple.dst.u3.in6, (unsigned int)ntohs(tuple.dst.u.all)); |
| 791 | } else { |
| 792 | tuple.src.u3.ip = sis->src_ip.ip; |
| 793 | tuple.dst.u3.ip = sis->dest_ip.ip; |
| 794 | tuple.src.l3num = AF_INET; |
| 795 | |
| 796 | DEBUG_TRACE("update connection - p: %d, s: %pI4:%u, d: %pI4:%u\n", |
| 797 | (int)tuple.dst.protonum, |
| 798 | &tuple.src.u3.ip, (unsigned int)ntohs(tuple.src.u.all), |
| 799 | &tuple.dst.u3.ip, (unsigned int)ntohs(tuple.dst.u.all)); |
| 800 | } |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 801 | |
| 802 | /* |
| 803 | * Look up conntrack connection |
| 804 | */ |
| 805 | h = nf_conntrack_find_get(&init_net, NF_CT_DEFAULT_ZONE, &tuple); |
| 806 | if (unlikely(!h)) { |
| 807 | DEBUG_TRACE("no connection found\n"); |
| 808 | return; |
| 809 | } |
| 810 | |
| 811 | ct = nf_ct_tuplehash_to_ctrack(h); |
| 812 | NF_CT_ASSERT(ct->timeout.data == (unsigned long)ct); |
| 813 | |
| 814 | /* |
| 815 | * Only update if this is not a fixed timeout |
| 816 | */ |
| 817 | if (!test_bit(IPS_FIXED_TIMEOUT_BIT, &ct->status)) { |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 818 | spin_lock_bh(&ct->lock); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 819 | ct->timeout.expires += sis->delta_jiffies; |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 820 | spin_unlock_bh(&ct->lock); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | acct = nf_conn_acct_find(ct); |
| 824 | if (acct) { |
| 825 | spin_lock_bh(&ct->lock); |
Xiaoping Fan | 3f1fe51 | 2014-11-05 12:14:57 -0800 | [diff] [blame] | 826 | atomic64_set(&SFE_ACCT_COUNTER(acct)[IP_CT_DIR_ORIGINAL].packets, sis->src_packet_count); |
| 827 | atomic64_set(&SFE_ACCT_COUNTER(acct)[IP_CT_DIR_ORIGINAL].bytes, sis->src_byte_count); |
| 828 | atomic64_set(&SFE_ACCT_COUNTER(acct)[IP_CT_DIR_REPLY].packets, sis->dest_packet_count); |
| 829 | atomic64_set(&SFE_ACCT_COUNTER(acct)[IP_CT_DIR_REPLY].bytes, sis->dest_byte_count); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 830 | spin_unlock_bh(&ct->lock); |
| 831 | } |
| 832 | |
| 833 | switch (sis->protocol) { |
| 834 | case IPPROTO_TCP: |
| 835 | spin_lock_bh(&ct->lock); |
| 836 | if (ct->proto.tcp.seen[0].td_maxwin < sis->src_td_max_window) { |
| 837 | ct->proto.tcp.seen[0].td_maxwin = sis->src_td_max_window; |
| 838 | } |
| 839 | if ((int32_t)(ct->proto.tcp.seen[0].td_end - sis->src_td_end) < 0) { |
| 840 | ct->proto.tcp.seen[0].td_end = sis->src_td_end; |
| 841 | } |
| 842 | if ((int32_t)(ct->proto.tcp.seen[0].td_maxend - sis->src_td_max_end) < 0) { |
| 843 | ct->proto.tcp.seen[0].td_maxend = sis->src_td_max_end; |
| 844 | } |
| 845 | if (ct->proto.tcp.seen[1].td_maxwin < sis->dest_td_max_window) { |
| 846 | ct->proto.tcp.seen[1].td_maxwin = sis->dest_td_max_window; |
| 847 | } |
| 848 | if ((int32_t)(ct->proto.tcp.seen[1].td_end - sis->dest_td_end) < 0) { |
| 849 | ct->proto.tcp.seen[1].td_end = sis->dest_td_end; |
| 850 | } |
| 851 | if ((int32_t)(ct->proto.tcp.seen[1].td_maxend - sis->dest_td_max_end) < 0) { |
| 852 | ct->proto.tcp.seen[1].td_maxend = sis->dest_td_max_end; |
| 853 | } |
| 854 | spin_unlock_bh(&ct->lock); |
| 855 | break; |
| 856 | } |
| 857 | |
| 858 | /* |
| 859 | * Release connection |
| 860 | */ |
| 861 | nf_ct_put(ct); |
| 862 | } |
| 863 | |
| 864 | /* |
| 865 | * sfe_cm_device_event() |
| 866 | */ |
| 867 | static int sfe_cm_device_event(struct notifier_block *this, unsigned long event, void *ptr) |
| 868 | { |
| 869 | struct net_device *dev = (struct net_device *)ptr; |
| 870 | |
| 871 | switch (event) { |
| 872 | case NETDEV_DOWN: |
| 873 | if (dev) { |
| 874 | sfe_ipv4_destroy_all_rules_for_dev(dev); |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 875 | sfe_ipv6_destroy_all_rules_for_dev(dev); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 876 | } |
| 877 | break; |
| 878 | } |
| 879 | |
| 880 | return NOTIFY_DONE; |
| 881 | } |
| 882 | |
| 883 | /* |
| 884 | * sfe_cm_inet_event() |
| 885 | */ |
| 886 | static int sfe_cm_inet_event(struct notifier_block *this, unsigned long event, void *ptr) |
| 887 | { |
| 888 | struct net_device *dev = ((struct in_ifaddr *)ptr)->ifa_dev->dev; |
| 889 | return sfe_cm_device_event(this, event, dev); |
| 890 | } |
| 891 | |
| 892 | /* |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 893 | * sfe_cm_inet6_event() |
| 894 | */ |
| 895 | static int sfe_cm_inet6_event(struct notifier_block *this, unsigned long event, void *ptr) |
| 896 | { |
| 897 | struct net_device *dev = ((struct inet6_ifaddr *)ptr)->idev->dev; |
| 898 | return sfe_cm_device_event(this, event, dev); |
| 899 | } |
| 900 | |
| 901 | /* |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 902 | * sfe_cm_get_exceptions |
| 903 | * dump exception counters |
| 904 | */ |
| 905 | static ssize_t sfe_cm_get_exceptions(struct device *dev, |
| 906 | struct device_attribute *attr, |
| 907 | char *buf) |
| 908 | { |
| 909 | int idx, len; |
| 910 | struct sfe_cm *sc = &__sc; |
| 911 | |
| 912 | spin_lock_bh(&sc->lock); |
| 913 | for (len = 0, idx = 0; idx < SFE_CM_EXCEPTION_MAX; idx++) { |
| 914 | if (sc->exceptions[idx]) { |
| 915 | len += sprintf(buf + len, "%s = %d\n", sfe_cm_exception_events_string[idx], sc->exceptions[idx]); |
| 916 | } |
| 917 | } |
| 918 | spin_unlock_bh(&sc->lock); |
| 919 | |
| 920 | return len; |
| 921 | } |
| 922 | |
| 923 | /* |
| 924 | * sysfs attributes. |
| 925 | */ |
| 926 | static const struct device_attribute sfe_cm_exceptions_attr = |
| 927 | __ATTR(exceptions, S_IRUGO, sfe_cm_get_exceptions, NULL); |
| 928 | |
| 929 | /* |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 930 | * sfe_cm_init() |
| 931 | */ |
| 932 | static int __init sfe_cm_init(void) |
| 933 | { |
| 934 | struct sfe_cm *sc = &__sc; |
| 935 | int result = -1; |
| 936 | |
| 937 | DEBUG_INFO("SFE CM init\n"); |
| 938 | |
| 939 | /* |
| 940 | * Create sys/sfe_cm |
| 941 | */ |
| 942 | sc->sys_sfe_cm = kobject_create_and_add("sfe_cm", NULL); |
| 943 | if (!sc->sys_sfe_cm) { |
| 944 | DEBUG_ERROR("failed to register sfe_cm\n"); |
| 945 | goto exit1; |
| 946 | } |
| 947 | |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 948 | /* |
| 949 | * Create sys/sfe_cm/exceptions |
| 950 | */ |
| 951 | result = sysfs_create_file(sc->sys_sfe_cm, &sfe_cm_exceptions_attr.attr); |
| 952 | if (result) { |
| 953 | DEBUG_ERROR("failed to register exceptions file: %d\n", result); |
| 954 | goto exit2; |
| 955 | } |
| 956 | |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 957 | sc->dev_notifier.notifier_call = sfe_cm_device_event; |
| 958 | sc->dev_notifier.priority = 1; |
| 959 | register_netdevice_notifier(&sc->dev_notifier); |
| 960 | |
| 961 | sc->inet_notifier.notifier_call = sfe_cm_inet_event; |
| 962 | sc->inet_notifier.priority = 1; |
| 963 | register_inetaddr_notifier(&sc->inet_notifier); |
| 964 | |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 965 | sc->inet6_notifier.notifier_call = sfe_cm_inet6_event; |
| 966 | sc->inet6_notifier.priority = 1; |
| 967 | register_inet6addr_notifier(&sc->inet6_notifier); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 968 | /* |
| 969 | * Register our netfilter hooks. |
| 970 | */ |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 971 | result = nf_register_hooks(sfe_cm_ops_post_routing, ARRAY_SIZE(sfe_cm_ops_post_routing)); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 972 | if (result < 0) { |
| 973 | DEBUG_ERROR("can't register nf post routing hook: %d\n", result); |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 974 | goto exit3; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | #ifdef CONFIG_NF_CONNTRACK_EVENTS |
| 978 | /* |
| 979 | * Register a notifier hook to get fast notifications of expired connections. |
| 980 | */ |
| 981 | result = nf_conntrack_register_notifier(&init_net, &sfe_cm_conntrack_notifier); |
| 982 | if (result < 0) { |
| 983 | DEBUG_ERROR("can't register nf notifier hook: %d\n", result); |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 984 | goto exit4; |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 985 | } |
| 986 | #endif |
| 987 | |
| 988 | spin_lock_init(&sc->lock); |
| 989 | |
| 990 | /* |
| 991 | * Hook the receive path in the network stack. |
| 992 | */ |
| 993 | BUG_ON(athrs_fast_nat_recv != NULL); |
| 994 | RCU_INIT_POINTER(athrs_fast_nat_recv, sfe_cm_recv); |
| 995 | |
| 996 | /* |
| 997 | * Hook the shortcut sync callback. |
| 998 | */ |
| 999 | sfe_ipv4_register_sync_rule_callback(sfe_cm_sync_rule); |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 1000 | sfe_ipv6_register_sync_rule_callback(sfe_cm_sync_rule); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 1001 | return 0; |
| 1002 | |
| 1003 | #ifdef CONFIG_NF_CONNTRACK_EVENTS |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 1004 | exit4: |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 1005 | #endif |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 1006 | nf_unregister_hooks(sfe_cm_ops_post_routing, ARRAY_SIZE(sfe_cm_ops_post_routing)); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 1007 | |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 1008 | exit3: |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 1009 | unregister_inet6addr_notifier(&sc->inet6_notifier); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 1010 | unregister_inetaddr_notifier(&sc->inet_notifier); |
| 1011 | unregister_netdevice_notifier(&sc->dev_notifier); |
Xiaoping Fan | 82c2151 | 2015-06-30 01:15:23 -0700 | [diff] [blame^] | 1012 | exit2: |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 1013 | kobject_put(sc->sys_sfe_cm); |
| 1014 | |
| 1015 | exit1: |
| 1016 | return result; |
| 1017 | } |
| 1018 | |
| 1019 | /* |
| 1020 | * sfe_cm_exit() |
| 1021 | */ |
| 1022 | static void __exit sfe_cm_exit(void) |
| 1023 | { |
| 1024 | struct sfe_cm *sc = &__sc; |
| 1025 | |
| 1026 | DEBUG_INFO("SFE CM exit\n"); |
| 1027 | |
| 1028 | /* |
| 1029 | * Unregister our sync callback. |
| 1030 | */ |
| 1031 | sfe_ipv4_register_sync_rule_callback(NULL); |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 1032 | sfe_ipv6_register_sync_rule_callback(NULL); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 1033 | |
| 1034 | /* |
| 1035 | * Unregister our receive callback. |
| 1036 | */ |
| 1037 | RCU_INIT_POINTER(athrs_fast_nat_recv, NULL); |
| 1038 | |
| 1039 | /* |
| 1040 | * Wait for all callbacks to complete. |
| 1041 | */ |
| 1042 | rcu_barrier(); |
| 1043 | |
| 1044 | /* |
| 1045 | * Destroy all connections. |
| 1046 | */ |
| 1047 | sfe_ipv4_destroy_all_rules_for_dev(NULL); |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 1048 | sfe_ipv6_destroy_all_rules_for_dev(NULL); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 1049 | |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 1050 | #ifdef CONFIG_NF_CONNTRACK_EVENTS |
| 1051 | nf_conntrack_unregister_notifier(&init_net, &sfe_cm_conntrack_notifier); |
| 1052 | |
| 1053 | #endif |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 1054 | nf_unregister_hooks(sfe_cm_ops_post_routing, ARRAY_SIZE(sfe_cm_ops_post_routing)); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 1055 | |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 1056 | unregister_inet6addr_notifier(&sc->inet6_notifier); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 1057 | unregister_inetaddr_notifier(&sc->inet_notifier); |
| 1058 | unregister_netdevice_notifier(&sc->dev_notifier); |
| 1059 | |
| 1060 | kobject_put(sc->sys_sfe_cm); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | module_init(sfe_cm_init) |
| 1064 | module_exit(sfe_cm_exit) |
| 1065 | |
| 1066 | MODULE_AUTHOR("Qualcomm Atheros Inc."); |
| 1067 | MODULE_DESCRIPTION("Shortcut Forwarding Engine - Connection Manager"); |
Matthew McClintock | a322194 | 2014-01-16 11:44:26 -0600 | [diff] [blame] | 1068 | MODULE_LICENSE("Dual BSD/GPL"); |
Dave Hudson | dcd08fb | 2013-11-22 09:25:16 -0600 | [diff] [blame] | 1069 | |