• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
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 OHOS_DHCP_ADDRESS_POOL_H
17 #define OHOS_DHCP_ADDRESS_POOL_H
18 
19 #include <stdint.h>
20 #include "dhcp_binding.h"
21 #include "dhcp_define.h"
22 #include "dhcp_option.h"
23 #include "hash_table.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 typedef struct DhcpAddressPool DhcpAddressPool;
30 typedef AddressBinding *(*QueryBind)(uint8_t macAddr[DHCP_HWADDR_LENGTH], PDhcpOptionList cliOptins);
31 typedef AddressBinding *(*AddBind)(uint8_t macAddr[DHCP_HWADDR_LENGTH], PDhcpOptionList cliOptins);
32 typedef uint32_t (*Distribute)(DhcpAddressPool *pool, uint8_t macAddr[DHCP_HWADDR_LENGTH]);
33 
34 typedef struct {
35     uint32_t beginAddress;
36     uint32_t endAddress;
37 } IpAddressRange;
38 
39 struct DhcpAddressPool {
40     char ifname[IFACE_NAME_SIZE];
41     uint32_t netmask;
42     IpAddressRange addressRange;
43     uint32_t serverId;
44     uint32_t gateway;
45     uint32_t leaseTime;
46     uint32_t renewalTime;
47     uint32_t rebindingTime;
48     uint32_t distribution;
49     Distribute distribue;
50     QueryBind binding;
51     AddBind newBinding;
52     HashTable leaseTable;
53     DhcpOptionList fixedOptions;
54     int initialized;
55 };
56 
57 int InitAddressPool(DhcpAddressPool *pool, const char *ifname, PDhcpOptionList options);
58 void FreeAddressPool(DhcpAddressPool *pool);
59 AddressBinding *FindBindingByIp(uint32_t bingdingIp);
60 int IsReserved(uint8_t macAddr[DHCP_HWADDR_LENGTH]);
61 int IsReservedIp(DhcpAddressPool *pool, uint32_t ipAddress);
62 int AddBinding(AddressBinding *binding);
63 int AddReservedBinding(uint8_t macAddr[DHCP_HWADDR_LENGTH]);
64 int RemoveReservedBinding(uint8_t macAddr[DHCP_HWADDR_LENGTH]);
65 int RemoveBinding(uint8_t macAddr[DHCP_HWADDR_LENGTH]);
66 int ReleaseBinding(uint8_t macAddr[DHCP_HWADDR_LENGTH]);
67 int AddLease(DhcpAddressPool *pool, AddressBinding *lease);
68 AddressBinding *GetLease(DhcpAddressPool *pool, uint32_t ipAddress);
69 int UpdateLease(DhcpAddressPool *pool, AddressBinding *lease);
70 int RemoveLease(DhcpAddressPool *pool, AddressBinding *lease);
71 int LoadBindingRecoders(DhcpAddressPool *pool);
72 int SaveBindingRecoders(const DhcpAddressPool *pool, int force);
73 AddressBinding *GetBindingByIp(HashTable *bindTable, uint32_t ipAddress);
74 AddressBinding *QueryBinding(uint8_t macAddr[DHCP_HWADDR_LENGTH], PDhcpOptionList cliOptins);
75 void SetDistributeMode(int mode);
76 int GetDistributeMode(void);
77 
78 #ifdef __cplusplus
79 }
80 #endif
81 #endif
82