Initial commit of vpp code.
[vpp.git] / vnet / vnet / ip / udp.h
1 /*
2  * ip/udp.h: udp protocol
3  *
4  * Copyright (c) 2013 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #ifndef included_udp_h
19 #define included_udp_h
20
21 #include <vnet/vnet.h>
22 #include <vnet/ip/udp_packet.h>
23 #include <vnet/ip/ip.h>
24 #include <vnet/ip/ip4.h>
25 #include <vnet/ip/ip4_packet.h>
26 #include <vnet/pg/pg.h>
27 #include <vnet/ip/format.h>
28
29 typedef enum {
30 #define udp_error(n,s) UDP_ERROR_##n,
31 #include <vnet/ip/udp_error.def>
32 #undef udp_error
33   UDP_N_ERROR,
34 } udp_error_t;
35
36 #define foreach_udp4_dst_port                   \
37 _ (67, dhcp_to_server)                          \
38 _ (68, dhcp_to_client)                          \
39 _ (500, ikev2)                                  \
40 _ (4341, lisp_gpe)                              \
41 _ (4739, ipfix)                                 \
42 _ (4789, vxlan)                                 \
43 _ (4790, vxlan_gpe)                             \
44 _ (6633, vpath_3)
45
46
47 #define foreach_udp6_dst_port                   \
48 _ (547, dhcpv6_to_server)                       \
49 _ (546, dhcpv6_to_client)                       \
50 _ (6633, vpath6_3)
51
52 typedef enum {
53 #define _(n,f) UDP_DST_PORT_##f = n,
54   foreach_udp4_dst_port
55   foreach_udp6_dst_port
56 #undef _
57 } udp_dst_port_t;
58
59 typedef enum {
60 #define _(n,f) UDP6_DST_PORT_##f = n,
61   foreach_udp6_dst_port
62 #undef _
63 } udp6_dst_port_t;
64
65 typedef struct {
66   /* Name (a c string). */
67   char * name;
68
69   /* GRE protocol type in host byte order. */
70   udp_dst_port_t dst_port;
71
72   /* Node which handles this type. */
73   u32 node_index;
74
75   /* Next index for this type. */
76   u32 next_index;
77 } udp_dst_port_info_t;
78
79 typedef enum {
80   UDP_IP6 = 0,
81   UDP_IP4,                      /* the code is full of is_ip4... */
82   N_UDP_AF,
83 } udp_af_t;
84
85 typedef struct {
86   udp_dst_port_info_t * dst_port_infos [N_UDP_AF];
87
88   /* Hash tables mapping name/protocol to protocol info index. */
89   uword * dst_port_info_by_name[N_UDP_AF];
90   uword * dst_port_info_by_dst_port[N_UDP_AF];
91
92   /* convenience */
93   vlib_main_t * vlib_main;
94 } udp_main_t;
95
96 always_inline udp_dst_port_info_t *
97 udp_get_dst_port_info (udp_main_t * um, udp_dst_port_t dst_port, u8 is_ip4)
98 {
99   uword * p = hash_get (um->dst_port_info_by_dst_port[is_ip4], dst_port);
100   return p ? vec_elt_at_index (um->dst_port_infos[is_ip4], p[0]) : 0;
101 }
102
103 format_function_t format_udp_header;
104 format_function_t format_udp_rx_trace;
105
106 unformat_function_t unformat_udp_header;
107
108 void udp_register_dst_port (vlib_main_t * vm,
109                             udp_dst_port_t dst_port,
110                             u32 node_index, u8 is_ip4);
111
112 #endif /* included_udp_h */
113