| lh | 0d3f4db | 2022-09-17 00:16:39 -0700 | [diff] [blame] | 1 | //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 |
| 14 | extern "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 | |
| 20 | typedef 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 | |
| 39 | typedef 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*/ |
| 46 | int nm_interface_ipv4_set(const char *intf_name, const char* addr, int prefix_len); |
| 47 | int nm_interface_ipv4_up(const char *intf_name); |
| 48 | int nm_interface_ipv4_down(const char *intf_name); |
| 49 | int nm_interface_ipv4_mtu_set(const char *intf_name, int mtu); |
| 50 | int nm_interface_ipv4_info_get(const char *intf_name, unsigned long *addr, |
| 51 | int *prefix_len, int *mtu, unsigned int*flags); |
| 52 | int nm_interface_ipv4_hwaddr_get(const char *intf_name, unsigned char *hw_addr); |
| 53 | int nm_interface_ipv4_addr_clear(const char *intf_name); |
| 54 | |
| 55 | |
| 56 | /*interface ipv6 related APIs*/ |
| 57 | int nm_interface_ipv6_mtu_set(const char *intf_name, int mtu); |
| 58 | int nm_interface_ipv6_addr_clear(const char *intf_name); |
| 59 | int nm_interface_ipv6_set(const char *intf_name, int on); |
| 60 | int nm_interface_ipv6_privacyextenstion_enable_set(const char *intf_name, int on); |
| 61 | int nm_interface_ipv6_ndoffload_enable_set(const char *intf_name, int on); |
| 62 | int nm_interface_ipv6_addr_set(const char *intf_name, const char *addr, int prefix_len); |
| 63 | int nm_interface_ipv6_addr_get(const char *intf_name, int addr_type, char *addr, int *prefix_len); |
| 64 | |
| 65 | |
| 66 | /*network related APIs*/ |
| 67 | int nm_network_create(unsigned net_id, const char *permission); |
| 68 | int nm_network_destroy(unsigned net_id); |
| 69 | int nm_network_default_set(unsigned net_id); |
| 70 | int nm_network_default_clear(); |
| 71 | int nm_network_interface_add(unsigned net_id, const char* intf_name); |
| 72 | int nm_network_interface_remove(unsigned net_id, const char* intf_name); |
| 73 | int nm_network_route_add(unsigned net_id, const char* intf_name, |
| 74 | const char *destination, const char *nexthop, |
| 75 | int legacy, unsigned int uid); |
| 76 | int 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*/ |
| 83 | int nm_fwd_ipv4_set(int enable, const char *requestor); |
| 84 | int nm_fwd_ipv4_get(int *enable); |
| 85 | int nm_fwd_ipv6_set(int enable, const char *requestor); |
| 86 | int nm_fwd_ipv6_get(int *enable); |
| 87 | |
| 88 | |
| 89 | /*DNS related APIs*/ |
| 90 | //set ipv6 dns name server |
| 91 | int 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 |
| 94 | int 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 |
| 97 | int 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 |
| 101 | int nm_resolver_dns_clear(unsigned net_id); |
| 102 | |
| 103 | //flush dns cache |
| 104 | int nm_resolver_dns_cache_flush(unsigned net_id); |
| 105 | |
| 106 | int nm_command_test(char *intf); |
| 107 | |
| 108 | int nm_interface_get_netid(const char *intf_name,unsigned int *netid); |
| 109 | |
| 110 | |
| 111 | void nm_network_policy_route_init(); |
| 112 | int nm_network_ipv6_policy_route_modify(uint16_t action, uint32_t table, const char* interface); |
| 113 | int 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); |
| 114 | int nm_network_ipv4_policy_route_modify(uint16_t action, uint32_t table, const char* interface); |
| 115 | int 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); |
| 116 | struct 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 | |
| 125 | int parseIfaceStats(const char* iface, struct Stats* stats); |
| 126 | |
| 127 | |
| 128 | #ifdef __cplusplus |
| 129 | } |
| 130 | #endif /* __cplusplus */ |
| 131 | |
| 132 | #endif /* __PAL_NM_H__*/ |