1 /*
2     pmacct (Promiscuous mode IP Accounting package)
3     pmacct is Copyright (C) 2003-2019 by Paolo Lucente
4 */
5 
6 /*
7     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11 
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16 
17     You should have received a copy of the GNU General Public License
18     along with this program; if no, write to the Free Software
19     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21 
22 #ifndef PMACCT_NETWORK_H
23 #define PMACCT_NETWORK_H
24 
25 #include "../include/extract.h"
26 #include "../include/llc.h"
27 #include "../include/sll.h"
28 #include "../include/ieee802_11.h"
29 #include "../include/ip6.h"
30 #include "../include/ah.h"
31 
32 #ifndef IN6_IS_ADDR_V4MAPPED
33 #define IN6_IS_ADDR_V4MAPPED(a) \
34         ((((__const uint32_t *) (a))[0] == 0)                                 \
35          && (((__const uint32_t *) (a))[1] == 0)                              \
36          && (((__const uint32_t *) (a))[2] == htonl (0xffff)))
37 #endif
38 
39 #define ETH_ADDR_LEN    	6               /* Octets in one ethernet addr   */
40 #define ETHER_HDRLEN    	14
41 #define ETHERMTU		1500
42 #define ETHER_JUMBO_MTU		9000
43 #define IEEE8021Q_TAGLEN	4
44 #define CFP_TAGLEN	        16
45 #define CVNT_TAGLEN		6
46 #define IEEE8021AH_LEN		10
47 #define PPP_TAGLEN              2
48 #define MAX_MCAST_GROUPS	20
49 #if defined ENABLE_PLABEL
50 #define PREFIX_LABEL_LEN	16
51 #define AF_PLABEL		255
52 #endif
53 #define PRIMPTRS_FUNCS_N	16
54 
55 /* Ethernet header */
56 struct eth_header
57 {
58   u_int8_t  ether_dhost[ETH_ADDR_LEN];      /* destination eth addr */
59   u_int8_t  ether_shost[ETH_ADDR_LEN];      /* source ether addr    */
60   u_int16_t ether_type;                     /* packet type ID field */
61 };
62 
63 /* 802.1Q header */
64 struct vlan_header
65 {
66   u_int16_t tci;		/* priority and VLAN ID */
67   u_int16_t proto;		/* packet type ID or len */
68 } __attribute__ ((packed));
69 
70 #define CHDLC_MCAST_ADDR	0x8F
71 #define CHDLC_FIXED_CONTROL	0x00
72 /* CHDLC header */
73 struct chdlc_header {
74   u_int8_t address;
75   u_int8_t control;
76   u_int16_t protocol;
77 };
78 
79 /* Ethernet protocol ID's */
80 #define ETHERTYPE_IP		0x0800          /* IP */
81 #define ETHERTYPE_IPV6          0x86dd		/* IPv6 */
82 #define ETHERTYPE_PPPOE         0x8864          /* pppoe (session stage) */
83 #define ETHERTYPE_8021Q		0x8100          /* 802.1Q */
84 #define ETHERTYPE_MPLS          0x8847		/* MPLS */
85 #define ETHERTYPE_MPLS_MULTI    0x8848		/* MPLS */
86 #define ETHERTYPE_ISO		0xFEFE		/* OSI */
87 #define ETHERTYPE_GRE_ISO	0x00FE		/* OSI over GRE */
88 #define ETHERTYPE_CFP		0x8903		/* Cisco FabricPath */
89 #define ETHERTYPE_CVNT		0x8926		/* Cisco Virtual Network TAG */
90 
91 /* PPP protocol definitions */
92 #define PPP_HDRLEN      4       /* octets for standard ppp header */
93 #define PPPOE_HDRLEN	6	/* octets for standard pppoe header  */
94 #define PPP_IP          0x0021  /* Internet Protocol */
95 #define PPP_IPV6	0x0057  /* IPv6 */
96 #define PPP_MPLS_UCAST  0x0281  /* rfc 3032 */
97 #define PPP_MPLS_MCAST  0x0283  /* rfc 3022 */
98 #define PPP_ADDRESS     0xff    /* The address byte value */
99 #define PPP_CONTROL     0x03    /* The control byte value */
100 
101 /* CHDLC protocol definitions */
102 #define CHDLC_HDRLEN    4
103 
104 /* additional protocol definitions */
105 #ifndef IPPROTO_HOPOPTS
106 #define IPPROTO_HOPOPTS         0               /* IPv6 hop-by-hop options */
107 #endif
108 #ifndef IPPROTO_IPV6
109 #define IPPROTO_IPV6            41
110 #endif
111 #ifndef IPPROTO_ROUTING
112 #define IPPROTO_ROUTING         43              /* IPv6 routing header */
113 #endif
114 #ifndef IPPROTO_FRAGMENT
115 #define IPPROTO_FRAGMENT        44              /* IPv6 fragmentation header */
116 #endif
117 #ifndef IPPROTO_ESP
118 #define IPPROTO_ESP             50              /* SIPP Encap Sec. Payload */
119 #endif
120 #ifndef IPPROTO_AH
121 #define IPPROTO_AH              51              /* SIPP Auth Header */
122 #endif
123 #ifndef IPPROTO_NONE
124 #define IPPROTO_NONE            59              /* IPv6 no next header */
125 #endif
126 #ifndef IPPROTO_DSTOPTS
127 #define IPPROTO_DSTOPTS         60              /* IPv6 destination options */
128 #endif
129 #ifndef IPPROTO_IPCOMP
130 #define IPPROTO_IPCOMP          108
131 #endif
132 #ifndef IPPROTO_MOBILITY
133 #define IPPROTO_MOBILITY        135
134 #endif
135 
136 struct pm_iphdr
137 {
138    u_int8_t     ip_vhl;         /* header length, version */
139 #define IP_V(ip)        (((ip)->ip_vhl & 0xf0) >> 4)
140 #define IP_HL(ip)       ((ip)->ip_vhl & 0x0f)
141    u_int8_t     ip_tos;         /* type of service */
142    u_int16_t    ip_len;         /* total length */
143    u_int16_t    ip_id;          /* identification */
144    u_int16_t    ip_off;         /* fragment offset field */
145 #define IP_DF 0x4000                    /* dont fragment flag */
146 #define IP_MF 0x2000                    /* more fragments flag */
147 #define IP_OFFMASK 0x1fff               /* mask for fragmenting bits */
148    u_int8_t     ip_ttl;         /* time to live */
149    u_int8_t     ip_p;           /* protocol */
150    u_int16_t    ip_sum;         /* checksum */
151    struct in_addr ip_src;	/* source and destination addresses */
152    struct in_addr ip_dst;
153 };
154 
155 typedef u_int32_t tcp_seq;
156 struct pm_tcphdr
157 {
158     u_int16_t th_sport;         /* source port */
159     u_int16_t th_dport;         /* destination port */
160     tcp_seq th_seq;             /* sequence number */
161     tcp_seq th_ack;             /* acknowledgement number */
162 #if defined IM_LITTLE_ENDIAN
163     u_int8_t th_x2:4;           /* (unused) */
164     u_int8_t th_off:4;          /* data offset */
165 #endif
166 #if defined IM_BIG_ENDIAN
167     u_int8_t th_off:4;          /* data offset */
168     u_int8_t th_x2:4;           /* (unused) */
169 #endif
170     u_int8_t th_flags;
171 #define TH_FIN        0x01
172 #define TH_SYN        0x02
173 #define TH_RST        0x04
174 #define TH_PUSH       0x08
175 #define TH_ACK        0x10
176 #define TH_URG        0x20
177     u_int16_t th_win;           /* window */
178     u_int16_t th_sum;           /* checksum */
179     u_int16_t th_urp;           /* urgent pointer */
180 };
181 
182 /* For TCP_MD5SIG socket option.  */
183 #ifndef TCP_MD5SIG_MAXKEYLEN
184 #define TCP_MD5SIG_MAXKEYLEN    80
185 #endif
186 
187 #ifndef TCP_MD5SIG
188 #define TCP_MD5SIG       14
189 #endif
190 
191 struct pm_tcp_md5sig
192 {
193   struct sockaddr_storage tcpm_addr;            /* Address associated.  */
194   u_int16_t     __tcpm_pad1;                    /* Zero.  */
195   u_int16_t     tcpm_keylen;                    /* Key length.  */
196   u_int32_t     __tcpm_pad2;                    /* Zero.  */
197   u_int8_t      tcpm_key[TCP_MD5SIG_MAXKEYLEN]; /* Key (binary).  */
198 };
199 
200 #define UDP_PORT_VXLAN	4789
201 
202 struct pm_udphdr
203 {
204   u_int16_t uh_sport;           /* source port */
205   u_int16_t uh_dport;           /* destination port */
206   u_int16_t uh_ulen;            /* udp length */
207   u_int16_t uh_sum;             /* udp checksum */
208 };
209 
210 struct pm_tlhdr {
211    u_int16_t	src_port;	/* source and destination ports */
212    u_int16_t	dst_port;
213 };
214 
215 #define VXLAN_FLAG_I	0x8
216 
217 /* according to rfc7348 */
218 struct vxlan_hdr {
219   u_int8_t flags;
220   u_char reserved1[3];
221   u_char vni[3];
222   u_int8_t reserved2;
223 } __attribute__ ((packed));
224 
225 #define MAX_GTP_TRIALS	8
226 
227 struct pm_gtphdr_v0 {
228     u_int8_t flags;
229     u_int8_t message;
230     u_int16_t length;
231 };
232 
233 struct pm_gtphdr_v1 {
234     u_int8_t flags;
235     u_int8_t message;
236     u_int16_t length;
237     u_int32_t teid;
238 };
239 
240 /* typedefs */
241 typedef u_int32_t as_t;
242 typedef u_int16_t as16_t;
243 typedef u_int16_t afi_t;
244 typedef u_int8_t safi_t;
245 
246 #define RD_LEN		8
247 #define RD_TYPE_AS      0
248 #define RD_TYPE_IP      1
249 #define RD_TYPE_AS4     2
250 #define RD_TYPE_VRFID	65535
251 
252 struct rd_as
253 {
254   u_int16_t type;
255   u_int16_t as;
256   u_int32_t val;
257 } __attribute__ ((packed));
258 
259 struct rd_ip
260 {
261   u_int16_t type;
262   struct in_addr ip;
263   u_int16_t val;
264 } __attribute__ ((packed));
265 
266 struct rd_as4
267 {
268   u_int16_t type;
269   as_t as;
270   u_int16_t val;
271 } __attribute__ ((packed));
272 
273 /* Picking one of the three structures as rd_t for simplicity */
274 typedef struct rd_as rd_t;
275 
276 typedef u_int32_t path_id_t;
277 
278 /* class status */
279 struct class_st {
280    u_int8_t tentatives;
281    struct timeval stamp;	/* accumulator timestamp */
282    u_int32_t ba;		/* bytes accumulator */
283    u_int16_t pa;		/* packet accumulator */
284    u_int8_t fa;			/* flow accumulator */
285 };
286 
287 struct packet_ptrs {
288   struct pcap_pkthdr *pkthdr; /* ptr to header structure passed by libpcap */
289   u_char *f_agent; /* ptr to flow export agent */
290   u_char *f_header; /* ptr to NetFlow packet header */
291   u_char *f_data; /* ptr to NetFlow data */
292   u_char *f_tpl; /* ptr to NetFlow V9 template */
293   u_char *f_status; /* ptr to status table entry */
294   u_char *f_status_g; /* ptr to status table entry. global per f_agent */
295   u_char *bpas_table; /* ptr to bgp_peer_as_src table map */
296   u_char *blp_table; /* ptr to bgp_src_local_pref table map */
297   u_char *bmed_table; /* ptr to bgp_src_med table map */
298   u_char *bta_table; /* ptr to bgp_to_agent table map */
299   u_char *bitr_table; /* ptr to flow_to_rd table map */
300   u_char *sampling_table; /* ptr to sampling_map table map */
301   u_char *packet_ptr; /* ptr to the whole packet */
302   u_char *mac_ptr; /* ptr to mac addresses */
303   u_int16_t l3_proto; /* layer-3 protocol: IPv4, IPv6 */
304   int (*l3_handler)(register struct packet_ptrs *); /* layer-3 protocol handler */
305   u_int16_t l4_proto; /* layer-4 protocol */
306   u_int8_t flow_type; /* Flow, NAT event, etc. */
307   pm_id_t tag; /* pre tag id */
308   u_int8_t have_tag; /* have tag? */
309   pm_id_t tag2; /* pre tag id2 */
310   u_int8_t have_tag2; /* have tag2? */
311   pt_label_t label; /* pre tag label */
312   u_int8_t have_label; /* have label? */
313   pm_id_t bpas; /* bgp_peer_as_src */
314   pm_id_t blp; /* bgp_src_local_pref */
315   pm_id_t bmed; /* bgp_src_med */
316   u_int16_t bta_af; /* bgp_to_agent address family */
317   pm_id_t bta; /* bgp_to_agent */
318   pm_id_t bta2; /* bgp_to_agent (cont.d: 64bits more for IPv6 addresses) */
319   pm_id_t bitr; /* flow_to_rd */
320   pm_id_t st; /* sampling_map */
321   s_uint8_t set_tos; /* pretag map: set_tos feature */
322   s_uint16_t lookup_bgp_port; /* bgp_agent_map: lookup BGP port feature */
323   char *bgp_src; /* pointer to bgp_node structure for source prefix, if any */
324   char *bgp_dst; /* pointer to bgp_node structure for destination prefix, if any */
325   char *bgp_src_info; /* pointer to bgp_info structure for source prefix, if any */
326   char *bgp_dst_info; /* pointer to bgp_info structure for destination prefix, if any */
327   char *bgp_peer; /* record BGP peer's Router-ID */
328   char *bgp_nexthop_info; /* record bgp_info of BGP next-hop in case of follow-up */
329   u_int8_t src_roa; /* record ROA status for source prefix */
330   u_int8_t dst_roa; /* record ROA status for destination prefix */
331   char *igp_src; /* pointer to IGP node structure for source prefix, if any */
332   char *igp_dst; /* pointer to IGP node structure for destination prefix, if any */
333   char *igp_src_info; /* pointer to IGP node info structure for source prefix, if any */
334   char *igp_dst_info; /* pointer to IGP node info structure for destination prefix, if any */
335   u_int8_t lm_mask_src; /* Longest match for source prefix (network mask bits) */
336   u_int8_t lm_mask_dst; /* Longest match for destination prefix (network mask bits) */
337   u_int8_t lm_method_src; /* Longest match for source prefix (method: BGP, IGP, etc.) */
338   u_int8_t lm_method_dst; /* Longest match for destination prefix (method: BGP, IGP, etc.) */
339   u_int16_t pf; /* pending fragments or packets */
340   u_int8_t new_flow; /* pmacctd flows: part of a new flow ? */
341   u_int8_t tcp_flags; /* pmacctd flows: TCP packet flags; URG, PUSH filtered out */
342   u_int8_t frag_first_found; /* entry found in fragments table */
343   u_int16_t frag_sum_bytes; /* accumulated bytes by fragment entry, ie. due to out of order */
344   u_int16_t frag_sum_pkts; /* accumulated packets by fragment entry, ie. due to out of order */
345   u_char *vlan_ptr; /* ptr to vlan id */
346   u_char *mpls_ptr; /* ptr to base MPLS label */
347   u_char *iph_ptr; /* ptr to ip header */
348   u_char *tlh_ptr; /* ptr to transport level protocol header */
349   u_char *vxlan_ptr; /* ptr to VXLAN VNI */
350   u_char *payload_ptr; /* classifiers: ptr to packet payload */
351   pm_class_t class; /* classifiers: class id */
352   struct class_st cst; /* classifiers: class status */
353   u_int8_t shadow; /* 0=the packet is being distributed for the 1st time
354 		      1=the packet is being distributed for the 2nd+ time */
355   u_int32_t ifindex_in;  /* input ifindex; used by pmacctd/uacctd */
356   u_int32_t ifindex_out; /* output ifindex; used by pmacctd/uacctd */
357   u_int8_t direction; /* packet sampling direction; used by pmacctd/uacctd */
358   u_char *tun_pptrs; /* tunnel packet pointers */
359   u_int8_t tun_stack; /* tunnell stack */
360   u_int8_t tun_layer; /* tunnell layer count */
361   u_int32_t sample_type; /* sFlow sample type */
362   u_int32_t seqno; /* sFlow/NetFlow sequence number */
363   u_int16_t f_len; /* sFlow/NetFlow payload length */
364   char *tee_dissect; /* pointer to flow tee dissection structure */
365   int tee_dissect_bcast; /* is the tee dissected element to be broadcasted? */
366   u_int8_t renormalized; /* Is it renormalized yet ? */
367   u_char *pkt_data_ptrs[CUSTOM_PRIMITIVE_MAX_PPTRS_IDX]; /* indexed packet pointers */
368   u_int16_t pkt_proto[CUSTOM_PRIMITIVE_MAX_PPTRS_IDX]; /* indexed packet protocols */
369 #if defined (WITH_GEOIPV2)
370   MMDB_lookup_result_s geoipv2_src;
371   MMDB_lookup_result_s geoipv2_dst;
372 #endif
373 #if defined (WITH_NDPI)
374   pm_class2_t ndpi_class;
375 #endif
376 };
377 
378 struct host_addr {
379   u_int8_t family;
380   union {
381     struct in_addr ipv4;
382     struct in6_addr ipv6;
383 #if defined ENABLE_PLABEL
384     char plabel[PREFIX_LABEL_LEN];
385 #endif
386   } address;
387 };
388 
389 struct host_mask {
390   u_int8_t family;
391   u_int8_t len;
392   union {
393     u_int32_t m4;
394     u_int8_t m6[16];
395   } mask;
396 };
397 
398 struct pkt_primitives {
399 #if defined (HAVE_L2)
400   u_int8_t eth_dhost[ETH_ADDR_LEN];
401   u_int8_t eth_shost[ETH_ADDR_LEN];
402   u_int16_t vlan_id;
403   u_int8_t cos;
404   u_int16_t etype;
405 #endif
406   struct host_addr src_ip;
407   struct host_addr dst_ip;
408   struct host_addr src_net;
409   struct host_addr dst_net;
410   u_int8_t src_nmask;
411   u_int8_t dst_nmask;
412   as_t src_as;
413   as_t dst_as;
414   u_int16_t src_port;
415   u_int16_t dst_port;
416   u_int8_t tos;
417   u_int8_t proto;
418   u_int32_t ifindex_in;
419   u_int32_t ifindex_out;
420 #if defined (WITH_GEOIP) || defined (WITH_GEOIPV2)
421   pm_country_t src_ip_country;
422   pm_country_t dst_ip_country;
423   pm_pocode_t src_ip_pocode;
424   pm_pocode_t dst_ip_pocode;
425   double src_ip_lat;
426   double src_ip_lon;
427   double dst_ip_lat;
428   double dst_ip_lon;
429 #endif
430 #if defined (WITH_NDPI)
431   pm_class2_t ndpi_class;
432 #endif
433   pm_id_t tag;
434   pm_id_t tag2;
435   pm_class_t class;
436   u_int32_t sampling_rate;
437   char sampling_direction[2]; /* 'i' = ingress, 'e' = egress, 'u' = unknown */
438   u_int32_t export_proto_seqno;
439   u_int16_t export_proto_version;
440   u_int32_t export_proto_sysid;
441 };
442 
443 struct pkt_data {
444   struct pkt_primitives primitives;
445   pm_counter_t pkt_len;
446   pm_counter_t pkt_num;
447   pm_counter_t flo_num;
448   u_int8_t flow_type;
449   u_int32_t tcp_flags; /* XXX */
450   struct timeval time_start;
451   struct timeval time_end;
452   struct class_st cst;
453 };
454 
455 struct pkt_payload {
456   u_int16_t cap_len;
457   pm_counter_t sample_pool;
458   pm_counter_t pkt_len;
459   pm_counter_t pkt_num;
460   u_int32_t time_start;
461   pm_class_t class;
462 #if defined (WITH_NDPI)
463   pm_class2_t ndpi_class;
464 #endif
465   pm_id_t tag;
466   pm_id_t tag2;
467   struct host_addr src_ip;
468   struct host_addr dst_ip;
469   as_t src_as;
470   as_t dst_as;
471   u_int32_t ifindex_in;
472   u_int32_t ifindex_out;
473   u_int8_t src_nmask;
474   u_int8_t dst_nmask;
475   u_int16_t vlan;
476   u_int8_t priority;
477   struct host_addr bgp_next_hop;
478 };
479 
480 struct pkt_vlen_hdr_primitives {
481   u_int16_t tot_len;
482   u_int16_t num;
483 } __attribute__ ((packed));
484 
485 // XXX: eventually deprecate pkt_extras
486 struct pkt_extras {
487   u_int8_t tcp_flags;
488 };
489 
490 #define PKT_MSG_SIZE 10000
491 struct pkt_msg {
492   struct sockaddr_storage agent;
493   u_int32_t seqno;
494   u_int16_t len;
495   u_char *payload;
496   pm_id_t tag;
497   pm_id_t tag2;
498   u_int8_t bcast;
499   u_int16_t pad;
500 };
501 
502 struct pkt_stitching {
503   struct timeval timestamp_min;
504   struct timeval timestamp_max;
505 };
506 
507 /* START: BGP section */
508 #define MAX_BGP_STD_COMMS       96
509 #define MAX_BGP_EXT_COMMS       96
510 #define MAX_BGP_LRG_COMMS       96
511 #define MAX_BGP_ASPATH          128
512 
513 struct extra_primitives {
514   u_int16_t off_pkt_bgp_primitives;
515   u_int16_t off_pkt_lbgp_primitives;
516   u_int16_t off_pkt_nat_primitives;
517   u_int16_t off_pkt_mpls_primitives;
518   u_int16_t off_pkt_tun_primitives;
519   u_int16_t off_custom_primitives;
520   u_int16_t off_pkt_extras; /* nfprobe only */
521   u_int16_t off_pkt_vlen_hdr_primitives;
522 };
523 
524 struct primitives_ptrs {
525   struct pkt_data *data;
526   struct pkt_bgp_primitives *pbgp;
527   struct pkt_legacy_bgp_primitives *plbgp;
528   struct pkt_nat_primitives *pnat;
529   struct pkt_mpls_primitives *pmpls;
530   struct pkt_tunnel_primitives *ptun;
531   u_char *pcust;
532   struct pkt_extras *pextras;
533   struct pkt_vlen_hdr_primitives *pvlen;
534 
535   u_int16_t vlen_next_off;
536 };
537 
538 typedef void (*primptrs_func) (u_char *, struct extra_primitives *, struct primitives_ptrs *);
539 
540 struct pkt_bgp_primitives {
541   as_t peer_src_as;
542   as_t peer_dst_as;
543   struct host_addr peer_src_ip;
544   struct host_addr peer_dst_ip;
545   u_int32_t local_pref;
546   u_int32_t med;
547   u_int32_t src_local_pref;
548   u_int32_t src_med;
549   rd_t mpls_vpn_rd;
550   u_int32_t mpls_pw_id;
551   u_int8_t src_roa;
552   u_int8_t dst_roa;
553 };
554 
555 struct pkt_legacy_bgp_primitives {
556   char std_comms[MAX_BGP_STD_COMMS];
557   char ext_comms[MAX_BGP_EXT_COMMS];
558   char lrg_comms[MAX_BGP_LRG_COMMS];
559   char as_path[MAX_BGP_ASPATH];
560   char src_std_comms[MAX_BGP_STD_COMMS];
561   char src_ext_comms[MAX_BGP_EXT_COMMS];
562   char src_lrg_comms[MAX_BGP_LRG_COMMS];
563   char src_as_path[MAX_BGP_ASPATH];
564 };
565 
566 struct pkt_nat_primitives {
567   struct host_addr post_nat_src_ip;
568   struct host_addr post_nat_dst_ip;
569   u_int16_t post_nat_src_port;
570   u_int16_t post_nat_dst_port;
571   u_int8_t nat_event;
572   struct timeval timestamp_start; /* XXX: clean-up: to be moved in a separate structure */
573   struct timeval timestamp_end; /* XXX: clean-up: to be moved in a separate structure */
574   struct timeval timestamp_arrival; /* XXX: clean-up: to be moved in a separate structure */
575 };
576 
577 struct pkt_mpls_primitives {
578   u_int32_t mpls_label_top;
579   u_int32_t mpls_label_bottom;
580   u_int8_t mpls_stack_depth;
581 };
582 
583 struct pkt_tunnel_primitives {
584   u_int8_t tunnel_eth_dhost[ETH_ADDR_LEN];
585   u_int8_t tunnel_eth_shost[ETH_ADDR_LEN];
586   struct host_addr tunnel_src_ip;
587   struct host_addr tunnel_dst_ip;
588   u_int8_t tunnel_tos;
589   u_int8_t tunnel_proto;
590   u_int16_t tunnel_src_port;
591   u_int16_t tunnel_dst_port;
592   u_int32_t tunnel_id; /* ie. VXLAN VNI */
593 };
594 
595 /* same as pkt_legacy_bgp_primitives but pointers in place of strings */
596 struct cache_legacy_bgp_primitives {
597   char *std_comms;
598   char *ext_comms;
599   char *lrg_comms;
600   char *as_path;
601   char *src_std_comms;
602   char *src_ext_comms;
603   char *src_lrg_comms;
604   char *src_as_path;
605 };
606 /* END: BGP section */
607 
608 struct packet_ptrs_vector {
609   struct packet_ptrs v4;
610   struct packet_ptrs vlan4;
611   struct packet_ptrs mpls4;
612   struct packet_ptrs vlanmpls4;
613   struct packet_ptrs v6;
614   struct packet_ptrs vlan6;
615   struct packet_ptrs mpls6;
616   struct packet_ptrs vlanmpls6;
617 };
618 
619 struct hosts_table_entry {
620   struct host_addr addr;
621   struct host_mask mask;
622 };
623 
624 struct hosts_table {
625   int num;
626   time_t timestamp;
627   struct hosts_table_entry table[MAX_MAP_ENTRIES];
628 };
629 
630 struct bgp_md5_table_entry {
631   struct host_addr addr;
632   char key[TCP_MD5SIG_MAXKEYLEN];
633 };
634 
635 struct bgp_md5_table {
636   int num;
637   struct bgp_md5_table_entry table[BGP_MD5_MAP_ENTRIES];
638 };
639 
640 #define TUNNEL_PROTO_STRING	16
641 #define TUNNEL_REGISTRY_STACKS	9 /* MAX + 1 */
642 #define TUNNEL_REGISTRY_ENTRIES 4
643 typedef int (*tunnel_func)(register struct packet_ptrs *);
644 
645 struct tunnel_handler {
646   tunnel_func tf;
647   u_int8_t proto;
648   u_int16_t port;
649 };
650 
651 typedef int (*tunnel_configurator)(struct tunnel_handler *, char *);
652 
653 struct tunnel_entry {
654   char type[TUNNEL_PROTO_STRING];
655   tunnel_func tf;
656   tunnel_configurator tc;
657 };
658 
659 /* global variables */
660 extern struct tunnel_handler tunnel_registry[TUNNEL_REGISTRY_STACKS][TUNNEL_REGISTRY_ENTRIES];
661 #endif //PMACCT_NETWORK_H
662