Added support for VLAN in IPv6
[samplevnf.git] / VNFs / DPPD-PROX / prox_ipv6.h
1 /*
2 // Copyright (c) 2020 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 #ifndef _PROX_IP_V6_H_
18 #define _PROX_IP_V6_H_
19
20 #include "ip6_addr.h"
21
22 #define ALL_NODES_IPV6_MCAST_ADDR               "ff02:0000:0000:0000:0000:0000:0000:0001"       // FF02::1
23 #define ALL_ROUTERS_IPV6_MCAST_ADDR             "ff02:0000:0000:0000:0000:0000:0000:0002"       // FF02::2
24
25 #define RANDOM_IPV6                             "1234:1234:1234:1234:1234:1234:1234:1234"       // Used by PROX as a flag forrandom IP
26
27 #define ALL_DHCP_RELAY_AGENTS_AND_SERVERS       "ff02:0000:0000:0000:0000:0000:0001:0002"       // FF02::1:2
28 #define ALL_DHCP_SERVERS                        "ff05:0000:0000:0000:0000:0000:0001:0003"       // FF02::1:2
29
30 #define DHCP_CLIENT_UDP_PORT    546
31 #define DHCP_SERVER_UDP_PORT    547
32
33 #define PROX_UNSOLLICITED       0
34 #define PROX_SOLLICITED         1
35
36 #define ICMPv6  0x3a
37
38 #define ICMPv6_DU       0x01
39 #define ICMPv6_PTB      0x02
40 #define ICMPv6_TE       0x03
41 #define ICMPv6_PaPr     0x04
42 #define ICMPv6_RS       0x85
43 #define ICMPv6_RA       0x86
44 #define ICMPv6_NS       0x87
45 #define ICMPv6_NA       0x88
46 #define ICMPv6_RE       0x89
47
48 #define ICMPv6_source_link_layer_address        1
49 #define ICMPv6_target_link_layer_address        2
50 #define ICMPv6_prefix_information               3
51 #define ICMPv6_redirect_header                  4
52 #define ICMPv6_mtu                              5
53
54 extern struct ipv6_addr null_addr;
55
56 struct icmpv6_prefix_option {
57         uint8_t type;
58         uint8_t length;
59         uint8_t prefix_length;
60         uint8_t flag;
61         uint32_t valid_lifetime;
62         uint32_t preferred_lifetime;
63         uint32_t reserved;
64         struct ipv6_addr prefix;
65 };
66
67 struct icmpv6_option {
68         uint8_t type;
69         uint8_t length;
70         uint8_t data[6];
71 }  __attribute__((__packed__));
72
73 struct icmpv6 {
74         uint8_t   type;
75         uint8_t   code;
76         uint16_t  checksum;
77 };
78
79 struct icmpv6_RA {
80         uint8_t   type;
81         uint8_t   code;
82         uint16_t  checksum;
83         uint8_t   hop_limit;
84         uint8_t   bits;
85         uint16_t  router_lifespan;
86         uint32_t  reachable_timeout;
87         uint32_t  retrans_timeout;
88         struct icmpv6_option  options;
89 } __attribute__((__packed__));
90
91 struct icmpv6_RS {
92         uint8_t   type;
93         uint8_t   code;
94         uint16_t  checksum;
95         uint32_t  reserved;
96         struct icmpv6_option  options;
97 } __attribute__((__packed__));
98
99 struct icmpv6_NS {
100         uint8_t   type;
101         uint8_t   code;
102         uint16_t  checksum;
103         uint32_t  reserved;
104         struct ipv6_addr target_address;
105         struct icmpv6_option  options;
106 } __attribute__((__packed__));
107
108 struct icmpv6_NA {
109         uint8_t   type;
110         uint8_t   code;
111         uint16_t  checksum;
112         uint16_t  bits;
113         uint16_t  reserved;
114         struct ipv6_addr destination_address;
115         struct icmpv6_option  options;
116 } __attribute__((__packed__));
117
118 struct icmpv6_RE {
119         uint8_t   type;
120         uint8_t   code;
121         uint16_t  checksum;
122         uint32_t  reserved;
123         struct ipv6_addr destination_address_hop;
124         struct ipv6_addr destination_address;
125         uint32_t  Options;
126 } __attribute__((__packed__));
127
128 void set_mcast_mac_from_ipv6(prox_rte_ether_addr *mac, struct ipv6_addr *ipv6_addr);
129 char *IP6_Canonical(struct ipv6_addr *addr);
130 void set_link_local(struct ipv6_addr *ipv6_addr);
131 void set_EUI(struct ipv6_addr *ipv6_addr, prox_rte_ether_addr *mac);
132 void create_mac_from_EUI(struct ipv6_addr *ipv6_addr, prox_rte_ether_addr *mac);
133
134 struct task_base;
135 prox_rte_ipv6_hdr *prox_get_ipv6_hdr(prox_rte_ether_hdr *hdr, uint16_t len, uint16_t *vlan);
136 void build_router_sollicitation(struct rte_mbuf *mbuf, prox_rte_ether_addr *s_addr, struct ipv6_addr *ipv6_s_addr, uint16_t vlan);
137 void build_router_advertisement(struct rte_mbuf *mbuf, prox_rte_ether_addr *s_addr, struct ipv6_addr *ipv6_s_addr, struct ipv6_addr *router_prefix, uint16_t vlan);
138 void build_neighbour_sollicitation(struct rte_mbuf *mbuf, prox_rte_ether_addr *s_addr, struct ipv6_addr *dst, struct ipv6_addr *src, uint16_t vlan);
139 void build_neighbour_advertisement(struct task_base *tbase, struct rte_mbuf *mbuf, prox_rte_ether_addr *target_mac, struct ipv6_addr *ipv6_addr, int sollicited, uint16_t vlan);
140
141 #endif /* _PROX_IP_V6_H_ */