MOD aaa-12 增加提供给dhcp的接口函数 SOL 增加提供给dhcp的接口函数 修改人:zhangliang 检视人:zhangliang
This commit is contained in:
parent
d8fac7bb53
commit
68ab2cbf93
|
@ -27,55 +27,6 @@ struct _net_ifnum {
|
|||
};
|
||||
typedef struct _net_ifnum net_ifnum_t;
|
||||
|
||||
|
||||
#if 0
|
||||
struct _ethtool_value {
|
||||
uint cmd;
|
||||
uint data;
|
||||
};
|
||||
typedef struct _ethtool_value ethtool_value_t;
|
||||
|
||||
|
||||
|
||||
|
||||
struct ethtool_cmd {
|
||||
uint cmd;
|
||||
uint supported;
|
||||
uint advertising;
|
||||
uint16 speed;
|
||||
uchar duplex;
|
||||
uchar port;
|
||||
uchar phy_address;
|
||||
uchar transceiver;
|
||||
uchar autoneg;
|
||||
uchar mdio_support;
|
||||
uint maxtxpkt;
|
||||
uint maxrxpkt;
|
||||
uint16 speed_hi;
|
||||
uchar eth_tp_mdix;
|
||||
uchar eth_tp_mdix_ctrl;
|
||||
uint lp_advertising;
|
||||
uint reserved[2];
|
||||
};
|
||||
|
||||
struct ethtool_link_settings {
|
||||
uint cmd;
|
||||
uint speed;
|
||||
uchar duplex;
|
||||
uchar port;
|
||||
uchar phy_address;
|
||||
uchar autoneg;
|
||||
uchar mdio_support;
|
||||
uchar eth_tp_mdix;
|
||||
uchar eth_tp_mdix_ctrl;
|
||||
uchar link_mode_masks_nwords;
|
||||
uchar transceiver;
|
||||
uchar reserved1[3];
|
||||
uint reserved[7];
|
||||
uint link_mode_masks[0];
|
||||
};
|
||||
#endif
|
||||
|
||||
struct ethtool_link_data{
|
||||
struct ethtool_link_settings req;
|
||||
uint link_mode_data[3 * ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32];
|
||||
|
@ -142,7 +93,20 @@ struct interface {
|
|||
int keepalive; /* keepalive value for SLIP */
|
||||
int outfill; /* outfill value for SLIP */
|
||||
};
|
||||
#ifndef _LINUX_IN6_H
|
||||
/*
|
||||
* This is in linux/include/net/ipv6.h.
|
||||
*/
|
||||
|
||||
struct in6_ifreq {
|
||||
struct in6_addr ifr6_addr;
|
||||
uint ifr6_prefixlen;
|
||||
unsigned int ifr6_ifindex;
|
||||
};
|
||||
|
||||
#endif
|
||||
ret_code ip_config_type_dhcp(char *ifname);
|
||||
ret_code ip_config_type_dhcpv6(char *ifname);
|
||||
ret_code if_get_ipenable(if_info_t *if_info);
|
||||
ret_code if_get_v4proto(if_info_t *if_info);
|
||||
ret_code if_get_v6proto(if_info_t *if_info);
|
||||
|
|
|
@ -16,18 +16,6 @@
|
|||
#include "netconfig.h"
|
||||
#include "parsefile.h"
|
||||
|
||||
#ifndef _LINUX_IN6_H
|
||||
/*
|
||||
* This is in linux/include/net/ipv6.h.
|
||||
*/
|
||||
|
||||
struct in6_ifreq {
|
||||
struct in6_addr ifr6_addr;
|
||||
uint ifr6_prefixlen;
|
||||
unsigned int ifr6_ifindex;
|
||||
};
|
||||
|
||||
#endif
|
||||
net_ifnum_t g_if_num = {.wan_num = 2, .lan_num = 4};
|
||||
|
||||
/* Display an Ethernet address in readable format. */
|
||||
|
@ -39,12 +27,6 @@ static void print_ether(char *buff, unsigned char *ptr)
|
|||
(ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)
|
||||
);
|
||||
}
|
||||
#if 0
|
||||
static uint ethtool_cmd_speed(const struct ethtool_cmd *ep)
|
||||
{
|
||||
return (ep->speed_hi << 16) | ep->speed;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* call ioctl system call */
|
||||
ret_code if_ioctl(int af, unsigned long request, caddr_t ifreq)
|
||||
|
@ -389,7 +371,7 @@ ret_code if_set_prefix(ip_config_t *ip_conf)
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_code if_del_oldin6(char *name, struct in6_ifreq *ifr6)
|
||||
ret_code if_del_in6(char *name, struct in6_ifreq *ifr6)
|
||||
{
|
||||
v6addr_t ipv6_arr[IPV6_ADDR_NUM] = {0};
|
||||
struct in6_ifreq ifdel = {0};
|
||||
|
@ -440,7 +422,7 @@ ret_code if_set_prefix6(uint config_type, ip_config_t *ip_conf)
|
|||
|
||||
if(config_type == CM_CONFIG_SET)
|
||||
{
|
||||
ret = if_del_oldin6(ip_conf->ifname, &ifr6);
|
||||
ret = if_del_in6(ip_conf->ifname, &ifr6);
|
||||
if(ret == RET_EXIST)
|
||||
{
|
||||
return RET_OK;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "rpc.h"
|
||||
#include "parsefile.h"
|
||||
#include "netconfig.h"
|
||||
#include "dhcp_lib.h"
|
||||
|
||||
uchar ip_masklen(struct in_addr netmask)
|
||||
{
|
||||
|
@ -44,6 +45,28 @@ static char *ip_inet6_print(struct in6_addr *ptr)
|
|||
return name;
|
||||
}
|
||||
|
||||
void ip_save_dhcp(char *ifname)
|
||||
{
|
||||
char static_name[IF_BUFF_LEN] = {0};
|
||||
char static_buff[IF_BUFF_LEN] = {0};
|
||||
|
||||
sprintf(static_name, "iface %s inet", ifname);
|
||||
sprintf(static_buff, "iface %s inet dhcp\n", ifname);
|
||||
|
||||
if_conf_file_set(ifname, static_name, static_buff);
|
||||
}
|
||||
|
||||
void ip_save_dhcpv6(char *ifname)
|
||||
{
|
||||
char static_name[IF_BUFF_LEN] = {0};
|
||||
char static_buff[IF_BUFF_LEN] = {0};
|
||||
|
||||
sprintf(static_name, "iface %s inet6", ifname);
|
||||
sprintf(static_buff, "iface %s inet6 dhcp\n", ifname);
|
||||
|
||||
if_conf_file_set(ifname, static_name, static_buff);
|
||||
}
|
||||
|
||||
|
||||
void ip_save_file(ip_config_t *ip_conf, uint config_type)
|
||||
{
|
||||
|
@ -252,6 +275,41 @@ cJSON * ip_config_format_json(if_info_t *config_buff, int v6_cnt)
|
|||
return json_obj;
|
||||
}
|
||||
|
||||
ret_code ip_del_allin6(char *name)
|
||||
{
|
||||
v6addr_t ipv6_arr[IPV6_ADDR_NUM] = {0};
|
||||
struct in6_ifreq ifdel = {0};
|
||||
ip_config_t ip_conf = {0};
|
||||
int addr_cnt = 0;
|
||||
int ifindex = 0;
|
||||
int i;
|
||||
|
||||
ifindex = if_nametoindex(name);
|
||||
ASSERT_COND(ifindex == 0);
|
||||
|
||||
addr_cnt = if_read_in6_file(name, ipv6_arr, IPV6_ADDR_NUM);
|
||||
|
||||
for(i = 0; i < addr_cnt; i++)
|
||||
{
|
||||
memset(&ifdel, 0, sizeof(struct in6_ifreq));
|
||||
ifdel.ifr6_ifindex = ifindex;
|
||||
ifdel.ifr6_prefixlen = ipv6_arr[i].prefixlen;
|
||||
memcpy((char *) &ifdel.ifr6_addr, &(ipv6_arr[i].addr), sizeof(struct in6_addr));
|
||||
|
||||
if_ioctl(AF_INET6, SIOCDIFADDR, (caddr_t)&ifdel);
|
||||
|
||||
memset(&ip_conf, 0, sizeof(ip_config_t));
|
||||
strncpy(&(ip_conf.ifname), name, INTERFACE_NAMSIZ - 1);
|
||||
memcpy(&(ip_conf.ipv6.addr), &(ipv6_arr[i].addr), sizeof(struct in6_addr));
|
||||
ip_conf.ipv6.prefixlen = ipv6_arr[i].prefixlen;
|
||||
|
||||
ip6_save_file(&ip_conf, CM_CONFIG_DEL);
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
||||
ret_code if_get_info(if_info_t *if_info, int *v6_cnt)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
|
@ -602,3 +660,52 @@ ret_code ip_config_get_all(uint source, pointer output, int *output_len)
|
|||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_code ip_config_type_dhcp(char *ifname)
|
||||
{
|
||||
uint conf_type = CM_CONFIG_DEL;
|
||||
ip_config_t ip_conf = {0};
|
||||
if_info_t if_info = {0};
|
||||
ret_code ret = RET_OK;
|
||||
|
||||
strncpy(if_info.ifname, ifname, INTERFACE_NAMSIZ - 1);
|
||||
if_get_v4proto(&if_info);
|
||||
if(strcmp(if_info.v4protocol, "dhcp") == 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
strncpy(ip_conf.ifname, ifname, INTERFACE_NAMSIZ - 1);
|
||||
ip_conf.family = AF_INET;
|
||||
ip_conf.ipv4.addr.s_addr = 0;
|
||||
|
||||
ret = if_set_prefix(&ip_conf);
|
||||
|
||||
ip_save_file(&ip_conf, conf_type);
|
||||
ip_save_dhcp(ifname);
|
||||
|
||||
ASSERT_RET(ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret_code ip_config_type_dhcpv6(char *ifname)
|
||||
{
|
||||
struct in6_ifreq ifr6 = {0};
|
||||
if_info_t if_info = {0};
|
||||
ret_code ret = RET_OK;
|
||||
|
||||
strncpy(if_info.ifname, ifname, INTERFACE_NAMSIZ - 1);
|
||||
if_get_v6proto(&if_info);
|
||||
if(strcmp(if_info.v6protocol, "dhcp") == 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = ip_del_allin6(ifname);
|
||||
ip_save_dhcpv6(ifname);
|
||||
|
||||
ASSERT_RET(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue