1518678f8Sopenharmony_ci/*
2518678f8Sopenharmony_ci * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
3518678f8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4518678f8Sopenharmony_ci * you may not use this file except in compliance with the License.
5518678f8Sopenharmony_ci * You may obtain a copy of the License at
6518678f8Sopenharmony_ci *
7518678f8Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8518678f8Sopenharmony_ci *
9518678f8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10518678f8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11518678f8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12518678f8Sopenharmony_ci * See the License for the specific language governing permissions and
13518678f8Sopenharmony_ci * limitations under the License.
14518678f8Sopenharmony_ci */
15518678f8Sopenharmony_ci
16518678f8Sopenharmony_ci#ifndef OHOS_DHCP_ADDRESS_POOL_H
17518678f8Sopenharmony_ci#define OHOS_DHCP_ADDRESS_POOL_H
18518678f8Sopenharmony_ci
19518678f8Sopenharmony_ci#include <stdint.h>
20518678f8Sopenharmony_ci#include <map>
21518678f8Sopenharmony_ci#include "dhcp_binding.h"
22518678f8Sopenharmony_ci#include "dhcp_s_define.h"
23518678f8Sopenharmony_ci#include "dhcp_option.h"
24518678f8Sopenharmony_ci#ifdef __cplusplus
25518678f8Sopenharmony_ciextern "C" {
26518678f8Sopenharmony_ci#endif
27518678f8Sopenharmony_ci
28518678f8Sopenharmony_citypedef struct DhcpAddressPool DhcpAddressPool;
29518678f8Sopenharmony_citypedef AddressBinding *(*QueryBind)(uint8_t macAddr[DHCP_HWADDR_LENGTH], PDhcpOptionList cliOptins);
30518678f8Sopenharmony_citypedef AddressBinding *(*AddBind)(uint8_t macAddr[DHCP_HWADDR_LENGTH], PDhcpOptionList cliOptins);
31518678f8Sopenharmony_citypedef uint32_t (*Distribute)(DhcpAddressPool *pool, uint8_t macAddr[DHCP_HWADDR_LENGTH]);
32518678f8Sopenharmony_ci
33518678f8Sopenharmony_citypedef struct {
34518678f8Sopenharmony_ci    uint32_t beginAddress;
35518678f8Sopenharmony_ci    uint32_t endAddress;
36518678f8Sopenharmony_ci} IpAddressRange;
37518678f8Sopenharmony_ci
38518678f8Sopenharmony_cistruct DhcpAddressPool {
39518678f8Sopenharmony_ci    char ifname[IFACE_NAME_SIZE];
40518678f8Sopenharmony_ci    uint32_t netmask;
41518678f8Sopenharmony_ci    IpAddressRange addressRange;
42518678f8Sopenharmony_ci    uint32_t serverId;
43518678f8Sopenharmony_ci    uint32_t gateway;
44518678f8Sopenharmony_ci    uint32_t leaseTime;
45518678f8Sopenharmony_ci    uint32_t renewalTime;
46518678f8Sopenharmony_ci    uint32_t rebindingTime;
47518678f8Sopenharmony_ci    uint32_t distribution;
48518678f8Sopenharmony_ci    Distribute distribue;
49518678f8Sopenharmony_ci    QueryBind binding;
50518678f8Sopenharmony_ci    AddBind newBinding;
51518678f8Sopenharmony_ci    std::map<uint32_t, AddressBinding> leaseTable;
52518678f8Sopenharmony_ci    DhcpOptionList fixedOptions;
53518678f8Sopenharmony_ci    int initialized;
54518678f8Sopenharmony_ci};
55518678f8Sopenharmony_ci
56518678f8Sopenharmony_ciint InitAddressPool(DhcpAddressPool *pool, const char *ifname, PDhcpOptionList options);
57518678f8Sopenharmony_civoid FreeAddressPool(DhcpAddressPool *pool);
58518678f8Sopenharmony_ciAddressBinding *FindBindingByIp(uint32_t bingdingIp);
59518678f8Sopenharmony_ciint IsReserved(uint8_t macAddr[DHCP_HWADDR_LENGTH]);
60518678f8Sopenharmony_ciint IsReservedIp(DhcpAddressPool *pool, uint32_t ipAddress);
61518678f8Sopenharmony_ciint AddBinding(AddressBinding *binding);
62518678f8Sopenharmony_ciint AddReservedBinding(uint8_t macAddr[DHCP_HWADDR_LENGTH]);
63518678f8Sopenharmony_ciint RemoveReservedBinding(uint8_t macAddr[DHCP_HWADDR_LENGTH]);
64518678f8Sopenharmony_ciint RemoveBinding(uint8_t macAddr[DHCP_HWADDR_LENGTH]);
65518678f8Sopenharmony_ciint ReleaseBinding(uint8_t macAddr[DHCP_HWADDR_LENGTH]);
66518678f8Sopenharmony_ciint AddLease(DhcpAddressPool *pool, AddressBinding *lease);
67518678f8Sopenharmony_ciAddressBinding *GetLease(DhcpAddressPool *pool, uint32_t ipAddress);
68518678f8Sopenharmony_ciint UpdateLease(DhcpAddressPool *pool, AddressBinding *lease);
69518678f8Sopenharmony_ciint RemoveLease(DhcpAddressPool *pool, AddressBinding *lease);
70518678f8Sopenharmony_ciint LoadBindingRecoders(DhcpAddressPool *pool);
71518678f8Sopenharmony_ciint SaveBindingRecoders(const DhcpAddressPool *pool, int force);
72518678f8Sopenharmony_ciAddressBinding *QueryBinding(uint8_t macAddr[DHCP_HWADDR_LENGTH], PDhcpOptionList cliOptins);
73518678f8Sopenharmony_civoid SetDistributeMode(int mode);
74518678f8Sopenharmony_ciint GetDistributeMode(void);
75518678f8Sopenharmony_ciint DeleteMacInLease(DhcpAddressPool *pool, AddressBinding *lease);
76518678f8Sopenharmony_ci
77518678f8Sopenharmony_ci#ifdef __cplusplus
78518678f8Sopenharmony_ci}
79518678f8Sopenharmony_ci#endif
80518678f8Sopenharmony_ci#endif
81