docs: Use newer Ubuntu LTS in tutorial
[vpp.git] / src / plugins / dhcp / client.h
1 /*
2  * Copyright (c) 2015 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  * client.h: dhcp client
17  */
18
19 #ifndef included_dhcp_client_h
20 #define included_dhcp_client_h
21
22 #include <vnet/ip/ip.h>
23 #include <dhcp/dhcp4_packet.h>
24
25 #define foreach_dhcp_client_state               \
26 _(DHCP_DISCOVER)                                \
27 _(DHCP_REQUEST)                                 \
28 _(DHCP_BOUND)
29
30 typedef enum
31 {
32 #define _(a) a,
33   foreach_dhcp_client_state
34 #undef _
35 } dhcp_client_state_t;
36
37 struct dhcp_client_t_;
38
39 /**
40  * Callback function for DHCP complete events
41  */
42 typedef void (*dhcp_event_cb_t) (u32 client_index,
43                                  const struct dhcp_client_t_ * client);
44
45 /**
46  * The set of addresses/mask that contribute forwarding info
47  * and are installed.
48  */
49 typedef struct dhcp_client_fwd_addresses_t_
50 {
51   /** the address assigned to this client and it's mask */
52   ip4_address_t leased_address;
53   u32 subnet_mask_width;
54
55   /** the address of the DHCP server handing out the address.
56       this is used to send any unicast messages */
57   ip4_address_t dhcp_server;
58
59   /** The address of this client's default gateway - may not be present */
60   ip4_address_t router_address;
61 } dhcp_client_fwd_addresses_t;
62
63 typedef struct dhcp_client_t_
64 {
65   dhcp_client_state_t state;
66
67   /* the interface in question */
68   u32 sw_if_index;
69
70   /* State machine retry counter */
71   u32 retry_count;
72
73   /* Send next pkt at this time */
74   f64 next_transmit;
75   f64 lease_expires;
76
77   /* DHCP transaction ID, a random number */
78   u32 transaction_id;
79
80   /**
81    * leased address, other learned info DHCP
82    *  the learned set is updated by new messages recieved in the DP
83    *  the installed set is what's actually been added
84    */
85   dhcp_client_fwd_addresses_t learned;
86   dhcp_client_fwd_addresses_t installed;
87   /* have local Addresses and default route been installed */
88   u8 addresses_installed;
89
90   ip4_address_t *domain_server_address; /* option 6 */
91   u32 lease_renewal_interval;   /* option 51 */
92   u32 lease_lifetime;           /* option 59 */
93
94   /* Requested data (option 55) */
95   u8 *option_55_data;
96
97   /* hostname and software client identifiers */
98   u8 *hostname;
99   u8 *client_identifier;        /* software version, e.g. vpe 1.0 */
100
101   /* Information used for event callback */
102   u32 client_index;
103   u32 pid;
104
105   /* Set the broadcast Flag in the Discover/Request messages */
106   u8 set_broadcast_flag;
107   /* Interface MAC address, so we can do an rx-packet-for-us check */
108   u8 client_hardware_address[6];
109   u8 client_detect_feature_enabled;
110
111   /* the broadcast adjacency on the link */
112   adj_index_t ai_bcast;
113   /* IP DSCP to set in sent packets */
114   ip_dscp_t dscp;
115
116   dhcp_event_cb_t event_callback;
117 } dhcp_client_t;
118
119 typedef struct
120 {
121   /* DHCP client pool */
122   dhcp_client_t *clients;
123   uword *client_by_sw_if_index;
124   u32 seed;
125
126   /* ip4-lookup node index */
127   u32 ip4_lookup_node_index;
128
129   /* convenience */
130   vlib_main_t *vlib_main;
131   vnet_main_t *vnet_main;
132 } dhcp_client_main_t;
133
134 typedef struct
135 {
136   int is_add;
137   u32 sw_if_index;
138   u8 set_broadcast_flag;
139
140   /* vectors, consumed by dhcp client code */
141   u8 *hostname;
142   u8 *client_identifier;
143
144   /* Bytes containing requested option numbers */
145   u8 *option_55_data;
146
147   /* Information used for event callback */
148   u32 client_index;
149   u32 pid;
150   ip_dscp_t dscp;
151   dhcp_event_cb_t event_callback;
152 } dhcp_client_add_del_args_t;
153
154 extern dhcp_client_main_t dhcp_client_main;
155
156 #define EVENT_DHCP_CLIENT_WAKEUP        1
157
158 int dhcp_client_for_us (u32 bi0,
159                         vlib_buffer_t * b0,
160                         ip4_header_t * ip0,
161                         udp_header_t * u0, dhcp_header_t * dh0);
162
163 /**
164  * Add/Delete DHCP clients
165  */
166 extern int dhcp_client_config (u32 is_add,
167                                u32 client_index,
168                                vlib_main_t * vm,
169                                u32 sw_if_index,
170                                u8 * hostname,
171                                u8 * client_id,
172                                dhcp_event_cb_t event_callback,
173                                u8 set_broadcast_flag,
174                                ip_dscp_t dscp, u32 pid);
175
176 /**
177  * callback function for clients walking the DHCP client configurations
178  *
179  * @param client The client being visitsed
180  * @param data   The data passed during the call to 'walk'
181  * @return !0 to continue walking 0 to stop.
182  */
183 typedef int (*dhcp_client_walk_cb_t) (const dhcp_client_t * client,
184                                       void *data);
185
186 /**
187  * Walk (visit each) DHCP client configuration
188  *
189  * @param cb The callback function invoked as each client is visited
190  * @param ctx Context data passed back to the client in the invocation of
191  *             the callback.
192  */
193 extern void dhcp_client_walk (dhcp_client_walk_cb_t cb, void *ctx);
194
195 #endif /* included_dhcp_client_h */
196
197 /*
198  * fd.io coding-style-patch-verification: ON
199  *
200  * Local Variables:
201  * eval: (c-set-style "gnu")
202  * End:
203  */