Implement DHCPv6 PD client (VPP-718, VPP-1050)
[vpp.git] / src / vnet / dhcp / dhcp6_pd_client_dp.h
1 /*
2  * Copyright (c) 2018 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #ifndef included_vnet_dhcp6_pd_client_dp_h
17 #define included_vnet_dhcp6_pd_client_dp_h
18
19 #include <vlib/vlib.h>
20
21 #define vl_typedefs             /* define message structures */
22 #include <vnet/vnet_all_api_h.h>
23 #undef vl_typedefs
24
25 typedef struct
26 {
27   u32 preferred_lt;
28   u32 valid_lt;
29   ip6_address_t prefix;
30   u8 prefix_length;
31 } dhcp6_pd_send_client_message_params_prefix_t;
32
33 typedef struct
34 {
35   u32 sw_if_index;
36   u32 server_index;
37   u32 irt;
38   u32 mrt;
39   u32 mrc;
40   u32 mrd;
41   u8 msg_type;
42   u32 T1;
43   u32 T2;
44   dhcp6_pd_send_client_message_params_prefix_t *prefixes;
45 } dhcp6_pd_send_client_message_params_t;
46
47 void dhcp6_pd_send_client_message (vlib_main_t * vm, u32 sw_if_index, u8 stop,
48                                    dhcp6_pd_send_client_message_params_t *
49                                    params);
50 void dhcp6_pd_set_publisher_node (uword node_index, uword event_type);
51 void dhcp6_clients_enable_disable (u8 enable);
52
53 void
54   vl_api_want_dhcp6_pd_reply_events_t_handler
55   (vl_api_want_dhcp6_pd_reply_events_t * mp);
56 void
57   vl_api_dhcp6_pd_send_client_message_t_handler
58   (vl_api_dhcp6_pd_send_client_message_t * mp);
59 void
60   vl_api_dhcp6_clients_enable_disable_t_handler
61   (vl_api_dhcp6_clients_enable_disable_t * mp);
62
63 extern vlib_node_registration_t dhcp6_pd_reply_process_node;
64
65 enum
66 { DHCP6_PD_DP_REPLY_REPORT, REPORT_MAX };
67
68 typedef struct _vnet_dhcp6_pd_reply_function_list_elt
69 {
70   struct _vnet_dhcp6_pd_reply_function_list_elt
71     *next_dhcp6_pd_reply_event_function;
72   clib_error_t *(*fp) (vl_api_dhcp6_pd_reply_event_t * mp);
73 } _vnet_dhcp6_pd_reply_event_function_list_elt_t;
74
75 typedef struct
76 {
77   _vnet_dhcp6_pd_reply_event_function_list_elt_t *functions;
78 } dhcp6_pd_client_public_main_t;
79
80 extern dhcp6_pd_client_public_main_t dhcp6_pd_client_public_main;
81
82 #define VNET_DHCP6_PD_REPLY_EVENT_FUNCTION(f)                             \
83                                                                           \
84 static void __vnet_dhcp6_pd_reply_event_function_init_##f (void)          \
85     __attribute__((__constructor__)) ;                                    \
86                                                                           \
87 static void __vnet_dhcp6_pd_reply_event_function_init_##f (void)          \
88 {                                                                         \
89  dhcp6_pd_client_public_main_t * nm = &dhcp6_pd_client_public_main;       \
90  static _vnet_dhcp6_pd_reply_event_function_list_elt_t init_function;     \
91  init_function.next_dhcp6_pd_reply_event_function = nm->functions;        \
92  nm->functions = &init_function;                                          \
93  init_function.fp = (void *) &f;                                          \
94 }                                                                         \
95                                                                           \
96 static void __vnet_dhcp6_pd_reply_event_function_deinit_##f (void)        \
97     __attribute__((__destructor__)) ;                                     \
98                                                                           \
99 static void __vnet_dhcp6_pd_reply_event_function_deinit_##f (void)        \
100 {                                                                         \
101  dhcp6_pd_client_public_main_t * nm = &dhcp6_pd_client_public_main;       \
102  _vnet_dhcp6_pd_reply_event_function_list_elt_t *next;                    \
103  if (nm->functions->fp == (void *) &f)                                    \
104     {                                                                     \
105       nm->functions =                                                     \
106         nm->functions->next_dhcp6_pd_reply_event_function;                \
107       return;                                                             \
108     }                                                                     \
109   next = nm->functions;                                                   \
110   while (next->next_dhcp6_pd_reply_event_function)                        \
111     {                                                                     \
112       if (next->next_dhcp6_pd_reply_event_function->fp == (void *) &f)    \
113         {                                                                 \
114           next->next_dhcp6_pd_reply_event_function =                      \
115             next->next_dhcp6_pd_reply_event_function->next_dhcp6_pd_reply_event_function; \
116           return;                                                         \
117         }                                                                 \
118       next = next->next_dhcp6_pd_reply_event_function;                    \
119     }                                                                     \
120 }
121
122 #endif /* included_vnet_dhcp6_pd_client_dp_h */
123
124 /*
125  * fd.io coding-style-patch-verification: ON
126  *
127  * Local Variables:
128  * eval: (c-set-style "gnu")
129  * End:
130  */