Support packets in flight
[samplevnf.git] / VNFs / DPPD-PROX / ip_subnet.h
1 /*
2 // Copyright (c) 2010-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
17 #ifndef _IP_SUBNET_H_
18 #define _IP_SUBNET_H_
19
20 #include <inttypes.h>
21
22 struct ip4_subnet {
23         uint32_t ip;
24         uint8_t prefix; /* always in range [1,32] inclusive */
25 };
26
27 struct ip6_subnet {
28         uint8_t ip[16];
29         uint8_t prefix; /* always in range [1,128] inclusive */
30 };
31
32 /* Returns number of hosts (assuming that network address and
33    broadcast address are both hosts) within the subnet. */
34 uint32_t ip4_subet_get_n_hosts(const struct ip4_subnet *sn);
35
36 /* Allows to get a specific host within a subnet. Note that the
37    network address and broadcast address are both considered to
38    "hosts". Setting host_index to 0 returns the network address and
39    setting the host_index to the last host within the subnet returns
40    the broadcast. To get all addresses with the subnet, loop
41    host_index from 0 to ip_subnet_get_n_hosts(). */
42 int ip4_subnet_to_host(const struct ip4_subnet* sn, uint32_t host_index, uint32_t* ret_ip);
43
44 /* Check if IP address is a network address (i.e. all bits outside the
45    prefix are set to 0). */
46 int ip4_subnet_is_valid(const struct ip4_subnet* sn);
47
48 #endif /* _IP_SUBNET_H_ */