blob: f1993ddcb4fa09ff970535f8e8103446af54526b [file] [log] [blame]
#ifndef __PIPED__
#define __PIPED__
#include <uci.h>
#include <libubus.h>
#include <stdbool.h>
#define MAX_DHCP_OPT_STR_LEN 256
#define MAX_FNAME 256
#define MAX_IFNAME 16
#define MAX_SEC_NAME 16
#define MAX_IP_STR_LEN 16
#define MAX_IP6_STR_LEN 46
#define MAX_PREFIX_STR_LEN 4
/* pd_iface flags definition */
#define PDI_LAN 0x00000001
#define PDI_UP 0x00000002
#define PDI_UP6 0x00000004
#define PDI_AUTO 0x00000008
#define PDI_IPADDR 0x00000010
#define PDI_DNS4P 0x00000020
#define PDI_DNS4S 0x00000040
#define PDI_IP6ADDR 0x00000080
#define PDI_DNS6P 0x00000100
#define PDI_DNS6S 0x00000200
#define PDI_DEDICATEAPN 0x00000400
#define PDI_COMBINE_IF 0x00000800
#define PDI_ZVLAN_ID 0x00001000
/* pd_context flags definition */
#define PDC_NETWORK_CHANGED 0x00000001
#define PDC_ODHCPD_CHANGED 0x00000002
#define PDC_DNSMASQ_CHANGED 0x00000004
#define MPIPE_PATH "/sys/kernel/mpipe/devices/"
#define USB_EN_PATH "/sys/class/android_usb/android0/enable"
#define MPIPE_FNAME_UP "up"
#define MPIPE_FNAME_UP6 "up6"
#define MPIPE_FNAME_IP "ipaddr"
#define MPIPE_FNAME_GW "gateway"
#define MPIPE_FNAME_IP6 "ll6addr"
#define MPIPE_FNAME_DNS6P "dns6p"
#define MPIPE_FNAME_DNS6S "dns6s"
#define MPIPE_FNAME_COMBINEIF "combineif"
#define MPIPE_FNAME_GB6ADDR "gb6addr"
#define UCI_PKG_PIPE "pipe"
#define UCI_PKG_NW "network"
#define UCI_PKG_DHCP "dhcp"
#define UCI_SEC_LAN "lan"
#define UCI_SEC_WAN "wan"
#define UCI_SEC_INTERFACE "interface"
#define UCI_OPT_DEVICE "device"
#define UCI_OPT_IPADDR "ipaddr"
#define UCI_OPT_IP6ADDR "ip6addr"
#define UCI_OPT_AUTO "auto"
#define UCI_OPT_DNS "dns"
#define UCI_OPT_START "start"
#define UCI_OPT_LIMIT "limit"
#define UCI_OPT_DHCP_OPT "dhcp_option"
#define UCI_OPT_DEDICATE_OPT "dedicate"
#define UCI_OPT_NETMASK "netmask"
#define UCI_OPT_GW "gateway"
#define UCI_OPT_COMBINE_IF_OPT "combineif"
#define UCI_OPT_VID_OPT "vid"
#define UCI_OPT_PROT "proto"
#define UCI_OPT_MTU "mtu"
#define UCI_DFLT_MTU "1500"
#define UCI_STATIC "static"
#define UCI_NONE "none"
#define UCI_DHCP_OPTNUM_SNMASK "1"
#define UCI_DHCP_OPTNUM_GW "3"
#define UCI_DHCP_OPTNUM_DNS "6"
#define UCI_DHCP_DFLT_START 100
#define UCI_DHCP_DFLT_LIMIT 150
#define UCI_DHCP_DFLT_SNMASK "255.255.255.0"
#define UCI_DHCP_DFLT_SNMASK1 "255.255.0.0"
#define UCI_DHCP_DFLT_SNMASK2 "255.0.0.0"
#define UCI_NW_DFLT_IP "192.168.1.1"
#define EMPTY_IPV4 "0.0.0.0"
#define EMPTY_IPV6 "::"
#define IPV4_FMT "%d.%d.%d.%d"
#define UCI_IPV6_DFLT_PREF 64
struct pd_path {
char buf[MAX_FNAME];
char *iptr;
char *fptr;
};
struct pd_context {
struct uci_context *c;
struct pd_path path;
unsigned int status;
};
struct pdi_status {
unsigned int added;
unsigned int changed;
unsigned int removed;
unsigned int same;
};
struct pd_iface {
int idx;
char ifname[MAX_IFNAME];
char sec[MAX_SEC_NAME];
char ipaddr[MAX_IP_STR_LEN];
char dns4p[MAX_IP_STR_LEN];
char dns4s[MAX_IP_STR_LEN];
char ip6addr[MAX_IP6_STR_LEN];
char dns6p[MAX_IP6_STR_LEN];
char dns6s[MAX_IP6_STR_LEN];
char combine_if[MAX_IFNAME];
struct list_head list;
struct list_head uplist;
struct list_head up6list;
unsigned int flags;
};
struct piped {
struct pd_iface *lan;
struct list_head plist;
struct list_head uplist;
struct list_head up6list;
struct pd_context pdc;
struct ubus_context *u_ctx;
bool rand_gw;
};
static inline bool pd_test(unsigned int *flags, unsigned int mask)
{
return *flags & mask;
}
static inline void pd_set(unsigned int *flags, unsigned int mask)
{
*flags |= mask;
}
static inline void pd_clear(unsigned int *flags, unsigned int mask)
{
*flags &= ~mask;
}
static inline bool pdi_test(struct pd_iface *pdi, unsigned int mask)
{
return pd_test(&pdi->flags, mask);
}
static inline void pdi_set(struct pd_iface *pdi, unsigned int mask)
{
pd_set(&pdi->flags, mask);
}
static inline void pdi_clear(struct pd_iface *pdi, unsigned int mask)
{
pd_clear(&pdi->flags, mask);
}
void pd_uevent_cb(char *ifname, bool added);
int pd_system(const char *cmd);
#endif