94 lines
2.5 KiB
C
94 lines
2.5 KiB
C
#ifndef IPCONFIG_H_
|
|
#define IPCONFIG_H_
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <errno.h>
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
#include <arpa/inet.h>
|
|
#include <sys/ioctl.h>
|
|
#include <net/if.h>
|
|
|
|
#define MAX_IF_NUM 32
|
|
#define INTERFACE_NAMSIZ 20
|
|
/* Max bit/byte length of IPv4 address. */
|
|
#define IPV4_MAX_BYTELEN 4
|
|
#define IPV4_MAX_BITLEN 32
|
|
#define IPV4_MAX_PREFIXLEN 32
|
|
#define IPV4_DEFAULT_PREFIXLEN 16
|
|
|
|
#define IPV4_ADDR_CMP(D,S) memcmp ((D), (S), IPV4_MAX_BYTELEN)
|
|
|
|
#define IPV4_ADDR_COPY(D,S) ipv4_addr_copy((D), (S))
|
|
|
|
#define IPV4_NET0(a) ((((uint)(a)) & 0xff000000) == 0x00000000)
|
|
#define IPV4_NET127(a) ((((uint)(a)) & 0xff000000) == 0x7f000000)
|
|
#define IPV4_LINKLOCAL(a) ((((uint)(a)) & 0xffff0000) == 0xa9fe0000)
|
|
#define IPV4_CLASS_DE(a) ((((uint)(a)) & 0xe0000000) == 0xe0000000)
|
|
#define IPV4_MC_LINKLOCAL(a) ((((uint)(a)) & 0xffffff00) == 0xe0000000)
|
|
#define IPV4_ADDR_SAME(A,B) ipv4_addr_same((A), (B))
|
|
|
|
static inline boolean ipv4_addr_same(const struct in_addr *a,
|
|
const struct in_addr *b)
|
|
{
|
|
return (a->s_addr == b->s_addr);
|
|
}
|
|
|
|
|
|
static inline void ipv4_addr_copy(struct in_addr *dst,
|
|
const struct in_addr *src)
|
|
{
|
|
dst->s_addr = src->s_addr;
|
|
}
|
|
|
|
/* NOTE: This routine expects the address argument in network byte order. */
|
|
static inline int ipv4_martian(struct in_addr *addr)
|
|
{
|
|
in_addr_t ip = ntohl(addr->s_addr);
|
|
|
|
if (IPV4_NET0(ip) || IPV4_NET127(ip) || IPV4_CLASS_DE(ip))
|
|
{
|
|
return TRUE;
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
|
|
/* 配置消息 */
|
|
struct _ip_config_str {
|
|
char ifname[INTERFACE_NAMSIZ];
|
|
uchar family;
|
|
uchar prefixlen;
|
|
struct in_addr prefix __attribute__((aligned(8)));
|
|
};
|
|
|
|
typedef struct _ip_config_str ip_config_t;
|
|
|
|
/* 业务模块函数声明 */
|
|
|
|
/* ip config */
|
|
ret_code ip_config_chk(uint source, uint config_type,
|
|
pointer input, int input_len,
|
|
pointer output, int *output_len);
|
|
|
|
ret_code ip_config_proc(uint source, uint config_type,
|
|
pointer input, int input_len,
|
|
pointer output, int *output_len);
|
|
|
|
ret_code ip_config_get(uint source,
|
|
pointer input, int input_len,
|
|
pointer output, int *output_len);
|
|
|
|
ret_code ip_config_get_all(uint source, uint64 config_id,
|
|
pointer output, short *single_len,
|
|
int *output_len);
|
|
|
|
|
|
|
|
#endif /* IPCONFIG_H_ */
|
|
|