common: Adding common library for sample vnf
[samplevnf.git] / common / VIL / l2l3_stack / lib_icmpv6.h
1 /*
2 // Copyright (c) 2017 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 /*      Author - Santosh Sethupathi     */
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <stdint.h>
20 #include <string.h>
21 #include <unistd.h>
22 #include <rte_common.h>
23 #include <rte_malloc.h>
24 #include <rte_ip.h>
25 #include <rte_byteorder.h>
26 #include <rte_table_lpm.h>
27 #include <rte_table_hash.h>
28 #include <rte_pipeline.h>
29 #include <rte_arp.h>
30 #include <rte_icmp.h>
31 #include <rte_hash.h>
32 #include <rte_jhash.h>
33 #include <rte_cycles.h>
34 #include "lib_arp.h"
35 #include <rte_pipeline.h>
36 #include "rte_ether.h"
37
38 /**
39 * ICMPv6 Header
40 */
41
42 struct icmpv6_hdr {
43         uint8_t icmpv6_type;    /**< ICMPV6 packet type. */
44         uint8_t icmpv6_code;    /**<  ICMPV6 packet code. */
45         uint16_t icmpv6_cksum;  /**< ICMPV6 packet checksum. */
46 } __attribute__ ((__packed__));
47
48 /**
49 * ICMPV6 Info Header
50 */
51 struct icmpv6_info_hdr {
52         uint16_t icmpv6_ident;  /**< ICMPV6 packet identifier. */
53         uint16_t icmpv6_seq_nb; /**< ICMPV6 packet sequence number. */
54 } __attribute__ ((__packed__));
55
56 /**
57  * ICMPV6 ND Header
58  */
59 struct icmpv6_nd_hdr {
60         /*ND Advertisement flags */
61         uint32_t icmpv6_reserved; /**< bit31-Router, bit30-Solicited, bit29-Override, bit28-bit0 unused */
62
63         uint8_t target_ipv6[16];  /**< target IPv6 address */
64         uint8_t type;                   /**< ICMPv6 Option*/
65         uint8_t length;          /**< Length */
66         uint8_t link_layer_addr[6]; /**< Link layer address */
67 } __attribute__ ((__packed__));
68
69 /* Icmpv6 types */
70 #define ICMPV6_PROTOCOL_ID 58
71 #define ICMPV6_ECHO_REQUEST 0x0080
72 #define ICMPV6_ECHO_REPLY 0x0081
73 #define ICMPV6_NEIGHBOR_SOLICITATION 0x0087
74 #define ICMPV6_NEIGHBOR_ADVERTISEMENT 0x0088
75 #define IPV6_MULTICAST 0xFF02
76
77 #define NEIGHBOR_SOLICITATION_SET 0x40000000
78 #define NEIGHBOR_ROUTER_OVERRIDE_SET 0xa0000000
79 enum icmpv6_link_layer_Address_type {
80         e_Source_Link_Layer_Address = 1,
81         e_Target_Link_Layer_Address,
82         e_Link_Layer_Address
83 };
84
85 /* Checks whether ipv6 is multicast
86  * @param ipv6
87  */
88 uint8_t is_multicast_ipv6_addr(uint8_t ipv6[]);
89
90 /**
91 *Icmpv6 Port address
92 */
93 struct icmpv6_port_address {
94         uint32_t ipv6[16];   /**< Ipv6 address */
95         uint64_t mac_addr;   /**< Mac address */
96 };
97
98 /**
99 * To store Icmpv6 Port address
100 */
101 struct icmpv6_port_address icmpv6_port_addresses[RTE_MAX_ETHPORTS];
102
103 #define MAX_NUM_ICMPv6_ENTRIES 64
104 struct rte_mbuf *lib_icmpv6_pkt;
105
106 /**
107  * Processes icmpv6 packets
108  * @param pkt
109  *  pkt mbuf packets
110  * @param port
111  *  port - port structure
112  */
113 void process_icmpv6_pkt(struct rte_mbuf *pkt, l2_phy_interface_t *port);