Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Murat Sezgin | 341b33e | 2019-06-20 15:29:33 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2020 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 | eebedb9 | 2017-11-17 17:14:32 -0800 | [diff] [blame] | 17 | extern int ecm_interface_src_check; /* Source interface check flag */ |
Manish Verma | d44beae | 2019-08-16 21:16:20 +0530 | [diff] [blame] | 18 | #ifdef CONFIG_NET_CLS_ACT |
| 19 | extern int ecm_interface_igs_enabled; /* IGS enabled check flag */ |
| 20 | #endif |
Murat Sezgin | eebedb9 | 2017-11-17 17:14:32 -0800 | [diff] [blame] | 21 | |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 22 | /* |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 23 | * struct ecm_interface_route |
| 24 | * An ecm route supports either v4 or v6 routing information |
| 25 | */ |
| 26 | struct ecm_interface_route { |
Murat Sezgin | 313f222 | 2016-08-11 12:22:10 -0700 | [diff] [blame] | 27 | struct dst_entry *dst; /* Both ipv4 and v6 have a common dst entry. It is an overlay pointer of rtv4 or rtv6 */ |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 28 | union { |
| 29 | struct rtable *rtv4; /* IPv4 route */ |
| 30 | struct rt6_info *rtv6; /* IPv6 route */ |
| 31 | } rt; |
| 32 | bool v4_route; /* True when a v4 route, false when v6 */ |
| 33 | }; |
| 34 | |
| 35 | /* |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 36 | * Netdev Index value for a Loopback device |
| 37 | */ |
| 38 | #define ECM_INTERFACE_LOOPBACK_DEV_INDEX 1 |
| 39 | |
| 40 | /* |
Thomas Wu | 0d64598 | 2016-01-24 12:27:54 -0800 | [diff] [blame] | 41 | * IPSec Core and Interface Definition |
| 42 | */ |
| 43 | #define ECM_INTERFACE_IPSEC_DEFAULT_CORE 0x2 |
| 44 | #define ECM_INTERFACE_IPSEC_CORE_OFFSET 24 |
Thomas Wu | 0d64598 | 2016-01-24 12:27:54 -0800 | [diff] [blame] | 45 | |
| 46 | /* |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 47 | * External defined functions |
| 48 | */ |
| 49 | extern struct net_device *bond_get_tx_dev(struct sk_buff *skb, uint8_t *src_mac, |
| 50 | uint8_t *dst_mac, void *src, |
| 51 | void *dst, uint16_t protocol, |
Suman Ghosh | fb8e770 | 2015-08-20 15:27:57 +0530 | [diff] [blame] | 52 | struct net_device *bond_dev, |
| 53 | __be16 *layer4hdr); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 54 | bool ecm_interface_mac_addr_get_no_route(struct net_device *dev, ip_addr_t ip_addr, uint8_t *mac_addr); |
Ben Menchaca | 84f3663 | 2014-02-28 20:57:38 +0000 | [diff] [blame] | 55 | bool ecm_interface_mac_addr_get(ip_addr_t addr, uint8_t *mac_addr, bool *on_link, ip_addr_t gw_addr); |
| 56 | bool ecm_interface_find_route_by_addr(ip_addr_t addr, struct ecm_interface_route *ecm_rt); |
| 57 | void ecm_interface_route_release(struct ecm_interface_route *rt); |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 58 | #ifdef ECM_IPV6_ENABLE |
| 59 | void ecm_interface_send_neighbour_solicitation(struct net_device *dev, ip_addr_t addr); |
| 60 | #endif |
| 61 | void ecm_interface_send_arp_request(struct net_device *dest_dev, ip_addr_t dest_addr, bool on_link, ip_addr_t gw_addr); |
Xiaoping Fan | c773546 | 2015-08-09 18:57:26 -0700 | [diff] [blame] | 62 | struct neighbour *ecm_interface_ipv4_neigh_get(ip_addr_t addr); |
| 63 | #ifdef ECM_IPV6_ENABLE |
| 64 | struct neighbour *ecm_interface_ipv6_neigh_get(ip_addr_t addr); |
| 65 | #endif |
Shyam Sunder | 2ca0249 | 2016-08-05 20:55:12 +0530 | [diff] [blame] | 66 | bool ecm_interface_is_pptp(struct sk_buff *skb, const struct net_device *out); |
| 67 | bool ecm_interface_is_l2tp_packet_by_version(struct sk_buff *skb, const struct net_device *out, int ver); |
| 68 | bool ecm_interface_is_l2tp_pptp(struct sk_buff *skb, const struct net_device *out); |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 69 | struct ecm_db_iface_instance *ecm_interface_establish_and_ref(struct ecm_front_end_connection_instance *feci, struct net_device *dev, struct sk_buff *skb); |
Murat Sezgin | 341b33e | 2019-06-20 15:29:33 -0700 | [diff] [blame] | 70 | #ifdef ECM_INTERFACE_OVS_BRIDGE_ENABLE |
| 71 | bool ecm_interface_is_ovs_bridge_port(const struct net_device *dev); |
| 72 | #endif |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 73 | #ifdef ECM_MULTICAST_ENABLE |
Shyam Sunder | a2e08ee | 2015-06-18 21:32:13 +0530 | [diff] [blame] | 74 | int32_t ecm_interface_multicast_heirarchy_construct_routed(struct ecm_front_end_connection_instance *feci, struct ecm_db_iface_instance *interfaces, struct net_device *in_dev, ip_addr_t packet_src_addr, ip_addr_t packet_dest_addr, uint8_t maxvif, uint32_t *dst_dev, uint32_t *to_interface_first, bool mfc_update, __be16 *layer4hdr, struct sk_buff *skb); |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 75 | |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 76 | int32_t ecm_interface_multicast_heirarchy_construct_bridged(struct ecm_front_end_connection_instance *feci, struct ecm_db_iface_instance *interfaces, struct net_device *br_dev, ip_addr_t src_addr, ip_addr_t dest_addr, uint8_t mc_max_dst, int32_t *mc_dst_dev, uint32_t *to_interface_first, uint8_t *src_node_addr, __be16 *layer4hdr, struct sk_buff *skb); |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 77 | |
| 78 | void ecm_interface_multicast_stats_update(struct ecm_db_connection_instance *ci, uint32_t from_tx_packets, uint32_t from_tx_bytes, uint32_t from_rx_packets, uint32_t from_rx_bytes, uint32_t to_tx_packets, uint32_t to_tx_bytes, uint32_t to_rx_packets, uint32_t to_rx_bytes); |
| 79 | |
Suman Ghosh | e1c939c | 2019-11-12 20:43:04 +0530 | [diff] [blame] | 80 | bool ecm_interface_multicast_find_updates_to_iface_list(struct ecm_db_connection_instance *ci, struct ecm_multicast_if_update *, uint32_t flags, bool is_br_snooper, uint32_t *dst_dev, uint32_t max_to_dev, struct net_device *brdev); |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 81 | |
| 82 | bool ecm_interface_multicast_check_for_br_dev(uint32_t dest_if[], uint8_t max_if); |
ratheesh kannoth | c5df16c | 2018-03-16 21:07:23 +0530 | [diff] [blame] | 83 | bool ecm_interface_multicast_is_iface_type(int32_t mc_if_index[], int32_t max_if_index, unsigned short type); |
Shyam Sunder | a2e08ee | 2015-06-18 21:32:13 +0530 | [diff] [blame] | 84 | |
| 85 | int32_t ecm_interface_multicast_check_for_src_ifindex(int32_t mc_if_index[], int32_t max_if_index, int32_t if_num); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 86 | int32_t ecm_interface_multicast_from_heirarchy_construct(struct ecm_front_end_connection_instance *feci, |
Murat Sezgin | 91c5d71 | 2015-06-12 15:16:22 -0700 | [diff] [blame] | 87 | struct ecm_db_iface_instance *interfaces[], |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 88 | ip_addr_t packet_src_addr, ip_addr_t packet_dest_addr, |
| 89 | int ip_version, int packet_protocol, |
| 90 | struct net_device *given_dest_dev, bool is_routed, |
| 91 | struct net_device *given_src_dev, |
Suman Ghosh | fb8e770 | 2015-08-20 15:27:57 +0530 | [diff] [blame] | 92 | uint8_t *dest_node_addr, uint8_t *src_node_addr, |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 93 | __be16 *layer4hdr, struct sk_buff *skb); |
Suman Ghosh | a11fc92 | 2020-01-08 14:34:03 +0530 | [diff] [blame] | 94 | #ifdef ECM_INTERFACE_OVS_BRIDGE_ENABLE |
| 95 | bool ecm_interface_multicast_check_for_ovs_br_dev(uint32_t dest_if[], uint8_t max_if); |
| 96 | int ecm_interface_multicast_ovs_to_interface_get_and_ref(struct ecm_db_connection_instance *ci, |
| 97 | struct net_device **to_ovs_port, |
| 98 | struct net_device **to_ovs_brdev); |
| 99 | #endif |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 100 | #endif |
| 101 | |
| 102 | int32_t ecm_interface_heirarchy_construct(struct ecm_front_end_connection_instance *feci, |
| 103 | struct ecm_db_iface_instance *interfaces[], |
| 104 | struct net_device *const_if, struct net_device *other_if, |
Murat Sezgin | f92db49 | 2016-07-15 11:33:15 -0700 | [diff] [blame] | 105 | ip_addr_t lookup_src_addr, |
| 106 | ip_addr_t lookup_dest_addr, |
| 107 | ip_addr_t real_dest_addr, |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 108 | int ip_version, int packet_protocol, |
| 109 | struct net_device *given_dest_dev, |
| 110 | bool is_routed, struct net_device *given_src_dev, |
| 111 | uint8_t *dest_node_addr, uint8_t *src_node_addr, |
Bhaskar Valaboju | c67adef | 2020-07-29 00:12:27 +0530 | [diff] [blame^] | 112 | __be16 *layer4hdr, struct sk_buff *skb, struct ecm_front_end_ovs_params *op); |
Murat Sezgin | 188b4a3 | 2015-06-03 10:58:59 -0700 | [diff] [blame] | 113 | void ecm_interface_stats_update(struct ecm_db_connection_instance *ci, uint32_t from_tx_packets, uint32_t from_tx_bytes, uint32_t from_rx_packets, uint32_t from_rx_bytes, uint32_t to_tx_packets, uint32_t to_tx_bytes, uint32_t to_rx_packets, uint32_t to_rx_bytes); |
Gareth Williams | 46f4b5f | 2014-06-01 23:35:23 +0100 | [diff] [blame] | 114 | struct net_device *ecm_interface_dev_find_by_addr(ip_addr_t addr, bool *from_local_addr); |
Shyam Sunder | 6358b86 | 2015-05-04 15:06:24 +0530 | [diff] [blame] | 115 | |
Murat Sezgin | b3731e8 | 2014-11-26 12:20:59 -0800 | [diff] [blame] | 116 | struct net_device *ecm_interface_get_and_hold_dev_master(struct net_device *dev); |
Tushar Mathur | cccbf28 | 2015-01-13 01:22:44 +0530 | [diff] [blame] | 117 | void ecm_interface_dev_regenerate_connections(struct net_device *dev); |
ratheesh kannoth | a32fdd1 | 2015-09-09 08:02:58 +0530 | [diff] [blame] | 118 | struct net_device *ecm_interface_dev_find_by_local_addr(ip_addr_t addr); |
Murat Sezgin | 5dae883 | 2015-12-03 14:23:19 -0800 | [diff] [blame] | 119 | bool ecm_interface_find_gateway(ip_addr_t addr, ip_addr_t gw_addr); |
Suman Ghosh | 7a26171 | 2016-01-12 21:42:55 +0530 | [diff] [blame] | 120 | void ecm_interface_dev_defunct_connections(struct net_device *dev); |
Murat Sezgin | 99cee22 | 2019-11-03 19:31:01 -0800 | [diff] [blame] | 121 | void ecm_interface_node_connections_defunct(uint8_t *mac, int ip_version); |
Murat Sezgin | 719434a | 2019-04-12 16:29:13 -0700 | [diff] [blame] | 122 | bool ecm_interface_tunnel_mtu_update(ip_addr_t saddr, ip_addr_t daddr, ecm_db_iface_type_t type, int32_t *mtu); |