More janitorial work
[vpp.git] / plugins / vcgn-plugin / vcgn / tcp_header_definitions.h
1 /*
2  *-----------------------------------------------------------------------------
3  *
4  * Filename: tcp_header_definitions.h
5  *
6  * Description: Layer 2, 3, 4 definitions and header types
7  *
8  * Assumptions and Constraints:
9  *
10  * Copyright (c) 2012-2013 Cisco and/or its affiliates.
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at:
14  *
15  *     http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  *-----------------------------------------------------------------------------
23  */
24
25 #ifndef __TCP_HEADER_DEFINITIONS_H__
26 #define __TCP_HEADER_DEFINITIONS_H__
27
28 /*
29  * A general list of Layer 3 protocols, used by many Layer 2 encaps.
30  *
31  *                       formerly:
32  * TYPE_IP               TYPE_IP10MB
33  * TYPE_ARP              TYPE_RFC826_ARP
34  * TYPE_RARP             TYPE_REVERSE_ARP
35  * TYPE_MPLS             TYPE_TAGSWITCH
36  */
37 #define   TYPE_IP                        0x0800
38 #define   TYPE_IP_V6                     0x86DD
39 #define   TYPE_ARP                       0x0806
40 #define   TYPE_RARP                      0x8035
41 #define   TYPE_MPLS                      0x8847
42 #define   TYPE_CDP                       0x2000
43 #define   TYPE_CGMP                      0x2001
44 #define   TYPE_LACP                      0x8808 /* 802.3ad */
45 #define   TYPE_CLNS                      0xFEFE
46
47 #define TYPE_PPPOE_SESSION               0x8864 /* PTA plus */
48 #define TYPE_PPPOE_DISCOVERY             0x8863 /* PTA plus */
49
50 /*
51  * for atm arp handling
52  */
53 #define IN_ATM_ARP_BIT     0x0008
54
55 /*
56  * The Layer 2 header structures.
57  */
58
59
60 /*
61 ** HDLC
62 */
63
64 typedef struct hdlc_hdr_type {
65     u16 addr;
66     u16 type;
67     u8  data[0];
68 } hdlc_hdr_type;
69
70 #define    HDLC_ADDR_CMD                 0x0F00
71 #define    HDLC_HDR_LEN                  4
72 #define    HDLC_BROADCAST_BIT            31
73 #define    TYPE_KEEP                     0x8035
74
75 #define    HDLC_CLNS  (HDLC_ADDR_CMD<<16|TYPE_CLNS)
76 #define    HDLC_CDP   (HDLC_ADDR_CMD<<16|TYPE_CDP)
77 #define    HDLC_MPLS  (HDLC_ADDR_CMD<<16|TYPE_MPLS)
78 #define    HDLC_IP    (HDLC_ADDR_CMD<<16|TYPE_IP)
79 #define    HDLC_IP_V6 (HDLC_ADDR_CMD<<16|TYPE_IP_V6)
80 #define    HDLC_KEEPALIVE_CMD (HDLC_ADDR_CMD<<16|TYPE_KEEP)
81
82 /*
83 ** PPP
84 */
85
86 typedef struct ppp_comp_hdr_type {
87     union {
88         u8  ppp_u8[4];
89         u16 ppp_u16[2];
90         u32 ppp_u32;
91     } ppp_comp_u;
92 } ppp_comp_hdr_type;
93
94 #define   PPP_STATION                    0xFF03
95 #define   PPP_STATION_LEN                0x2
96 #define   PPP_ENDPROTO                   0x01
97 #define   PPP_NOT_ENDPROTO               0xfffffffe
98 #define   PPP_CONTROL_PROTOCOL_MASK      0x8000
99 #define   PPP_CONTROL_PROTOCOL_BIT       15
100 #define   PPP_CSCO_LEN                   4
101 #define   PPP_RFC1661_LEN                2
102 #define   PPP_RFC1661_COMP_LEN           1
103
104 #define   TYPE_PPP_IP                    0x0021
105 #define   TYPE_PPP_IP_V6                 0x0057
106 #define   TYPE_PPP_MPLS_UNICAST          0x0281
107 #define   TYPE_PPP_MPLS_CONTROL          0x8281
108 #define   TYPE_PPP_CLNS                  0x0023
109 #define   TYPE_PPP_CDP                   0x0207
110
111 #define   TYPE_PPP_IPCP                  0x8021
112 #define   TYPE_PPP_LCP                   0xC021
113 #define   TYPE_PPP_PAP                   0xC023
114 #define   TYPE_PPP_LQR                   0xC025
115 #define   TYPE_PPP_CHAP                  0xC223
116
117
118 #define TYPE_PPP_LCP_ECHO_REQUEST               0x09
119 /*
120 ** MultiLink PPP
121 */
122
123 #define   MLPPP_FLAGS_FIELD_LEN          4
124 #define   MLPPP_BEGIN_MASK               0x80000000
125 #define   MLPPP_END_MASK                 0x40000000
126 #define   MLPPP_BEGIN_END_MASK           (MLPPP_BEGIN_MASK|MLPPP_END_MASK)
127 #define   MLPPP_BEGIN_END_SHIFT          30
128 #define   MLPPP_SEQUENCE_NUM_MASK        0x00FFFFFF
129 #define   MLPPP_MC_CLASS_ID_MASK         0x3C000000
130 #define   MLPPP_MC_CLASS_SHIFT           26
131
132 #define   TYPE_PPP_MULTILINK             0x003D
133
134 /* these are needed in the micro-code, for optimizations */
135 #define   TYPE_PPP_FULL_IP_4             0xff030021
136 #define   TYPE_PPP_FULL_IP_3             0xff0321
137 #define   TYPE_PPP_FULL_IP_2             0x0021
138 #define   TYPE_PPP_FULL_IP_1             0x21
139
140 #define   MLPPP_BEGIN_END_MASK_BYTE      0xC0
141 #define   MLPPP_BEGIN_BIT                7
142 #define   MLPPP_END_BIT                  6
143 #define   MLPPP_MC_CLASS_ID_MASK_BYTE    0x3C
144 #define   MLPPP_MC_CLASS_ID_SHIFT_BYTE   2
145
146 #define   MLPOA_BEGIN_END_SHIFT          24
147
148 /*
149 ** Ethernet ARPA
150 */
151
152
153 typedef struct ethernet_arpa_hdr_type {
154     u8  daddr[6];
155     u8  saddr[6];
156     u16 type;
157     u8  data[0];
158 } ethernet_arpa_hdr_type;
159
160 typedef struct extension_802p3_type {
161     u16 type;
162     u8  ctl;
163     u8  data[0];
164 } extension_802p3_type;
165
166 typedef struct ethernet_802p3_hdr_type {
167     u8  daddr[6];
168     u8  saddr[6];
169     u16 length;
170     extension_802p3_type extension;
171 } ethernet_802p3_hdr_type;
172
173
174 typedef struct ethernet_vlan_802p3_hdr_type {
175     u8  daddr[6];
176     u8  saddr[6];
177     u16 type1;
178     u16 vlan_id;
179     u16 length;
180     extension_802p3_type extension;
181 } ethernet_vlan_802p3_hdr_type;
182
183 #define   MIN_ETHERNET_PKT_LEN           60
184 #define   MAX_ETHERNET_PKT_LEN           1500
185 #define   ETHERNET_ARPA_HDR_LEN          14
186 #define   ETHERNET_TYPE_FIELD_SIZE       2
187
188
189 /*
190 ** Ethernet 802.1q (VLAN)
191 */
192
193 typedef struct ethernet_vlan_hdr_type {
194     u8  dest_addr[6];
195     u8  src_addr[6];
196     u16 type1;
197     u16 vlan_hdr;
198     u16 type2;
199     u8  data[0];
200 } ethernet_vlan_hdr_type;
201
202
203 /*
204 ** Ethernet 802.1.q-in-q (QinQ)
205 */
206
207 typedef struct ethernet_qinq_hdr_type {
208     u8  dest_addr[6];
209     u8  src_addr[6];
210     u16 type1;
211     u16 vlan_hdr1;
212     u16 type2;
213     u16 vlan_hdr2;
214     u16 type3;
215     u8  data[0];
216 } ethernet_qinq_hdr_type;
217
218
219 /*
220 ** Ethernet 802.3ad EtherChannel control
221 */
222
223 typedef struct ethernet_lacp_hdr_type {
224     u8  daddr[6];
225     u8  saddr[6];
226     u16 type;
227     u16 LAcmd;
228     u8  data[0];
229 } ethernet_lacp_hdr_type;
230
231
232 /*
233 ** Ethernet 802.1 Bridge (spanning tree) PDU
234 */
235
236 typedef struct ethernet_bpdu_hdr_type {
237     u8  daddr[6];
238     u8  saddr[6];
239     u8  dsap;
240     u8  ssap;
241     u8  control;
242     u8  more[0];
243 } ethernet_bpdu_hdr_type;
244
245 #define ETH_BPDU_DSAP       0x42
246 #define ETH_BPDU_SSAP       0x42
247 #define ETH_BPDU_CONTROL    0x03
248 #define ETH_BPDU_MATCH      0x424203
249
250
251 /************************************************************/
252 /*         PTA PLUS ETHERNET ENCAPSULATIONS                      */
253 /*
254  * PPPoEoARPA 20 bytes
255  */
256 typedef struct ethernet_pppoe_arpa_hdr_type {
257     u8  daddr[6];
258     u8  saddr[6];
259     u16 type;
260     /* pppoe hdr at begining of enet payload */
261     u16 vtc;           /* version(4b), type(4b) and code(8b) fields */
262     u16 sid;
263     u16 len;
264     u8  ppp_header[0]; /* PPP header start, no ff03 field present */
265 } ethernet_pppoe_arpa_hdr_type;
266
267 typedef struct pppoe_hdr_type {
268     /* pppoe hdr at begining of enet payload */
269     u16 vtc;           /* version(4b), type(4b) and code(8b) fields */
270     u16 sid;
271     u16 len;
272     u8  ppp_header[0]; /* PPP header start, no ff03 field present */
273 } pppoe_hdr_type;
274
275 /*
276 ** PPPoEoVLAN (802.1p or 802.1q) 24 bytes
277 */
278 typedef struct ethernet_pppoe_vlan_hdr_type {
279     u8  dest_addr[6];
280     u8  src_addr[6];
281     u16 type1;
282     u16 vlan_hdr;
283     u16 type2;
284     /* pppoe hdr at begining of enet payload */
285     u16 vtc;           /* version(4b), type(4b) and code(8b) fields */
286     u16 sid;
287     u16 len;
288     u8  ppp_header[0]; /* PPP header start, no ff03 field present */
289 } ethernet_pppoe_vlan_hdr_type;
290
291 /*
292 ** PPPoEoQinQ 28 bytes
293 */
294 typedef struct ethernet_pppoe_qinq_hdr_type {
295     u8  dest_addr[6];
296     u8  src_addr[6];
297     u16 type1;
298     u16 vlan_hdr1;
299     u16 type2;
300     u16 vlan_hdr2;
301     u16 type3;
302     /* pppoe hdr at begining of enet payload */
303     u16 vtc;           /* version(4b), type(4b) and code(8b) fields */
304     u16 sid;
305     u16 len;
306     u8  ppp_header[0]; /* PPP header start, no ff03 field present */
307 } ethernet_pppoe_qinq_hdr_type;
308
309 #define  ETH_PPPOE_ARPA_HDR_LEN   sizeof(ethernet_pppoe_arpa_hdr_type)
310 #define  ETH_PPPOE_VLAN_HDR_LEN   sizeof(ethernet_pppoe_vlan_hdr_type)
311 #define  ETH_PPPOE_QINQ_HDR_LEN   sizeof(ethernet_pppoe_qinq_hdr_type)
312 #define  PPPOE_HDR_LEN  6
313 /*    End PTA PLUS ETHERNET ENCAPSULATIONS                           */
314 /****************************************************************/
315
316
317
318 #define   TYPE_DOT1Q                     0x8100
319 #define   DOT1Q_HDR_LEN                  18
320 #define   DOT1Q_VLAN_ID_MASK             0x0FFF
321 #define   DOT1Q_VLAN_ID_RES_0            0x0000
322 #define   DOT1Q_VLAN_ID_RES_4095         0x0FFF
323 #define   DOT1Q_ARPA_INDEX               DOT1Q_VLAN_ID_RES_0
324
325 #define   TYPE_QINQ_91                   0x9100
326 #define   TYPE_QINQ_92                   0x9200
327 #define   TYPE_QINQ_88A8                 0x88A8
328 #define   QINQ_HDR_LEN                   22
329
330 /*
331  * 802.1p support
332  */
333 #define  DOT1P_VLAN_COS_MASK  0xE000
334 #define  DOT1P_VLAN_COS_SHIFT 13
335 #define  DOT1P_MAX_COS_VALUE  7
336
337 /*
338 ** Frame Relay
339 */
340
341 /*
342  *                          formerly:
343  * TYPE_FR_IETF_IPV4        ENCAPS_FR_IETF
344  * TYPE_FR_CISCO_IPV4       ENCAPS_FR_CISCO
345  * TYPE_FR_ISIS             ENCAPS_FR_ISIS
346  *
347  * FR_LMI_DLCI_CISCO        LMI_DLCI_CISCO
348  * FR_LMI_DLCI_IETF         LMI_DLCI_ITUANSI
349  */
350
351 typedef struct frame_relay_hdr_type {
352     u16 address;
353     u16 control_nlpid;
354     u8  data[0];
355 } frame_relay_hdr_type;
356
357 typedef struct fr_snap_hdr_type {
358     u16 address;
359     u8  control;
360     u8  pad;
361     u8  nlpid;
362     u8  oui[3];
363     u16 protocol_id;
364 } fr_snap_hdr_type;
365
366 #define   FR_ADDR_LEN                    2
367 #define   FR_CTL_NLPID_LEN               2
368 #define   FR_HDR_LEN                     (FR_ADDR_LEN+FR_CTL_NLPID_LEN)
369
370 /*
371  * These defines are for the FR-SNAP header.
372  * The SNAP header is set up solely so that we can
373  * identify ARP packets, which look like this:
374  *
375  *   control  pad  nlpid    oui     protocol_id
376  *     03     00    80    00 00 00    0806
377  */
378 #define   FR_ARP_CONTROL                 0x03
379 #define   FR_ARP_PAD                     0x00
380 #define   FR_ARP_NLPID                   0x80
381 #define   FR_ARP_OUI_0                   0x00
382 #define   FR_ARP_OUI_1                   0x00
383 #define   FR_ARP_OUI_2                   0x00
384 /*
385  * these are used only in the tmc code
386  */
387 #define   FR_NLPID_OUI_LEN               4
388 #define   FR_ARP_CONTROL_PAD             0x0300
389 #define   FR_ARP_NLPID_OUI               0x80000000
390
391
392 #define   FR_DLCI_UPPER_MASK             0xFC00
393 #define   FR_DLCI_UPPER_SHIFT            6
394 #define   FR_DLCI_LOWER_MASK             0x00F0
395 #define   FR_DLCI_LOWER_SHIFT            4
396
397 /*
398  * Defines for converting a DLCI for insertion into a synthesized FR address
399  * field for FRoMPLS disposition.
400
401  * bit 8  7   6   5   4   3   2   1
402  * +-------------------------------+
403  * |             Flag              |
404  * | 0  1   1   1    1   1   1   0 |
405  * +-------------------------------+
406  * |   Upper DLCI          |C/R| 0 |
407  * +-------------------------------+
408  * |  Lower DLCI   | F | B | DE| 1 |
409  * +-------------------------------+
410  * |                               |
411  * :Frame relay information field  :
412  * :       (i.e.payload)           :
413  * |                               |
414  * +-------------------------------+
415  * |   FCS (2 or 4 octets)         |
416  * |                               |
417  * +-------------------------------+
418  * |             Flag              |
419  * | 0  1   1   1    1   1   1   0 |
420  * +-------------------------------+
421  *
422  *   a-With 10 bits for the DLCI
423  */
424 #define   FR_DLCI_TO_HDR_UPPER_MASK      0x3f0
425 #define   FR_DLCI_TO_HDR_UPPER_SHIFT     (10-4)
426 #define   FR_DLCI_TO_HDR_LOWER_MASK      0xf
427 #define   FR_DLCI_TO_HDR_LOWER_SHIFT     4
428
429 #define   TYPE_FR_IETF_IP                0x03CC
430 #define   TYPE_FR_IETF_IP_V6             0x038E
431 #define   TYPE_FR_CISCO_IP               0x0800
432 #define   TYPE_FR_CISCO_IP_V6            0x86DD
433 #define   TYPE_FR_ISIS                   0x0383
434 #define   TYPE_FR_SNAP0PAD               0x0380
435 #define   TYPE_FR_SNAP1PAD               0x0300
436 #define   TYPE_FR_FRF12                  0x03B1
437 #define   TYPE_FR_MLP                    0x03CF
438 #define   TYPE_FR_EEK                    0x8037
439
440 #define   FR_LMI_DLCI_CISCO              1023
441 #define   FR_LMI_DLCI_IETF               0
442
443 #define   FR_NOT_NOT_NOT                 0
444 #define   FR_NOT_NOT_DE                  1
445 #define   FR_NOT_BECN_NOT                2
446 #define   FR_NOT_BECN_DE                 3
447 #define   FR_FECN_NOT_NOT                4
448 #define   FR_FECN_NOT_DE                 5
449 #define   FR_FECN_BECN_NOT               6
450 #define   FR_FECN_BECN_DE                7
451
452 #define   FR_FECN_BECN_DE_MASK           0x000E
453 #define   FR_FECN_BECN_DE_SHIFT          1
454
455 /* Address field extension bit for standard 2-byte FR address field */
456 #define   FR_EA1_MASK                    0x0001
457 #define   FR_EA1_MASK_BIT                0
458
459 /*
460  * these are needed in the micro-code, for optimizations
461  */
462
463 /* the bit position (in the address field) of the LSB of the DLCI */
464 #define   FR_DLCI_LS_BIT                 4
465
466
467 /*
468 **
469 ** MultiLink Frame Relay
470 **
471 */
472
473 typedef struct mlfr_hdr_type {
474     u16 frag_hdr;
475     u16 address;
476     u16 control_nlpid;
477     u8  data[0];
478 } mlfr_hdr_type;
479
480 /*
481  * LIP frames have B, E and C set--the other
482  *  bits in the frag_hdr field are irrelevant.
483  *
484  * NOTE: Injected LIP packets have a frag_hdr of 0xE100.
485  *
486  */
487 #define   MLFR_LIP_FRAME                 0xE100
488 #define   MLFR_LIP_MASK                  0xE000
489 #define   MLFR_FRAG_HDR_LEN              2
490
491 #define   MLFR_BEGIN_MASK                0x8000
492 #define   MLFR_END_MASK                  0x4000
493 #define   MLFR_BEGIN_END_MASK            (MLFR_BEGIN_MASK|MLFR_END_MASK)
494 #define   MLFR_BEGIN_END_SHIFT           14
495
496 #define   MLFR_SEQ_NUM_HI_MASK           0x1E00
497 #define   MLFR_SEQ_NUM_HI_SHIFT          1
498 #define   MLFR_SEQ_NUM_LO_MASK           0x00FF
499
500 /*
501  * these are needed in the micro-code, for optimizations
502  */
503 #define   MLFR_BEGIN_END_MASK_BYTE       0xC0
504
505
506 /*
507  * FRF.12 definitions
508  */
509 typedef struct frf12_hdr_type_ {
510     u16 address;
511     u16 control_nlpid;
512     u16 frag_hdr;
513     u8  data[0];
514 } frf12_hdr_type;
515
516 #define   FRF12_FRAG_HDR_LEN             sizeof(frf12_hdr_type)
517
518 #define   FRF12_BEGIN_MASK               0x8000
519 #define   FRF12_END_MASK                 0x4000
520 #define   FRF12_BEGIN_END_MASK           (FRF12_BEGIN_MASK|FRF12_END_MASK)
521 #define   FRF12_BEGIN_END_SHIFT          8
522
523 #define   FRF12_SEQ_NUM_HI_MASK          0x1E00
524 #define   FRF12_SEQ_NUM_HI_SHIFT         1
525 #define   FRF12_SEQ_NUM_LO_MASK          0x00FF
526 #define   FRF12_BEGIN_END_MASK_BYTE      0xC0
527
528
529
530 /*
531 **
532 ** MLP over Frame Relay
533 **  The ppp hdr can be either a
534 **   an MLP hdr or a PPP hdr
535 **
536 **   MLP can be compressed or not:
537 **     a) 0xff03003d
538 **     b) 0x003d
539 **     c) 0x3d
540 **    followed by:
541 **     1 byte with begin/end bits
542 **     3 bytes of a sequence #
543 **
544 **  PPP can be also be compressed or not.
545 **    Only these will be fwded:
546 **     a) 0xff030021
547 **     b) 0xff0321
548 **     c) 0x0021
549 **     d) 0x21
550 **
551 **
552 */
553 typedef struct mlpofr_hdr_type {
554     u16 address;
555     u16 control_nlpid;
556     u8  ppp_header[0];
557 } mlpofr_hdr_type;
558
559 /*
560 ** ATM -
561 */
562
563 /*
564  * channel_handle is defined as follows:
565  *
566  * bits 15      = reserved (must be 0)
567  * bits 14 - 0  = channel handle
568  *
569  *
570  * flags is a bitfield defined as follows:
571  *
572  * bits 15 - 13 = proto (PPPoA RFC1661 = 0,
573  *                       PPPoE = 1,
574  *                       RBE = 2,
575  *                       PPPoA Cisco = 3,
576  *                       MLPoATM RFC1661 = 4,
577  *                       MLPoATM Cisco  = 5,
578  *                       Reserved = 6-7)
579  * bit       12 = encap (MUX=0,
580  *                       SNAP=1)
581  * bits 11 -  6 = reserved (must be 0)
582  * bits  5 -  3 = pkt_type (AAL5 pkt = 0,
583  *                          Raw cell (includes F4 OAM) = 1,
584  *                          F5 segment OAM cell = 2
585  *                          F5 end-to-end OAM cell = 3
586  *                          Reserved = 4-7)
587  * bit        2 = EFCI (congestion indication)
588  * bit        1 = reserved (must be 0)
589  * bit        0 = CLP (cell loss priority)
590  */
591
592 typedef struct apollo_atm_generic_hdr_type {
593     u16 channel_handle;
594     u16 flags;
595 } apollo_atm_generic_hdr_type;
596
597 typedef struct apollo_atm_aal5_snap_hdr_type {
598     u16 channel_handle;
599     u16 flags;
600     u8  dsap;
601     u8  ssap;
602     u8  control;
603     u8  oui[3];
604     u16 type;
605     u8  data[0];
606 } apollo_atm_aal5_snap_hdr_type;
607
608 typedef struct atm_aal5_snap_hdr_type {
609     u8  dsap;
610     u8  ssap;
611     u8  control;
612     u8  oui[3];
613     u16 pid;
614     u16 pad;
615     u8  data[0];
616 } atm_aal5_snap_hdr_type;
617
618
619 typedef struct apollo_atm_aal5_snap_hdr1_type {
620     u16 channel_handle;
621     u16 flags;
622     u8  dsap;
623     u8  ssap;
624     u8  control;
625     u8  oui0;
626     u8  oui1;
627     u8  oui2;
628     u16 type;
629     u8  data[0];
630 } apollo_atm_aal5_snap_hdr1_type;
631
632 typedef struct apollo_atm_aal5_clns_hdr_type {
633     u16 channel_handle;
634     u16 flags;
635     u16 type;
636     u16 data;
637 } apollo_atm_aal5_clns_hdr_type;
638
639 typedef struct apollo_atm_aal5_ilmi_hdr_type {
640     u16 channel_handle;
641     u16 flags;
642     u8  data[0];
643 } apollo_atm_aal5_ilmi_hdr_type;
644
645 typedef struct apollo_atm_aal5_mux_hdr_type {
646     u16 channel_handle;
647     u16 flags;
648     u8  data[0];
649 } apollo_atm_aal5_mux_hdr_type;
650
651 typedef struct apollo_atm_oam_f4_hdr_type {
652     u16 channel_handle;
653     u16 flags;
654     /*
655      * gcf_vpi_vci_pt_clp is a bitfield defined as follows:
656      *
657      * bits 31 - 28 = GCF
658      * bits 27 - 20 = VPI
659      * bits 19 -  4 = VCI
660      * bits  3 -  1 = PT
661      * bit        0 = CLP
662      */
663     u32 gcf_vpi_vci_pt_clp;
664     u8  data[0];
665 } apollo_atm_oam_f4_hdr_type;
666
667 #define APOLLO_ATM_OAM_F4_HDR_PT_MASK     0xE
668 #define APOLLO_ATM_OAM_F4_HDR_PT_SHIFT    1
669
670 typedef struct apollo_atm_oam_f5_hdr_type {
671     u16 channel_handle;
672     u16 flags;
673     u8  data[0];
674 } apollo_atm_oam_f5_hdr_type;
675
676 #define   APOLLO_IRONBUS_EXT_LESS_PROTO    0xFFFF0FFF
677 #define   APOLLO_CHANNEL_HANDLE_MASK       0xFFFF
678 #define   APOLLO_PKT_TYPE_MASK             0x0038
679 #define   APOLLO_PKT_TYPE_SHIFT            3
680 #define   APOLLO_FLAG_CLP_MASK             0x0001
681 #define   APOLLO_FLAG_CLP_BIT              0
682
683 #define   APOLLO_CHANNEL_HANDLE_RES_0      0x0000
684 /*
685  * The 1 byte HEC field is removed by the line card.
686  */
687 #define   APOLLO_F4_RX_CELL_SIZE           52
688 #define   APOLLO_F5_RX_CELL_SIZE           52
689
690 #define   APOLLO_ATM_PACKET_TYPE_AAL5      0
691 #define   APOLLO_ATM_PACKET_TYPE_F4        1
692 #define   APOLLO_ATM_PACKET_TYPE_F5_SEG    2
693 #define   APOLLO_ATM_PACKET_TYPE_F5_E_TO_E 3
694 #define   APOLLO_ATM_PACKET_TYPE_4         4
695 #define   APOLLO_ATM_PACKET_TYPE_5         5
696 #define   APOLLO_ATM_PACKET_TYPE_6         6
697 #define   APOLLO_ATM_PACKET_RESERVED       7 
698
699 #define   APOLLO_AAL5_MUX_IP_HDR_LEN       4
700 #define   APOLLO_AAL5_SNAP_HDR_LEN         12
701
702 #define   APOLLO_RCV_IRON_BUS_EXT_LEN      4
703 #define   APOLLO_TX_IRON_BUS_EXT_LEN       8
704
705 /*
706  * MLPoA type definitions
707  */
708 #define MLPOA_CISCO_HDR                    0xFF03
709 #define MLPOA_SNAP_HDR_LEN                 4
710 #define MLPOA_CISCO_HDR_LEN                2
711
712 /************************************************************/
713 /*         PTA PLUS ATM ENCAPSULATIONS                      */
714
715 /* RBE header 28 bytes*/
716 typedef struct apollo_atm_aal5_llcsnap_rbe_hdr_type {
717     u16 channel_handle;
718     u16 flags;
719     u8  dsap;
720     u8  ssap;
721     u8  control;
722     u8  oui[3];
723     u16 pid;
724     u16 pad;
725     /* enet header within */
726     u8  daddr[6];
727     u8  saddr[6];
728     u16 type;
729     u8  data[0]; /* start of IP */
730 } apollo_atm_aal5_llcsnap_rbe_hdr_type;
731
732 /* PPPoEoA header 34 bytes*/
733 typedef struct apollo_atm_aal5_llcsnap_pppoe_hdr_type {
734     u16 channel_handle;
735     u16 flags;
736     u8  dsap;
737     u8  ssap;
738     u8  control;
739     u8  oui[3];
740     u16 pid;
741     u16 pad;
742     /* enet header within */
743     u8  daddr[6];
744     u8  saddr[6];
745     u16 type;
746     /* pppoe hdr at begining of enet payload */
747     u16 vtc;           /* version(4b), type(4b) and code(8b) fields */
748     u16 sid;
749     u16 len;
750     u8  ppp_header[0]; /* PPP header start, no ff03 field present */
751 } apollo_atm_aal5_llcsnap_pppoe_hdr_type;
752
753
754 /* PPPoA MUX 4 bytes*/
755 typedef struct apollo_atm_aal5_mux_pppoa_hdr_type {
756     u16 channel_handle;
757     u16 flags;
758     u8  ppp_header[0];
759 } apollo_atm_aal5_mux_pppoa_hdr_type;
760
761
762 /* PPPoA SNAP LLC 8 bytes */
763 typedef struct apollo_atm_aal5_llcsnap_pppoa_hdr_type {
764     u16 channel_handle;
765     u16 flags;
766     u8  dsap;
767     u8  ssap;
768     u8  control;
769     u8  nlpid;
770     u8  ppp_header[0];
771 } apollo_atm_aal5_llcsnap_pppoa_hdr_type;
772
773 /* MLPoA MUX (generic) */
774 typedef struct apollo_atm_aal5_mux_mlpoa_hdr_type {
775     u16 channel_handle;
776     u16 flags;
777     u8  ppp_header[0];
778 } apollo_atm_aal5_mux_mlpoa_hdr_type;
779
780 /* MLPoA SNAP LLC */
781 typedef struct apollo_atm_aal5_llcsnap_mlpoa_hdr_type {
782     u16 channel_handle;
783     u16 flags;
784     u8  dsap;
785     u8  ssap;
786     u8  control;
787     u8  nlpid;
788     u8  ppp_header[0];
789 } apollo_atm_aal5_llcsnap_mlpoa_hdr_type;
790
791
792 #define PPPOA_SNAPLLC_HDR_LEN   sizeof(apollo_atm_aal5_llcsnap_pppoa_hdr_type)
793 #define PPPOA_MUX_HDR_LEN       sizeof(apollo_atm_aal5_mux_pppoa_hdr_type)
794 #define PPPOE_SNAPLLC_HDR_LEN   sizeof(apollo_atm_aal5_llcsnap_pppoe_hdr_type)
795 #define RBE_SNAPLLC_HDR_LEN     sizeof(apollo_atm_aal5_llcsnap_rbe_hdr_type)
796
797 /*    End PTA PLUS ATM ENCAPSULATIONS                           */
798 /****************************************************************/
799
800 #define   LLCSNAP_PID_DOT3_NOFCS           0x0007
801
802 /*
803 ** the SNAP header
804 */
805
806 /*
807  * Note that some of these definitions are split
808  * up along certain word or half word boundaries
809  * to help expediate the TMC code.
810  */
811 #define   LLC_SNAP_HDR_DSAP                0xAA
812 #define   LLC_SNAP_HDR_SSAP                0xAA
813 #define   LLC_SNAP_HDR_CONTROL             0x03
814 #define   LLC_SNAP_HDR_OUI_0               0x00
815 #define   LLC_SNAP_HDR_OUI_1               0x00
816 #define   LLC_SNAP_HDR_OUI_2               0x00
817 #define   LLC_SNAP_HDR_OUI_2_CDP           0x0C
818
819 #define   LLC_SNAP_HDR_DSAP_SSAP           0xAAAA
820 #define   LLC_SNAP_HDR_DSAP_SSAP_CTRL_OUI0 0xAAAA0300
821 #define   LLC_SNAP_HDR_CONTROL_OUI         0x03000000
822 #define   LLC_SNAP_HDR_OUI1_OUI2_CDP       0x000C2000
823
824
825
826 /*
827 ** SRP
828 */
829
830 /*
831  * The v2_gen_hdr is a 2-byte field that contains the following:
832  *
833  *      [ ttl | ring_id | mode | priority | parity ]
834  * bits    8       1        3        3         1
835  */
836 typedef struct srp_hdr_type {
837     u16 v2_gen_hdr;
838     u8  dest_addr[6];
839     u8  src_addr[6];
840     u16 protocol;
841     u8  data[0];
842 } srp_hdr_type;
843
844 #define   SRP_HDR_LEN                      16
845
846 #define   SRP_IB_CHANNEL_CONTROL           0x0000
847 #define   SRP_IB_CHANNEL_DATA_HI           0x0001
848 #define   SRP_IB_CHANNEL_DATA_LO           0x0002
849
850 #define   SRP_RING_ID_MASK                 0x0080
851 #define   SRP_RING_ID_BIT                  7
852
853 #define   SRP_MODE_BITS_MASK               0x0070
854 #define   SRP_MODE_BITS_SHIFT              4
855 #define   SRP_MODE_CONTROL_TOPOLOGY        4
856 #define   SRP_MODE_CONTROL_IPS             5
857 #define   SRP_MODE_DATA                    7
858
859 #define   SRP_PRIORITY_BITS_MASK           0x000E 
860 #define   SRP_PRIORITY_BITS_SHIFT          1
861 #define   SRP_PRIORITY_HIGH                7
862 #define   SRP_PRIORITY_PAK_PRIORITY        6
863
864 /* this is for the tmc code */
865 #define   SRP_INV_PRIORITY_BITS_MASK       0xFFF1
866
867 #define   SRP_PROT_CONTROL_TOPOLOGY        0x2007
868 #define   SRP_PROT_CONTROL_IPS             0x2007
869
870 /* this is for the tmc code */
871 #define   SRP_TRUE                         1
872 #define   SRP_FALSE                        0
873
874 /*
875 ** MPLS
876 */
877 #define   MPLS_EOS_BIT                     0x00000100
878 #define   MPLS_EOS_SHIFT                   8
879 #define   MPLS_LABEL_SIZE                  4
880 #define   MAX_MPLS_LABEL_STACK             6
881 #define   MPLS_LABEL_MASK                  0xfffff000
882 #define   MPLS_LABEL_SHIFT                 12
883 #define   MPLS_TTL_MASK                    0x000000ff
884 #define   MPLS_EXP_MASK                    0x00000e00
885 #define   MPLS_EXP_SHIFT                   9
886 #define   MPLS_EXP_TTL_MASK                0x00000eff
887
888
889
890 typedef union _layer2 {
891     hdlc_hdr_type                           hdlc;
892     ppp_comp_hdr_type                       ppp;
893     ethernet_arpa_hdr_type                  eth_arpa;
894     ethernet_vlan_hdr_type                  eth_vlan;
895     ethernet_qinq_hdr_type                  eth_qinq;
896     ethernet_lacp_hdr_type                  eth_lacp;
897     ethernet_bpdu_hdr_type                  eth_bpdu;
898     ethernet_802p3_hdr_type                 eth_802p3;
899     ethernet_vlan_802p3_hdr_type            eth_vlan_802p3;
900     ethernet_pppoe_arpa_hdr_type            eth_pppoe_arpa; /* PTA plus */
901     ethernet_pppoe_vlan_hdr_type            eth_pppoe_vlan; /* PTA plus */
902     ethernet_pppoe_qinq_hdr_type            eth_pppoe_qinq; /* PTA plus */
903     frame_relay_hdr_type                    frame_relay;
904     fr_snap_hdr_type                        fr_snap;
905     mlfr_hdr_type                           mlfr;
906     mlpofr_hdr_type                         mlpofr;
907     frf12_hdr_type                          frf12;
908     apollo_atm_generic_hdr_type             atm_generic;
909     apollo_atm_aal5_snap_hdr_type           atm_aal5_snap;
910     apollo_atm_aal5_snap_hdr1_type          atm_aal5_snap1;
911     apollo_atm_aal5_clns_hdr_type           atm_aal5_clns;
912     apollo_atm_aal5_ilmi_hdr_type           atm_aal5_ilmi;
913     apollo_atm_aal5_mux_hdr_type            atm_aal5_mux;
914     apollo_atm_oam_f4_hdr_type              atm_oam_f4;
915     apollo_atm_oam_f5_hdr_type              atm_oam_f5;
916     apollo_atm_aal5_llcsnap_rbe_hdr_type    atm_aal5_rbe_snapllc;   /* PTA plus */
917     apollo_atm_aal5_llcsnap_pppoe_hdr_type  atm_aal5_pppoe_snapllc; /* PTA plus */
918     apollo_atm_aal5_mux_pppoa_hdr_type      atm_aal5_pppoa_mux;     /* PTA plus */
919     apollo_atm_aal5_llcsnap_pppoa_hdr_type  atm_aal5_pppoa_snapllc; /* PTA plus */
920     apollo_atm_aal5_mux_mlpoa_hdr_type      mlpoa_generic;
921     apollo_atm_aal5_llcsnap_mlpoa_hdr_type  mlpoa_snapllc;
922     srp_hdr_type                            srp;
923 } layer2_t;
924
925 /*
926  * Define the Common OAM cell format - F4 & F5 cells
927  *  For F4 cells:
928  *      VPI == User VPI
929  *      VCI == (3 == Segment), (4 == End-to-End)
930  *
931  *  For F5 cells:
932  *      VPI == User VPI
933  *      VCI == User VCI
934  *      PT == (100 == Segment, 101 == End-to-End)
935  * 
936  *      OAM Cell Type & Function Type:
937  *
938  *      OAM_TYPE = (0001 == Fault management)
939  *      OAM_FUNC == (0000 == AIS, 0001 == RDI, 0100 == CC,
940  *                           1000 == loopback)
941  *
942  *      OAM_TYPE = (0010 == Performance management)
943  *      OAM_FUNC == (0000 == Forward Monitoring(FM), 
944  *                           0001 == Backward monitoring(BR), 
945  *                           0010 == Monitoring & reporting (FM+BR))
946  *
947  *              OAM_TYPE = (1000 == Activation/Deactivation)
948  *      OAM_FUNC == (0000 == Performance Monitoring, 
949  *                           0001 == Continuity Check)
950  *            
951  *              OAM_TYPE = (1111 == Sytem Management)
952  *      OAM_FUNC == (0001 == Security - non-real-time, 
953  *                           0010 == Security - real-time)
954  *
955  */
956 #define ATM_OAM_FAULT_MGMT  0x1 /* OAM Fault mgmt. code */
957 #define ATM_OAM_PRFRM_MGMT      0x2     /* performance mgmt code */
958 #define ATM_OAM_ACT_DEACT       0x8     /* OAM Activation/Deactivation
959                                            code */
960 #define ATM_OAM_SYSTEM_MGMT     0xF     /* System Management code */
961
962 #define ATM_OAM_AIS_FUNC    0x0 /* AIS function type */
963 #define ATM_OAM_RDI_FUNC    0x1 /* RDI function type */
964 #define ATM_OAM_CC_FUNC     0x4 /* OAM CC FM function code */
965 #define ATM_OAM_LOOP_FUNC   0x8 /* Loopback function type */
966
967 #define ATM_OAM_F5_SEGMENT  0x4     /* Segment function */
968 #define ATM_OAM_F5_ENDTOEND 0x5     /* End-to-End function */
969 #define ATM_OAM_F4_SEGMENT  0x3     /* Segment function */
970 #define ATM_OAM_F4_ENDTOEND 0x4     /* End-to-End function */
971 #define ATM_OAM_F4_PTI_ZERO     0x0             /* PTI=0 for F4 OAM */
972
973 typedef struct  atm_oam_hdr_t_ {
974     unsigned    oam_gfc:4;          /* GFC */
975     unsigned    oam_vpi:8;          /* VPI */
976     unsigned    oam_vci_ms:4;         /* VCI (Most Significant Bits) */
977
978     unsigned    oam_vci_ls:12;        /* VCI (Least Significant Bits) */
979     unsigned    oam_pt:3;           /* Payload Type */
980     unsigned    oam_clp:1;          /* Cell Loss Priority */
981     u8  data[0];
982 } atm_oam_hdr_t;
983
984 typedef struct  atm_oam_type_func_t_ {
985     u8  oam_type:4;
986     u8  oam_func:4;
987     u8  data[0];
988 } atm_oam_type_func_t;
989
990 /*
991 ** IP Version 4 header
992 */
993
994 /*
995  * version_hdr_len_words [7-4]   IP Header Version
996  *                       [3-0]   IP Header Length in 32-bit words
997  * tos                   Type of Service
998  * total_len_bytes       Total IP datagram length in bytes
999  *                       (including IP header)
1000  * identification        Unique fragmentation identifier
1001  * frag_flags_offset     [15-13] Fragmentation flags
1002  *                       [12-0]  Fragmentation Offset
1003  * ttl                   Time To Live
1004  * protocol_id           Protocol Identifier
1005  * checksum              16-bit 1's complement IP Header checksum
1006  * src_addr              IP Source Address
1007  * dest_addr             IP Destination Address
1008  */
1009 typedef struct ipv4_header {
1010     u8  version_hdr_len_words;
1011     u8  tos;
1012     u16 total_len_bytes;
1013     u16 identification;
1014     u16 frag_flags_offset;
1015     u8  ttl;
1016     u8  protocol;
1017     u16 checksum;
1018     u32 src_addr;
1019     u32 dest_addr;
1020     u8  data[0];
1021 } ipv4_header;
1022
1023 /*OPTIONS PACKET TYPE 
1024  * +-+-+-+-+-+-+-+-+
1025  * |C| CL|    OP   |
1026  * +-+-+-+-+-+-+-+-+
1027  */
1028 typedef struct ipv4_options {
1029     u8 copy     :1 ;
1030     u8 op_class :2 ;
1031     u8 option   :5 ;
1032     u8 pad ;
1033 }ipv4_options;
1034
1035 #define LOOSE_SOURCE_ROUTE  131
1036 #define STRICT_SOURCE_ROUTE 137
1037 #define IPV4_NO_OPTIONS_HDR_LEN (sizeof(ipv4_header))
1038 #define IPV4_VERSION 4
1039 #define IPV4_HEADER_LENGTH_WORDS 5
1040 #define IPV4_VERSION_HDR_LEN_FIELD  ((u8) 0x45)
1041 #define IPV4_HEADER_LENGTH_WORDS 5
1042 #define IPV4_MIN_HEADER_LENGTH_BYTES 20
1043 #define IP_HDR_LEN sizeof(ipv4_header)
1044 #define IPV4_VERSION_VALUE_SHIFT 4
1045
1046 #define IPV4_FRAG_OFFSET_MASK (0x1fff)
1047 #define IPV4_FRAG_MF_MASK     (0x2000)
1048 #define IPV4_FRAG_MF_SHIFT    (13)
1049
1050 /* 0.0.0.0 */
1051 #define IP_BOOTP_SOURCE_ADDRESS 0
1052 /* 255.255.255.255 */
1053 #define IP_LIMITED_BROADCAST_ADDRESS 0xFFFFFFFF
1054
1055 /*
1056  * IPv4 header - version & length fields
1057  */
1058 #define IP_VER_LEN          0x45
1059 #define IP_VER              0x4
1060 #define IP_MIN_LEN          0x5
1061 #define IP_VER_MASK         0xf0
1062 #define IP_LEN_MASK         0x0f
1063
1064 /*
1065  * IPv4 header - TOS field
1066  */
1067 #define PS_IP_TOS_MASK      0xff
1068 #define IP_PRECEDENCE_SHIFT 5     /* shift value up to precedence bits */
1069 #define IP_DSCP_SHIFT       2     /* shift value up to dscp bits */
1070
1071 #define IP_TOS_PRECEDENCE       0xe0    /* mask of precedence in tos byte */
1072 #define IP_TOS_NO_PRECEDENCE    0x1f
1073 #define IP_TOS_LOW_DELAY        8       /* values must be shifted 1 bit */
1074 #define IP_TOS_HIGH_TPUT        4       /* before using */
1075 #define IP_TOS_HIGH_RELY        2
1076 #define IP_TOS_LOW_COST         1
1077 #define IP_TOS_NORMAL           0
1078 #define IP_TOS_MASK             0x1e    /* mask of tos in tos byte */
1079 #define IP_TOS_MBZ_MASK         0x01    /* mask for MZB bit in tos byte */
1080 #define IP_TOS_DSCP             0xfc    /* mask for dscp in tos byte */
1081 #define IP_TOS_NO_DSCP          0x03
1082
1083 #define IP_TOS_METRIC_TYPES     8
1084 #define IP_TOS_SHIFT            1
1085
1086 #define IP_TOS_PRECEDENCE_MASK  (IP_TOS_PRECEDENCE | IP_TOS_MASK)
1087
1088 /*
1089  * IP TOS Precedence values (High order 3 bits)
1090  */
1091 #define TOS_PREC_NET_CONTROL    0xe0
1092 #define TOS_PREC_INET_CONTROL   0xc0
1093 #define TOS_PREC_CRIT_ECP       0xa0
1094 #define TOS_PREC_FLASH_OVER     0x80
1095 #define TOS_PREC_FLASH          0x60
1096 #define TOS_PREC_IMMEDIATE      0x40
1097 #define TOS_PREC_PRIORITY       0x20
1098 #define TOS_PREC_ROUTINE        0x00
1099 #define TOS_PREC_ILLEGAL        0xff    /* invalid precedence value */
1100
1101 #define TOS_PREC_NET_CONTROL_NUM   7
1102 #define TOS_PREC_INET_CONTROL_NUM  6
1103 #define TOS_PREC_CRIT_ECP_NUM      5
1104 #define TOS_PREC_FLASH_OVER_NUM    4
1105 #define TOS_PREC_FLASH_NUM         3
1106 #define TOS_PREC_IMMEDIATE_NUM     2
1107 #define TOS_PREC_PRIORITY_NUM      1
1108 #define TOS_PREC_ROUTINE_NUM       0
1109
1110
1111
1112 /*
1113  * IPv4 header - flags and fragment offset fields
1114  */
1115 #define IP_FRAG_OFFSET_MASK 0x1fff
1116
1117
1118 #define IP_FRAG_MORE_MASK   0x2000
1119 #define IP_FRAG_DF_MASK     0x4000
1120 #define IP_FRAG_UNDEF_MASK  0x8000
1121 #define IP_FRAG_NO_DF_SET   0x0000
1122
1123 /* bit definitions for fragment flags */
1124 #define IP_FRAG_MORE_BIT       13
1125 #define IP_FRAG_DF_BIT         14
1126 #define IP_FRAG_UNDEF_BIT      15
1127
1128 /*
1129  * IPv4 header - TTL field
1130  */
1131 #define TTL_DEFAULT     255
1132 #define TTL_1           1
1133 #define TTL_2           2
1134 #define TTL_255         255
1135
1136
1137 /*
1138  * IPv4 header - protocol field
1139  *
1140  * ICMP_PROT      1    ICMP
1141  * IGMP_PROT      2    group management
1142  * GGP_PROT       3    GGP
1143  * IPINIP_PROT    4    IPv4 in IPv4 encapsulation
1144  * TCP_PROT       6    TCP
1145  * EGP_PROT       8    EGP
1146  * IGRP_PROT      9    IGRP
1147  * UDP_PROT       17   UDP
1148  * HMP_PROT       20   HMP
1149  * RDP_PROT       27   RDP
1150  * IPV6_INIP_PROT 41   IPV6 in IPv4 encapsulation
1151  * RSVP_PROT      46   RSVP
1152  * GRE_PROT       47   GRE
1153  * ESP_PROT       50   ESP
1154  * AHP_PROT       51   AHP
1155  * SDNS0_PROT     53   SNDS
1156  * NHRP_PROT      54   NHRP
1157  * SDNS1_PROT     55   SDNS1
1158  * HELLO_PROT     63   HELLO
1159  * ND_PROT        77   ND
1160  * EONIP_PROT     80   CLNS over IP
1161  * VINES_PROT     83   Banyan Vines
1162  * NEWIGRP_PROT   88   IGRP
1163  * OSPF_PROT      89   OSPF
1164  * FST_RSRB_PROT  90   RSRB
1165  * FST_DLSW_PROT  91   DLSW
1166  * NOSIP_PROT     94   KA9Q/NOS compatible IP over IP
1167  * PIM_PROT       103  PIMv2
1168  * PCP_PROT       108  PCP
1169  * PGM_PROT       113  PGM
1170  * MAX_PROT       113  maximum protocol number in the above list,
1171  *                      used in creating case registry
1172  */
1173 #define ICMP_PROT       1
1174 #define IGMP_PROT       2
1175 #define GGP_PROT        3
1176 #define IPINIP_PROT     4
1177 #define TCP_PROT        6
1178 #define EGP_PROT        8
1179 #define IGRP_PROT       9
1180 #define UDP_PROT        17
1181 #define HMP_PROT        20
1182 #define RDP_PROT        27
1183 #define IPV6_INIP_PROT  41
1184 #define RSVP_PROT       46
1185 #define GRE_PROT        47
1186 #define ESP_PROT        50
1187 #define AHP_PROT        51
1188 #define SDNS0_PROT      53
1189 #define NHRP_PROT       54
1190 #define SDNS1_PROT      55
1191 #define HELLO_PROT      63
1192 #define ND_PROT         77
1193 #define EONIP_PROT      80
1194 #define VINES_PROT      83
1195 #define NEWIGRP_PROT    88
1196 #define OSPF_PROT       89
1197 #define FST_RSRB_PROT   90
1198 #define FST_DLSW_PROT   91
1199 #define NOSIP_PROT      94
1200 #define PIM_PROT        103
1201 #define PCP_PROT        108
1202 #define PGM_PROT        113
1203 #define MAX_PROT        113
1204
1205 /*Well Known Application ports */
1206 #define FTP_PORT        21  /* For control connection */
1207 /*
1208  * TCP header
1209  */
1210 typedef struct tcp_hdr_type {
1211     u16 src_port;
1212     u16 dest_port;
1213     u32 seq_num;
1214     u32 ack_num;
1215     u8  hdr_len;
1216     u8  flags;
1217     u16 window_size;
1218     u16 tcp_checksum;
1219     u16 urgent_pointer;
1220     u8  option_data[0];
1221 } tcp_hdr_type;
1222
1223 #define TCP_FLAG_FIN    0x01
1224 #define TCP_FLAG_SYN    0x02
1225 #define TCP_FLAG_RST    0x04
1226 #define TCP_FLAG_PUSH   0x08
1227 #define TCP_FLAG_ACK    0x10
1228 #define TCP_FLAG_URG    0x20
1229 #define TCP_FLAG_ECE    0x40
1230 #define TCP_FLAG_CWR    0x80
1231
1232 /*
1233  * TCP Option
1234  */
1235 typedef struct tcp_option_s {
1236     u8  kind;
1237     u8  length;
1238     u8  data[0];
1239 } tcp_option_t;
1240
1241 #define TCP_END_OPTIONS_LIST       0
1242 #define TCP_OPTION_NOP             1
1243 #define TCP_OPTION_MSS             2
1244 #define TCP_OPTION_WINDOW_SCALE    3
1245 #define TCP_OPTION_SACK_PERMITTED  4
1246 #define TCP_OPTION_SACK_DATA       5
1247 #define TCP_OPTION_ECHO            6
1248 #define TCP_OPTION_ECHO_REPLY      7
1249 #define TCP_OPTION_TSOPT           8
1250 /*
1251   9   2   Partial Order Connection Permitted. RFC 1693
1252   10  3   Partial Order Service Profile.  RFC 1693
1253   11  6   CC, Connection Count.   RFC 1644
1254   12  6   CC.NEW  RFC 1644
1255   13  6   CC.ECHO RFC 1644
1256   14  3   TCP Alternate Checksum Request. RFC 1146
1257   15  Variable.   TCP Alternate Checksum Data.    RFC 1146
1258   16      Skeeter.     
1259   17      Bubba.   
1260   18  3   Trailer Checksum Option.     
1261 */
1262 #define TCP_OPTION_MD5_SIGNATURE   19
1263 /*
1264   20      SCPS Capabilities.   
1265   21      Selective Negative Acknowledgements.     
1266   22      Record Boundaries.   
1267   23      Corruption experienced.  
1268   24      SNAP.    
1269   25           
1270   26      TCP Compression Filter.  
1271 */
1272 #define TCP_OPTION_QUICK_START     27
1273
1274 #define TCP_OPTION_NUM_MAX         27
1275
1276 #ifdef TARGET_CISCO
1277 #define tcp_printf(format_str, params...) //printf(format_str, ## params)
1278 #else
1279 #define tcp_printf(format_str, params...) printf(format_str, ## params)
1280 #endif
1281
1282 typedef struct udp_hdr_type {
1283   u16 src_port;
1284   u16 dest_port;
1285   u16 udp_length;
1286   u16 udp_checksum;
1287 } udp_hdr_type_t;
1288
1289 #define TYPE_IPV6 0x86dd
1290 #define TYPE_IPV4 0x0800
1291
1292 /*
1293  * version_trafficclass_flowlabel [31:28] IP Header Version, 
1294                                   [27:20] traffic_class, 
1295                                   [19:0]  flow_label[20]
1296  * payload_length                 Length of packet in bytes excluding header size(s) 
1297  * next_header                    Identifies the type of header following the IPv6 header  
1298  * hop_limit                      Decremented by 1 by each forwarding node, packet discarded when zero
1299  * src_addr                       IPv6 Source Address
1300  * dst_addr                       IPv6 Destination Address
1301  */
1302 typedef struct ipv6_header {
1303   u32 version_trafficclass_flowlabel;
1304   u16 payload_length;
1305   u8  next_header;
1306   u8  hop_limit;
1307   u32 src_addr[4];
1308   u32 dst_addr[4];
1309   u8  data[0];  
1310 } ipv6_header_t;
1311
1312 #define IPV6_HDR_LEN 40 
1313 #define IPV6_HDR_LEN_WORDS 10
1314 #define IPV6_FLABLE_MASK 0x000FFFFF
1315 #define IPV6_MIN_PATH_MTU (1280)
1316
1317 #define IPV6_GET_IP_VER(ih) ((clib_net_to_host_u32((ih) \
1318                       ->version_trafficclass_flowlabel) >> 28) & 0xf)
1319 #define IPV6_GET_TOS(ih) ((clib_net_to_host_u32((ih) \
1320                       ->version_trafficclass_flowlabel) >> 20) & 0xff)
1321 #define IPV6_GET_FLOW_LABEL(ih) ((clib_net_to_host_u32((ih) \
1322                       ->version_trafficclass_flowlabel)) & 0xfffff)
1323
1324 #define IPV6_VERSION_VALUE                    (6)
1325 #define IPV6_VERSION_VALUE_SHIFT              (28)
1326 #define IPV6_TRAFFIC_CLASS_VALUE_SHIFT        (20)
1327 #define IPV6_TRAFFIC_CLASS_VALUE_MASK         (0xff)
1328
1329 #define IPV6_PROTO_HOPOPTS      0
1330 #define IPV6_PROTO_TCP          6       
1331 #define IPV6_PROTO_UDP          17
1332 #define IPV6_PROTO_IPV6         41       
1333 #define IPV6_PROTO_ROUTING      43  
1334 #define IPV6_PROTO_FRAGMENT     44 
1335 #define IPV6_PROTO_DESTOPTS     60 
1336 #define IPV6_PROTO_ESP          50   
1337 #define IPV6_PROTO_AH           51
1338 #define IPV6_PROTO_ICMPV6       58
1339 #define IPV6_PROTO_NONE         59 
1340
1341 /* standard v6 extension header are 2 tytes
1342  * one byte next header
1343  * one byte header length
1344  */
1345
1346 typedef struct ipv6_frag_header {
1347     u8 next_header;
1348     u8 reserved;
1349     u16 frag_offset_res_m;
1350     u32 identification;
1351 } ipv6_frag_header_t;
1352
1353 #define IPV6_FRAG_HDR_LEN (sizeof(ipv6_frag_header_t))
1354
1355 #define IPV6_FRAG_OFFSET_MASK     (0xFFF8)
1356 #define IPV6_FRAG_OFFSET_SHIFT    (3)
1357 #define IPV6_FRAG_MORE_FRAG_MASK  (0x0001)
1358
1359 #define IPV6_TOS_SHIFT       20
1360 #define IPV6_TOS_SHIFT_HLF_WD 4
1361 #define IPV6_NEXT_HDR_SHIFT  8
1362
1363 typedef struct ipv6_routing_header {
1364     u8 next_header;
1365     u8 hdr_ext_len;
1366     u8 routing_type;
1367     u8 segments_left;
1368     u8 data[0];
1369 } ipv6_routing_header_t;
1370 #define IPV6_ROUTING_HDR_LEN (sizeof(ipv6_routing_header_t))
1371
1372 typedef struct ipv6_hop_header {
1373     u8 next_header;
1374     u8 hdr_ext_len;
1375     u8 options[0];
1376 } ipv6_hop_header_t;
1377 #define IPV6_HOP_LEN (sizeof(ipv6_hop_header_t))
1378
1379 typedef struct ipv6_dest_opt_header {
1380     u8 next_header;
1381     u8 hdr_ext_len;
1382     u8 options[0];
1383 } ipv6_dest_opt_header_t;
1384 #define IPV6_DESTOPT_LEN (sizeof(ipv6_dest_opt_header_t))
1385
1386
1387 /* Definition of ICMP header */
1388 typedef struct icmp_v4_s {
1389     u8 type;
1390     u8 code;
1391     u16 checksum;
1392     u16 identifier;
1393     u16 sequence;
1394 } icmp_v4_t;
1395
1396 #define ICMPV4_HDR_SIZE  (sizeof(icmp_v4_t))
1397 #define ICMPV4_ECHOREPLY 0                /* Type: echo reply */
1398 #define ICMPV4_ECHO      8                /* Type: echo request */
1399
1400 #define ICMPV4_UNREACHABLE 3              /* Type: destination unreachable */
1401 #define ICMPV4_UNRNET 0                   /* Code: Net unreachable  */
1402 #define ICMPV4_UNRHOST 1                  /* Code: host unreachable */
1403 #define ICMPV4_UNRPROT 2                  /* Code: protocol unreachable */
1404 #define ICMPV4_UNRPORT 3                  /* Code: port unreachable */
1405 #define ICMPV4_UNRFRAG 4                  /* Code: frag req DF set  */
1406 #define ICMPV4_UNRADMIN 13                /* Code: administratively prohib. */
1407 #define ICMPV4_SOURCEROUTE_FAILED 5       /* Code: administratively prohib. */
1408
1409 #define ICMPV4_SRC_ROUTE_FAIL 5           /* Code: Source Route Failed */
1410 #define ICMPV4_NO_ROUTE_DESTN_8 8         /* Code: No Route to Destn */
1411 #define ICMPV4_NO_ROUTE_DESTN_11 11       /* Code: No Route to Destn */
1412 #define ICMPV4_NO_ROUTE_DESTN_12 12       /* Code: No Route to Destn */
1413
1414 #define ICMPV4_ADMIN_PROH_9 9             /* Code: Administratively Prohibited */
1415 #define ICMPV4_ADMIN_PROH_10 10             /* Code: Administratively Prohibited */
1416 #define ICMPV4_PREC_CUTOFF 15             /* Code: Precedence Cutoff  */
1417
1418
1419 #define ICMPV4_TIMEEXCEEDED 11            /* Type: time exceeded */
1420 #define ICMPV4_TIMTTL 0                   /* Code: ttl in transit code */
1421
1422 #define ICMPV4_PARAMETER_PROBLEM    12    /* Type: Parameter Problem */
1423 #define ICMPV4_PARAM_ERROR  0             /* Code: Pointer to Error  */
1424 #define ICMPV4_MISSING_OPTION_CODE  1     /* Code: Mission option */
1425 #define ICMPV4_PARAM_BAD_LEN  2           /* Code:  Bad Length */
1426
1427 #define ICMPV4_CONVERSION_ERROR     31
1428 #define ICMPV4_SOURCE_QUENCH        4
1429 #define ICMPV4_REDIRECT             5
1430 #define ICMPV4_TIMESTAMP            13
1431 #define ICMPV4_TIMESTAMP_REPLY      14
1432 #define ICMPV4_INFO_REQUEST         15
1433 #define ICMPV4_INFO_REPLY           16
1434 #define ICMPV4_ADDR_MASK_REQUEST    17
1435 #define ICMPV4_ADDR_MASK_REPLY      18
1436
1437 typedef struct icmp_v6_s {
1438
1439     u8 type;
1440     u8 code;
1441     u16 checksum;
1442
1443     u32 data[0];
1444 } icmp_v6_t;
1445
1446 typedef struct pseudo_v6_header {
1447     u32 src_addr[4];
1448     u32 dst_addr[4];
1449     u16 payload_length;
1450     u16 next_header;
1451 } pseudo_v6_header_t;
1452
1453
1454 #define ICMPV6_ECHO                 128
1455 #define ICMPV6_ECHO_REPLY           129
1456 #define ICMPV6_PKT_TOO_BIG          2
1457 #define ICMPV6_TIMEEXCEEDED         3
1458 #define ICMPV6_TIMTTL               0
1459 #define ICMPV6_PARAMETER_PROBLEM    4
1460 #define ICMPV6_UNREACHABLE          1
1461 #define ICMPV6_NEIGHBOR_SOLICITAION 135
1462 #define ICMPV6_NEIGHBOR_ADVT        136
1463 /* ICMP V6 generated packet size */
1464 #define ICMPV6_ERR_SIZE          48 
1465 #define ICMPV6_HDR_SIZE          (sizeof(icmp_v6_t) +sizeof(u32))
1466
1467 /* Code for Type 1 */
1468 #define ICMPV6_UNRDESTN      0  /* Code: No route to Desnt */
1469 #define ICMPV6_ADM_PROH      1  /* Code: Adminitrative Prohibited */
1470 #define ICMPV6_SRC_ADD_SCOPE 2  /* Code: Source Address beyond scope */
1471 #define ICMPV6_UNRHOST       3  /* Code: Host Unreachable */
1472 #define ICMPV6_UNRPORT       4  /* Code: Port UnReachable */
1473
1474 #define ICMPV6_UNRPROT       1  /* type 4 - Code: No route to Desnt */
1475
1476 #define ICMPV6_PTB_CODE      0  /* Code: For PTB */
1477 #define ICMPV6_PARAM_CODE    0  /* Code: For Parameter Problem */
1478 #define ICMPV6_UNREC_HDR     1  /* Code: For Parameter Problem */
1479 #define ICMPV6_SRC_ADD_FAIL  5  /* Code: For Source address failed */
1480 #define ICMP_ECHO_REPLY_CODE 0
1481 #define DEFAULT_TTL_HOPLIMIT_VAL 64
1482
1483 typedef struct pptp_hdr_type {
1484
1485   u16 flags_ver;
1486   u16 proto_type;  /* PPP = 0x880B */
1487   u16 payload_len;
1488   u16 call_id;
1489   u32 seq_no;
1490   u32 ack_no;
1491
1492 } pptp_hdr_type_t;
1493
1494 /*
1495  * NAME
1496  *
1497  *   tcp_findoption
1498  *
1499  * SYNOPSIS
1500  *   u8* tcp_findoption (tcp_hdr_t *tcp, uchar option)
1501  *
1502  * PARAMETERS
1503  *   tcp       - pointer to TCP header
1504  *   option    - TCP option
1505  *
1506  * RETURNS
1507  *   This function returns a pointer to the option found,
1508  *   otherwise returns null.
1509  *
1510  *
1511  * DESCRIPTION
1512  *   This function searches the option and returns a pointer to the
1513  *   matched option field containing option kind/length/data sub-fields.
1514  *
1515  */
1516 static inline u8* tcp_findoption (tcp_hdr_type *tcp, u8 option)
1517 {
1518     u8*data;
1519     u8 len, optlen;
1520
1521     data = tcp->option_data;
1522     len = ((tcp->hdr_len>>4) << 2) - sizeof(tcp_hdr_type);
1523
1524 #define         MAXTCPOPTIONBYTES   40
1525 #define         MINTCPOPTIONLENGTH   2
1526
1527     while (len) {
1528         if (PREDICT_TRUE(option == data[0])) {
1529             return (data);
1530         } else {
1531             switch (data[0]) {
1532             case TCP_END_OPTIONS_LIST:
1533                 return (NULL);
1534             case TCP_OPTION_NOP:
1535                 len -= 1;
1536                 data += 1;
1537                 break;
1538             default:
1539                 /* Sanity check the length. */
1540                 optlen = data[1];
1541                 if ((optlen < MINTCPOPTIONLENGTH) ||
1542                     (optlen > MAXTCPOPTIONBYTES)  ||
1543                     (optlen > len)) {
1544                     return (NULL);
1545                 }
1546                 len -= optlen;
1547                 data += optlen;
1548                 break;
1549             }
1550         }
1551     }
1552
1553     return (NULL);
1554 }
1555
1556
1557 static inline u32 crc_calc (ipv4_header *ipv4)
1558 {
1559     u16 *ipv4_word_ptr = (u16 *) ipv4;
1560     u32 crc32;
1561     /*
1562      * Add all fields except the checksum field
1563      */
1564     crc32 = (u32)clib_net_to_host_u16(*ipv4_word_ptr)     +
1565             (u32)clib_net_to_host_u16(*(ipv4_word_ptr + 1)) +
1566             (u32)clib_net_to_host_u16(*(ipv4_word_ptr + 2)) +
1567             (u32)clib_net_to_host_u16(*(ipv4_word_ptr + 3)) +
1568             (u32)clib_net_to_host_u16(*(ipv4_word_ptr + 4)) +
1569             (u32)clib_net_to_host_u16(*(ipv4_word_ptr + 6)) +
1570             (u32)clib_net_to_host_u16(*(ipv4_word_ptr + 7)) +
1571             (u32)clib_net_to_host_u16(*(ipv4_word_ptr + 8)) +
1572             (u32)clib_net_to_host_u16(*(ipv4_word_ptr + 9));
1573
1574     /* Add in the carry of the original sum */
1575     crc32 = (crc32 & 0xFFFF) + (crc32 >> 16);
1576     /* Add in the carry of the final sum */
1577     crc32 = (crc32 & 0xFFFF) + (crc32 >> 16);
1578
1579     return crc32;
1580 }
1581
1582 #endif /* __TCP_HEADER_DEFINITIONS_H__ */