blob: 844fb1f3a180b3599d10f422fe5323011561b0ac [file] [log] [blame]
lh0d3f4db2022-09-17 00:16:39 -07001//SPDX-License-Identifier: MediaTekProprietary
2#ifndef __PAL_NM_H__
3#define __PAL_NM_H__
4
5/**
6 * @file pal_nm.h
7 * @brief
8 * @author MediaTek
9 * @version v0.1
10 * @date 2016-07-11
11 */
12
13#ifdef __cplusplus
14extern "C" {
15#endif /* __cplusplus */
16
17#define NM_INTERFACE_FLAG_UP (0x1<<0) //IFF_UP
18#define NM_INTERFACE_FLAG_LOOPBACK (0x1<<2) //IPP_LOOPBACK
19
20typedef enum {
21 NM_IP_TYPE_UNKNOWN = 0,
22 NM_IP_TYPE_V6_UNSPEC = 0x1,
23 NM_IP_TYPE_V6_LOOPBACK = 0x2,
24 NM_IP_TYPE_V6_MULTICAST = 0x4,
25 NM_IP_TYPE_V6_LINKLOCAL = 0x8,
26 NM_IP_TYPE_V6_SITELOCAL = 0x10,
27
28 NM_IP_TYPE_V6_GLOBAL_PERNAMENT = 0x20,
29 NM_IP_TYPE_V6_GLOBAL_TEMP = 0x40,
30 NM_IP_TYPE_V6_GLOBAL_DYNAMIC =0x80,
31 NM_IP_TYPE_V6_GLOBAL = NM_IP_TYPE_V6_GLOBAL_PERNAMENT | NM_IP_TYPE_V6_GLOBAL_TEMP | NM_IP_TYPE_V6_GLOBAL_DYNAMIC,
32 NM_IP_TYPE_V6_UNIQUE = 0x100,
33
34 NM_IP_TYPE_V6_ALLCONFIG = NM_IP_TYPE_V6_GLOBAL | NM_IP_TYPE_V6_UNIQUE,
35 NM_IP_TYPE_V6_VALIDIP = NM_IP_TYPE_V6_GLOBAL_PERNAMENT | NM_IP_TYPE_V6_GLOBAL_DYNAMIC | NM_IP_TYPE_V6_UNIQUE, /*For App use*/
36
37} NM_IP_TYPE_V6;
38
39typedef enum {
40 NM_NETWORK_TYPE_UNKNOW = 0,
41 NM_NETWORK_TYPE_IMS = 1,
42 NM_NETWORK_TYPE_INTERNET = 2
43} NM_NETWORK_TYPE;
44
45/*interface ipv4 related APIs*/
46int nm_interface_ipv4_set(const char *intf_name, const char* addr, int prefix_len);
47int nm_interface_ipv4_up(const char *intf_name);
48int nm_interface_ipv4_down(const char *intf_name);
49int nm_interface_ipv4_mtu_set(const char *intf_name, int mtu);
50int nm_interface_ipv4_info_get(const char *intf_name, unsigned long *addr,
51 int *prefix_len, int *mtu, unsigned int*flags);
52int nm_interface_ipv4_hwaddr_get(const char *intf_name, unsigned char *hw_addr);
53int nm_interface_ipv4_addr_clear(const char *intf_name);
54
55
56/*interface ipv6 related APIs*/
57int nm_interface_ipv6_mtu_set(const char *intf_name, int mtu);
58int nm_interface_ipv6_addr_clear(const char *intf_name);
59int nm_interface_ipv6_set(const char *intf_name, int on);
60int nm_interface_ipv6_privacyextenstion_enable_set(const char *intf_name, int on);
61int nm_interface_ipv6_ndoffload_enable_set(const char *intf_name, int on);
62int nm_interface_ipv6_addr_set(const char *intf_name, const char *addr, int prefix_len);
63int nm_interface_ipv6_addr_get(const char *intf_name, int addr_type, char *addr, int *prefix_len);
64
65
66/*network related APIs*/
67int nm_network_create(unsigned net_id, const char *permission);
68int nm_network_destroy(unsigned net_id);
69int nm_network_default_set(unsigned net_id);
70int nm_network_default_clear();
71int nm_network_interface_add(unsigned net_id, const char* intf_name);
72int nm_network_interface_remove(unsigned net_id, const char* intf_name);
73int nm_network_route_add(unsigned net_id, const char* intf_name,
74 const char *destination, const char *nexthop,
75 int legacy, unsigned int uid);
76int nm_network_route_remove( unsigned net_id, const char* intf_name,
77 const char *destination, const char *nexthop,
78 int legacy, unsigned int uid);
79
80
81
82/*ipfwd related APIs*/
83int nm_fwd_ipv4_set(int enable, const char *requestor);
84int nm_fwd_ipv4_get(int *enable);
85int nm_fwd_ipv6_set(int enable, const char *requestor);
86int nm_fwd_ipv6_get(int *enable);
87
88
89/*DNS related APIs*/
90//set ipv6 dns name server
91int nm_resolver_ipv6_dns_set(unsigned net_id, const char *domains, const char* const* servers, int numservers, NM_NETWORK_TYPE type);
92
93//set ipv4 dns name server
94int nm_resolver_ipv4_dns_set(unsigned net_id, const char *domains, const char* const* servers, int numservers, NM_NETWORK_TYPE type);
95
96//set ipv4 && ipv6 dns name server
97int nm_resolver_dns_set(unsigned net_id, const char *domains, const char* const* servers, int numservers, NM_NETWORK_TYPE type);
98
99
100//clear name server for both ipv4/ipv6
101int nm_resolver_dns_clear(unsigned net_id);
102
103//flush dns cache
104int nm_resolver_dns_cache_flush(unsigned net_id);
105
106int nm_command_test(char *intf);
107
108int nm_interface_get_netid(const char *intf_name,unsigned int *netid);
109
110
111void nm_network_policy_route_init();
112int nm_network_ipv6_policy_route_modify(uint16_t action, uint32_t table, const char* interface);
113int nm_network_ipv6_policy_rule_modify(uint16_t action, uint32_t priority, uint32_t table, uint32_t fwmark, uint32_t mask, const char* iif, const char* oif);
114int nm_network_ipv4_policy_route_modify(uint16_t action, uint32_t table, const char* interface);
115int nm_network_ipv4_policy_rule_modify(uint16_t action, uint32_t priority, uint32_t table, uint32_t fwmark, uint32_t mask, const char* iif, const char* oif);
116struct Stats {
117 uint64_t rxBytes;
118 uint64_t rxPackets;
119 uint64_t txBytes;
120 uint64_t txPackets;
121 uint64_t tcpRxPackets;
122 uint64_t tcpTxPackets;
123};
124
125int parseIfaceStats(const char* iface, struct Stats* stats);
126
127
128#ifdef __cplusplus
129}
130#endif /* __cplusplus */
131
132#endif /* __PAL_NM_H__*/