Click
Loading...
Searching...
No Matches
ip6.h
1/* -*- mode: c; c-basic-offset: 4 -*- */
2#ifndef CLICKNET_IP6_H
3#define CLICKNET_IP6_H
4//#include <clicknet/ip.h>
5/* get struct in6_addr */
6#include <click/cxxprotect.h>
7CLICK_CXX_PROTECT
8
9#if CLICK_LINUXMODULE
10# include <net/checksum.h>
11# include <linux/in6.h>
12#else
13# include <sys/types.h>
14# undef true
15# include <netinet/in.h>
16# define true linux_true
17#endif
18
19struct click_ip6 {
20 union {
21 struct {
22 uint32_t ip6_un1_flow; /* 0-3 bits 0-3: version == 6 */
23 /* bits 4-11: traffic class */
24 /* bits 4-9: DSCP */
25 /* bits 10-11: ECN */
26 /* bits 12-31: flow label */
27 uint16_t ip6_un1_plen; /* 4-5 payload length */
28 uint8_t ip6_un1_nxt; /* 6 next header */
29 uint8_t ip6_un1_hlim; /* 7 hop limit */
30 } ip6_un1;
31 uint8_t ip6_un2_vfc; /* 0 bits 0-3: version == 6 */
32 /* bits 4-7: top 4 class bits */
33 struct {
34#if CLICK_BYTE_ORDER == CLICK_BIG_ENDIAN
35 unsigned ip6_un3_v : 4; /* 0 version == 6 */
36 unsigned ip6_un3_fc : 4; /* header length */
37#elif CLICK_BYTE_ORDER == CLICK_LITTLE_ENDIAN
38 unsigned ip6_un3_fc : 4; /* 0 header length */
39 unsigned ip6_un3_v : 4; /* version == 6 */
40#endif
41 } ip6_un3;
42 } ip6_ctlun;
43 struct in6_addr ip6_src; /* 8-23 source address */
44 struct in6_addr ip6_dst; /* 24-39 dest address */
45} CLICK_SIZE_PACKED_ATTRIBUTE;
46
47struct click_ip6_eh {
48 uint8_t nxt;
49 uint8_t len;
50} CLICK_SIZE_PACKED_ATTRIBUTE;
51
52#define ip6_v ip6_ctlun.ip6_un3.ip6_un3_v
53#define ip6_vfc ip6_ctlun.ip6_un2_vfc
54#define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow
55#define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen
56#define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt
57#define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim
58
59#define IP6_EH_HOPBYHOP 0
60#define IP6_EH_ROUTING 43
61#define IP6_EH_FRAGMENT 44
62#define IP6_EH_AH 51
63#define IP6_EH_ESP 50
64#define IP6_EH_NONXT 59
65#define IP6_EH_DST 60
66#define IP6_EH_MOBILITY 135
67
68#define IP6_FLOW_MASK 0x000FFFFFU
69#define IP6_FLOW_SHIFT 0
70#define IP6_CLASS_MASK 0x0FF00000U
71#define IP6_CLASS_SHIFT 20
72#define IP6_DSCP_MASK 0x0FC00000U
73#define IP6_DSCP_SHIFT 22
74#define IP6_V_MASK 0xF0000000U
75#define IP6_V_SHIFT 28
76
77#define IP6_CHECK_V(hdr) (((hdr).ip6_vfc & htonl(IP6_V_MASK)) == htonl(6 << IP6_V_SHIFT))
78
79#ifndef IP6PROTO_FRAGMENT
80#define IP6PROTO_FRAGMENT 0x2c
81#endif
82struct click_ip6_fragment {
83 uint8_t ip6_frag_nxt;
84 uint8_t ip6_frag_reserved;
85 uint16_t ip6_frag_offset;
86#define IP6_MF 0x0001
87#define IP6_OFFMASK 0xFFF8
88 /* bits 0-12: Fragment offset */
89 /* bit 13-14: reserved */
90 /* bit 15: More Fragment */
91 uint32_t ip6_frag_id;
92} CLICK_SIZE_PACKED_ATTRIBUTE;
93
94#ifndef IP6PROTO_SEGMENT_ROUTING
95#define IP6PROTO_SEGMENT_ROUTING 4
96#endif
97struct click_ip6_sr {
98 uint8_t ip6_sr_next;
99 uint8_t ip6_hdrlen;
100 uint8_t type; // Always 4 for Segment Routing
101 uint8_t segment_left;
102 uint8_t last_entry; // Number of segments in the Segment List
103 uint8_t flags;
104 uint16_t tag;
105 struct in6_addr segments[0]; // Segment List (variable length)
106} CLICK_SIZE_PACKED_ATTRIBUTE;
107
108struct click_sr6_tlv {
109 uint8_t type;
110 uint8_t len;
111 uint8_t value[0];
112} CLICK_SIZE_PACKED_ATTRIBUTE;
113
114uint16_t in6_fast_cksum(const struct in6_addr *saddr,
115 const struct in6_addr *daddr,
116 uint16_t len,
117 uint8_t proto,
118 uint16_t ori_csum,
119 const unsigned char *addr,
120 uint16_t len2);
121
122uint16_t in6_cksum(const struct in6_addr *saddr,
123 const struct in6_addr *daddr,
124 uint16_t len,
125 uint8_t proto,
126 uint16_t ori_csum,
127 unsigned char *addr,
128 uint16_t len2);
129
130CLICK_CXX_UNPROTECT
131#include <click/cxxunprotect.h>
132#endif