LCOV - code coverage report
Current view: top level - root/contrail/vrouter/include - vr_nexthop.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 2 6 33.3 %
Date: 2026-11-09 02:10:49 Functions: 1 2 50.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14