/
vr_nexthop.h
170 lines (147 loc) · 5.25 KB
/
vr_nexthop.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
* nexthop.h --
*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#ifndef __NEXTHOP_H__
#define __NEXTHOP_H__
#ifdef __cplusplus
extern "C" {
#endif
/*
* nexthop id is also part of the flow key and is only 16 bits. Hence, you
* know where you are getting into if you want to increase this limit
*/
#define VR_DEF_NEXTHOPS 65536
#define NH_TABLE_ENTRIES VR_DEF_NEXTHOPS
#define VR_NEXTHOP_COMPONENT_DUMP_LIMIT 16
#define NH_DISCARD_ID 0
enum nexthop_type {
NH_DEAD,
NH_RCV,
NH_ENCAP,
NH_TUNNEL,
NH_RESOLVE,
NH_DISCARD,
NH_COMPOSITE,
NH_VRF_TRANSLATE,
NH_L2_RCV,
NH_MAX,
};
#define NH_VXLAN_VRF NH_VRF_TRANSLATE
#define NH_FLAG_VALID 0x00001
#define NH_FLAG_POLICY_ENABLED 0x00002
#define NH_FLAG_ENCAP_L2 0x00004
#define NH_FLAG_TUNNEL_GRE 0x00008
#define NH_FLAG_TUNNEL_UDP 0x00010
/*
* Mcast flag can be appended to any type of nexthop, either an Encap,
* composite etc
*/
#define NH_FLAG_MCAST 0x00020
#define NH_FLAG_TUNNEL_UDP_MPLS 0x00040
#define NH_FLAG_TUNNEL_VXLAN 0x00080
#define NH_FLAG_RELAXED_POLICY 0x00100
#define NH_FLAG_COMPOSITE_FABRIC 0x00200
#define NH_FLAG_COMPOSITE_ECMP 0x00400
#define NH_FLAG_COMPOSITE_L2 0x00800
#define NH_FLAG_COMPOSITE_EVPN 0x01000
#define NH_FLAG_COMPOSITE_ENCAP 0x02000
#define NH_FLAG_COMPOSITE_TOR 0x04000
#define NH_FLAG_VNID 0x08000
#define NH_FLAG_ROUTE_LOOKUP 0x10000
#define NH_FLAG_UNKNOWN_UC_FLOOD 0x20000
#define NH_SOURCE_INVALID 0
#define NH_SOURCE_VALID 1
#define NH_SOURCE_MISMATCH 2
struct vr_packet;
struct vr_forwarding_md;
struct vr_component_nh {
int cnh_label;
struct vr_nexthop *cnh;
};
struct vr_nexthop {
uint8_t nh_type;
/*
* nh_family is going to be AF_INET for L3 nexthops, AF_BRIDGE for L2
* nexthops
*/
uint8_t nh_family;
uint32_t nh_flags;
int nh_vrf;
unsigned int nh_id;
unsigned int nh_rid;
unsigned int nh_users;
union {
struct {
uint16_t encap_len;
uint16_t encap_family;
} nh_encap;
struct {
unsigned int tun_sip;
unsigned int tun_dip;
uint16_t tun_encap_len;
} nh_gre_tun;
struct {
unsigned int tun_sip;
unsigned int tun_dip;
unsigned short tun_sport;
unsigned short tun_dport;
uint16_t tun_encap_len;
} nh_udp_tun;
struct {
unsigned short cnt;
struct vr_component_nh *component;
} nh_composite;
} nh_u;
uint16_t nh_data_size;
struct vrouter *nh_router;
int (*nh_validate_src)(struct vr_packet *,
struct vr_nexthop *,
struct vr_forwarding_md *,
void *);
int (*nh_reach_nh)(struct vr_packet *,
struct vr_nexthop *,
struct vr_forwarding_md *);
struct vr_interface *nh_dev;
void (*nh_destructor)(struct vr_nexthop *);
uint8_t nh_data[0];
};
#define nh_encap_family nh_u.nh_encap.encap_family
#define nh_encap_len nh_u.nh_encap.encap_len
#define nh_gre_tun_sip nh_u.nh_gre_tun.tun_sip
#define nh_gre_tun_dip nh_u.nh_gre_tun.tun_dip
#define nh_udp_tun_sip nh_u.nh_udp_tun.tun_sip
#define nh_udp_tun_dip nh_u.nh_udp_tun.tun_dip
#define nh_udp_tun_sport nh_u.nh_udp_tun.tun_sport
#define nh_udp_tun_dport nh_u.nh_udp_tun.tun_dport
#define nh_gre_tun_encap_len nh_u.nh_gre_tun.tun_encap_len
#define nh_udp_tun_encap_len nh_u.nh_udp_tun.tun_encap_len
#define nh_component_cnt nh_u.nh_composite.cnt
#define nh_component_nh nh_u.nh_composite.component
static inline bool
vr_nexthop_is_vcp(struct vr_nexthop *nh)
{
if (nh && (nh->nh_type == NH_RESOLVE))
return true;
return false;
}
extern int vr_nexthop_init(struct vrouter *);
extern void vr_nexthop_exit(struct vrouter *, bool);
extern struct vr_nexthop *__vrouter_get_nexthop(struct vrouter *, unsigned int);
extern struct vr_nexthop *vrouter_get_nexthop(unsigned int, unsigned int);
extern void vrouter_put_nexthop(struct vr_nexthop *);
extern int vr_ip_rcv(struct vrouter *, struct vr_packet *,
struct vr_forwarding_md *);
extern int nh_output(struct vr_packet *,
struct vr_nexthop *, struct vr_forwarding_md *);
extern int vr_nexthop_add(vr_nexthop_req *);
extern int vr_nexthop_get(vr_nexthop_req *);
extern int vr_nexthop_dump(vr_nexthop_req *);
extern bool vr_gateway_nexthop(struct vr_nexthop *);
extern unsigned int vr_nexthop_req_get_size(void *);
extern struct vr_nexthop *vr_discard_nh;
#ifdef __cplusplus
}
#endif
#endif /* __VNSW_NEXTHOP_H__ */