Line data Source code
1 : /* 2 : * nexthop.h -- 3 : * 4 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 5 : */ 6 : #ifndef __NEXTHOP_H__ 7 : #define __NEXTHOP_H__ 8 : 9 : #include "vr_defs.h" 10 : 11 : #ifdef __cplusplus 12 : extern "C" { 13 : #endif 14 : 15 : #include "vr_os.h" 16 : #include "vr_types.h" 17 : #include "vr_interface.h" 18 : 19 : #define VR_DEF_NEXTHOPS 524288 20 : #define NH_TABLE_ENTRIES VR_DEF_NEXTHOPS 21 : 22 : #define VR_NEXTHOP_COMPONENT_DUMP_LIMIT 16 23 : 24 : #define NH_DISCARD_ID 0 25 : 26 : enum nexthop_type { 27 : NH_DEAD, 28 : NH_RCV, 29 : NH_ENCAP, 30 : NH_TUNNEL, 31 : NH_RESOLVE, 32 : NH_DISCARD, 33 : NH_COMPOSITE, 34 : NH_VRF_TRANSLATE, 35 : NH_L2_RCV, 36 : NH_MAX, 37 : }; 38 : 39 : #define NH_VXLAN_VRF NH_VRF_TRANSLATE 40 : 41 : #define NH_FLAG_VALID 0x000001 42 : #define NH_FLAG_POLICY_ENABLED 0x000002 43 : /* 0x000004 is free */ 44 : #define NH_FLAG_TUNNEL_GRE 0x000008 45 : #define NH_FLAG_TUNNEL_UDP 0x000010 46 : /* 47 : * Mcast flag can be appended to any type of nexthop, either an Encap, 48 : * composite etc 49 : */ 50 : #define NH_FLAG_MCAST 0x000020 51 : #define NH_FLAG_TUNNEL_UDP_MPLS 0x000040 52 : #define NH_FLAG_TUNNEL_VXLAN 0x000080 53 : #define NH_FLAG_RELAXED_POLICY 0x000100 54 : #define NH_FLAG_COMPOSITE_FABRIC 0x000200 55 : #define NH_FLAG_COMPOSITE_ECMP 0x000400 56 : #define NH_FLAG_COMPOSITE_LU_ECMP 0x000800 57 : #define NH_FLAG_COMPOSITE_EVPN 0x001000 58 : #define NH_FLAG_COMPOSITE_ENCAP 0x002000 59 : #define NH_FLAG_COMPOSITE_TOR 0x004000 60 : #define NH_FLAG_ROUTE_LOOKUP 0x008000 61 : #define NH_FLAG_UNKNOWN_UC_FLOOD 0x010000 62 : #define NH_FLAG_TUNNEL_SIP_COPY 0x020000 63 : #define NH_FLAG_FLOW_LOOKUP 0x040000 64 : #define NH_FLAG_TUNNEL_PBB 0x080000 65 : #define NH_FLAG_MAC_LEARN 0x100000 66 : #define NH_FLAG_ETREE_ROOT 0x200000 67 : #define NH_FLAG_INDIRECT 0x400000 68 : #define NH_FLAG_L2_CONTROL_DATA 0x800000 69 : #define NH_FLAG_CRYPT_TRAFFIC 0x01000000 70 : #define NH_FLAG_L3_VXLAN 0x02000000 71 : #define NH_FLAG_TUNNEL_MPLS_O_MPLS 0x04000000 72 : #define NH_FLAG_VALIDATE_MCAST_SRC 0x08000000 73 : #define NH_FLAG_TUNNEL_UNDERLAY_ECMP 0x10000000 74 : 75 : #define NH_SOURCE_INVALID 0 76 : #define NH_SOURCE_VALID 1 77 : #define NH_SOURCE_MISMATCH 2 78 : 79 : 80 : #define NH_ECMP_CONFIG_HASH_BITS 5 81 : #define NH_ECMP_CONFIG_HASH_MASK ((1 << NH_ECMP_CONFIG_HASH_BITS) - 1) 82 : #define NH_ECMP_CONFIG_HASH_PROTO 0x01 83 : #define NH_ECMP_CONFIG_HASH_SRC_IP 0x02 84 : #define NH_ECMP_CONFIG_HASH_SRC_PORT 0x04 85 : #define NH_ECMP_CONFIG_HASH_DST_IP 0x08 86 : #define NH_ECMP_CONFIG_HASH_DST_PORT 0x10 87 : 88 : #define NH_ECMP_PACKET_HELD (-2) 89 : 90 : struct vr_packet; 91 : 92 : struct vr_forwarding_md; 93 : 94 : struct vr_component_nh { 95 : int cnh_label; 96 : int cnh_ecmp_index; 97 : struct vr_nexthop *cnh; 98 : }; 99 : 100 : typedef enum { 101 : NH_PROCESSING_COMPLETE, 102 : NH_PROCESSING_INCOMPLETE, 103 : } nh_processing_t; 104 : 105 : struct vr_nexthop { 106 : uint8_t nh_type; 107 : /* 108 : * nh_family is going to be AF_INET for L3 nexthops, AF_BRIDGE for L2 109 : * nexthops 110 : */ 111 : uint8_t nh_family; 112 : /* nh_data_size = encap_size * number of physical interfaces */ 113 : uint16_t nh_data_size; 114 : uint32_t nh_flags; 115 : int nh_vrf; 116 : unsigned int nh_id; 117 : unsigned int nh_rid; 118 : unsigned int nh_users; 119 : union { 120 : struct { 121 : uint16_t encap_len; 122 : uint16_t encap_family; 123 : } nh_encap; 124 : 125 : struct { 126 : unsigned int tun_sip; 127 : unsigned int tun_dip; 128 : uint16_t tun_encap_len; 129 : uint32_t transport_label; 130 : } nh_gre_tun; 131 : 132 : struct nh_udp_tun_ { 133 : unsigned int tun_sip; 134 : unsigned int tun_dip; 135 : unsigned short tun_sport; 136 : unsigned short tun_dport; 137 : uint16_t tun_encap_len; 138 : uint32_t transport_label; 139 : } nh_udp_tun; 140 : 141 : struct { 142 : struct nh_udp_tun_ udp_tun; 143 : uint8_t tun_l3_mac[VR_ETHER_ALEN]; 144 : } nh_vxlan_tun; 145 : 146 : struct { 147 : int tun_pbb_label; 148 : uint8_t tun_pbb_mac[VR_ETHER_ALEN]; 149 : } nh_pbb_tun; 150 : 151 : struct { 152 : uint8_t *tun_sip6; 153 : uint8_t *tun_dip6; 154 : unsigned short tun_sport6; 155 : unsigned short tun_dport6; 156 : uint16_t tun_encap_len; 157 : } nh_udp_tun6; 158 : 159 : struct { 160 : unsigned short cnt; 161 : unsigned short ecmp_cnt; 162 : unsigned short ecmp_config_hash; 163 : struct vr_component_nh *component; 164 : struct vr_component_nh *ecmp_active; 165 : } nh_composite; 166 : 167 : } nh_u; 168 : 169 : struct vrouter *nh_router; 170 : struct vr_nexthop *nh_direct_nh; 171 : int (*nh_validate_src)(struct vr_packet *, 172 : struct vr_nexthop *, 173 : struct vr_forwarding_md *, 174 : void *); 175 : nh_processing_t (*nh_reach_nh)(struct vr_packet *, 176 : struct vr_nexthop *, 177 : struct vr_forwarding_md *); 178 : struct vr_interface *nh_crypt_dev; 179 : void (*nh_destructor)(struct vr_nexthop *); 180 : struct vr_interface *nh_dev_arr[VR_MAX_PHY_INF]; 181 : uint8_t nh_encap_valid[VR_MAX_PHY_INF]; 182 : struct vr_interface *nh_valid_underlay_dev[VR_MAX_PHY_INF]; 183 : int nh_valid_underlay_dev_count; 184 : uint8_t nh_data[]; 185 : }; 186 : 187 : #define nh_dev nh_dev_arr[0] 188 : #define nh_encap_family nh_u.nh_encap.encap_family 189 : #define nh_encap_len nh_u.nh_encap.encap_len 190 : 191 : #define nh_gre_tun_sip nh_u.nh_gre_tun.tun_sip 192 : #define nh_gre_tun_dip nh_u.nh_gre_tun.tun_dip 193 : #define nh_gre_tun_label nh_u.nh_gre_tun.transport_label 194 : 195 : #define nh_udp_tun_sip nh_u.nh_udp_tun.tun_sip 196 : #define nh_udp_tun_dip nh_u.nh_udp_tun.tun_dip 197 : #define nh_udp_tun_sport nh_u.nh_udp_tun.tun_sport 198 : #define nh_udp_tun_dport nh_u.nh_udp_tun.tun_dport 199 : #define nh_udp_tun_encap_len nh_u.nh_udp_tun.tun_encap_len 200 : #define nh_udp_tun_label nh_u.nh_udp_tun.transport_label 201 : 202 : #define nh_udp_tun6_sip nh_u.nh_udp_tun6.tun_sip6 203 : #define nh_udp_tun6_dip nh_u.nh_udp_tun6.tun_dip6 204 : #define nh_udp_tun6_sport nh_u.nh_udp_tun6.tun_sport6 205 : #define nh_udp_tun6_dport nh_u.nh_udp_tun6.tun_dport6 206 : #define nh_udp_tun6_encap_len nh_u.nh_udp_tun6.tun_encap_len 207 : 208 : #define nh_gre_tun_encap_len nh_u.nh_gre_tun.tun_encap_len 209 : 210 : #define nh_component_cnt nh_u.nh_composite.cnt 211 : #define nh_component_nh nh_u.nh_composite.component 212 : #define nh_component_ecmp_cnt nh_u.nh_composite.ecmp_cnt 213 : #define nh_component_ecmp nh_u.nh_composite.ecmp_active 214 : #define nh_ecmp_config_hash nh_u.nh_composite.ecmp_config_hash 215 : 216 : #define nh_pbb_mac nh_u.nh_pbb_tun.tun_pbb_mac 217 : #define nh_pbb_label nh_u.nh_pbb_tun.tun_pbb_label 218 : 219 : #define nh_vxlan_tun_sip nh_u.nh_vxlan_tun.udp_tun.tun_sip 220 : #define nh_vxlan_tun_dip nh_u.nh_vxlan_tun.udp_tun.tun_dip 221 : #define nh_vxlan_tun_encap_len nh_u.nh_vxlan_tun.udp_tun.tun_encap_len 222 : #define nh_vxlan_tun_l3_mac nh_u.nh_vxlan_tun.tun_l3_mac 223 : 224 : static inline bool 225 0 : vr_nexthop_is_vcp(struct vr_nexthop *nh) 226 : { 227 0 : if (nh && (nh->nh_type == NH_RESOLVE)) 228 0 : return true; 229 : 230 0 : return false; 231 : } 232 : 233 : extern int vr_nexthop_init(struct vrouter *); 234 : extern void vr_nexthop_exit(struct vrouter *, bool); 235 : extern struct vr_nexthop *__vrouter_get_nexthop(struct vrouter *, unsigned int); 236 : extern struct vr_nexthop *vrouter_get_nexthop(unsigned int, unsigned int); 237 : extern void vrouter_put_nexthop(struct vr_nexthop *); 238 : extern int vr_ip_rcv(struct vrouter *, struct vr_packet *, 239 : struct vr_forwarding_md *); 240 : extern int nh_output(struct vr_packet *, 241 : struct vr_nexthop *, struct vr_forwarding_md *); 242 : extern int vr_nexthop_add(vr_nexthop_req *); 243 : extern int vr_nexthop_get(vr_nexthop_req *); 244 : extern int vr_nexthop_dump(vr_nexthop_req *); 245 : extern bool vr_gateway_nexthop(struct vr_nexthop *); 246 : extern bool vr_hosted_nexthop(struct vr_nexthop *); 247 : extern unsigned int vr_nexthop_req_get_size(void *); 248 : extern int vr_is_local_ecmp_nh(struct vr_nexthop *nh); 249 : extern struct vr_interface *vr_get_ecmp_first_member_dev(struct vr_nexthop *nh); 250 : 251 : extern struct vr_nexthop *vr_discard_nh; 252 : 253 : extern nh_processing_t nh_discard(struct vr_packet *pkt, struct vr_nexthop *nh, 254 : struct vr_forwarding_md *fmd); 255 : 256 : /* returns whether nexthop is currently being edited by vr_nexthop_add and thus 257 : * may be in inconsistent state */ 258 82 : static inline bool vr_nexthop_is_being_edited(const struct vr_nexthop *nh) { 259 82 : return nh->nh_reach_nh == nh_discard && nh->nh_type != NH_DISCARD; 260 : } 261 : 262 : #ifdef __cplusplus 263 : } 264 : #endif 265 : 266 : #endif /* __VNSW_NEXTHOP_H__ */