Dear All,
I have a question about how to sync the interface infos via netlink while adding a new vlan module on linux machine. The initial runnning config I have is as follows,
Current configuration:
!
hostname Router
!
interface lo
ip address 127.0.0.1/8
!
interface sw0
ip address 192.168.8.120/25
!
ip route 0.0.0.0/0 192.168.8.1
!
After creating a new vlan 2 and setting its ip 130.233.235.1/24 through the attached CLI, it looks fine and "ifconfig" shows,
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 iB) TX bytes:0 (0.0 iB)
sw0 Link encap:Ethernet HWaddr 00:90:27:57:1B:00
inet addr:192.168.8.120 Bcast:192.168.8.127 Mask:255.255.255.128
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:0 (0.0 iB) TX bytes:0 (0.0 iB)
Interrupt:2 Base address:0xe000
sw0.2 Link encap:Ethernet HWaddr 00:90:27:57:1B:00
inet addr:130.233.235.1 Bcast:130.233.235.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 iB) TX bytes:0 (0.0 iB)
However, the running config becomes,
Current configuration:
!
hostname Router
!
interface lo
ip address 127.0.0.1/8
!
interface sw0
ip address 192.168.8.120/25
ip address 130.233.235.1/24
!
interface sw0.2
!
ip route 0.0.0.0/0 192.168.8.1
!
It should configure vlan 2 (sw0.2)'s ip address, not vlan 1 (sw0)'s ip address. Did I miss something?
It is highly appreciated that if any of you could kindly help me out.
Thank you so much!
Mike
------------------------------------------------------------------------------------------
DEFUN (zebra_interface_vlan,
zebra_interface_vlan_cmd,
"interface vlan VLAN-ID",
"Select an interface to configure\n"
"Select a vlan to configure\n"
"Vlan's id\n")
{
int fd;
struct vlan_ioctl_args if_request;
struct interface * ifp; // 11/03/03 mikeliu
char vlan_name[20]; // 11/03/03 mikeliu
char* cmd = "add"; // ADD_VLAN_CMD
char* if_name = "sw0";
unsigned int vid = 0;
char* conf_file_name = "/proc/net/vlan/config";
memset(&if_request, 0, sizeof(struct vlan_ioctl_args));
if(strlen(if_name) > 15) {
vty_out(vty, "ERROR: if_name must be 15 characters or less.%s", VTY_NEWLINE);
return CMD_WARNING;
}
strcpy(if_request.device1, if_name);
vid = atoi(argv[0]);
if_request.u.VID = vid;
// 11/03/03 mikeliu
if (vid == 1)
sprintf(vlan_name, "%s", if_name);
else
sprintf(vlan_name, "%s.%d", if_name, vid);
ifp = if_lookup_by_name (vlan_name);
if (ifp == NULL || ! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
{
if (ifp == NULL){
// Open up the /proc/vlan/config
if ((fd = open(conf_file_name, O_RDONLY)) < 0) {
vty_out(vty, "WARNING: Could not open /proc/net/vlan/config. Maybe you need to load the 8021q module, or maybe you are not using PROCFS??%s", VTY_NEWLINE);
}
else {
close(fd);
}
/* We use sockets now, instead of the file descriptor */
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
vty_out(vty, "FATAL: Couldn't open a socket..go figure!%s", VTY_NEWLINE);
}
/* add */
if (strcasecmp(cmd, "add") == 0) {
if_request.cmd = ADD_VLAN_CMD;
if (ioctl(fd, SIOCSIFVLAN, &if_request) < 0) {
vty_out(vty, "ERROR: trying to add VLAN #%u to IF -:%s:- error: %s%s", vid, if_name, strerror(errno), VTY_NEWLINE);
} else {
vty_out(vty, "Added VLAN with VID == %u to IF -:%s:- %s", vid, if_name, VTY_NEWLINE);
ifp = if_get_by_name (vlan_name);
/* If new link is added. */
if_add_update(ifp);
}
}
}
}
vty->index = ifp;
vty->node = INTERFACE_NODE;
vty_out(vty, "interface %s's index is %d%s", ifp->name, ifp->ifindex, VTY_NEWLINE);
return CMD_SUCCESS;
}
I have a question about how to sync the interface infos via netlink while adding a new vlan module on linux machine. The initial runnning config I have is as follows,
Current configuration:
!
hostname Router
!
interface lo
ip address 127.0.0.1/8
!
interface sw0
ip address 192.168.8.120/25
!
ip route 0.0.0.0/0 192.168.8.1
!
After creating a new vlan 2 and setting its ip 130.233.235.1/24 through the attached CLI, it looks fine and "ifconfig" shows,
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 iB) TX bytes:0 (0.0 iB)
sw0 Link encap:Ethernet HWaddr 00:90:27:57:1B:00
inet addr:192.168.8.120 Bcast:192.168.8.127 Mask:255.255.255.128
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:0 (0.0 iB) TX bytes:0 (0.0 iB)
Interrupt:2 Base address:0xe000
sw0.2 Link encap:Ethernet HWaddr 00:90:27:57:1B:00
inet addr:130.233.235.1 Bcast:130.233.235.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 iB) TX bytes:0 (0.0 iB)
However, the running config becomes,
Current configuration:
!
hostname Router
!
interface lo
ip address 127.0.0.1/8
!
interface sw0
ip address 192.168.8.120/25
ip address 130.233.235.1/24
!
interface sw0.2
!
ip route 0.0.0.0/0 192.168.8.1
!
It should configure vlan 2 (sw0.2)'s ip address, not vlan 1 (sw0)'s ip address. Did I miss something?
It is highly appreciated that if any of you could kindly help me out.
Thank you so much!
Mike
------------------------------------------------------------------------------------------
DEFUN (zebra_interface_vlan,
zebra_interface_vlan_cmd,
"interface vlan VLAN-ID",
"Select an interface to configure\n"
"Select a vlan to configure\n"
"Vlan's id\n")
{
int fd;
struct vlan_ioctl_args if_request;
struct interface * ifp; // 11/03/03 mikeliu
char vlan_name[20]; // 11/03/03 mikeliu
char* cmd = "add"; // ADD_VLAN_CMD
char* if_name = "sw0";
unsigned int vid = 0;
char* conf_file_name = "/proc/net/vlan/config";
memset(&if_request, 0, sizeof(struct vlan_ioctl_args));
if(strlen(if_name) > 15) {
vty_out(vty, "ERROR: if_name must be 15 characters or less.%s", VTY_NEWLINE);
return CMD_WARNING;
}
strcpy(if_request.device1, if_name);
vid = atoi(argv[0]);
if_request.u.VID = vid;
// 11/03/03 mikeliu
if (vid == 1)
sprintf(vlan_name, "%s", if_name);
else
sprintf(vlan_name, "%s.%d", if_name, vid);
ifp = if_lookup_by_name (vlan_name);
if (ifp == NULL || ! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
{
if (ifp == NULL){
// Open up the /proc/vlan/config
if ((fd = open(conf_file_name, O_RDONLY)) < 0) {
vty_out(vty, "WARNING: Could not open /proc/net/vlan/config. Maybe you need to load the 8021q module, or maybe you are not using PROCFS??%s", VTY_NEWLINE);
}
else {
close(fd);
}
/* We use sockets now, instead of the file descriptor */
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
vty_out(vty, "FATAL: Couldn't open a socket..go figure!%s", VTY_NEWLINE);
}
/* add */
if (strcasecmp(cmd, "add") == 0) {
if_request.cmd = ADD_VLAN_CMD;
if (ioctl(fd, SIOCSIFVLAN, &if_request) < 0) {
vty_out(vty, "ERROR: trying to add VLAN #%u to IF -:%s:- error: %s%s", vid, if_name, strerror(errno), VTY_NEWLINE);
} else {
vty_out(vty, "Added VLAN with VID == %u to IF -:%s:- %s", vid, if_name, VTY_NEWLINE);
ifp = if_get_by_name (vlan_name);
/* If new link is added. */
if_add_update(ifp);
}
}
}
}
vty->index = ifp;
vty->node = INTERFACE_NODE;
vty_out(vty, "interface %s's index is %d%s", ifp->name, ifp->ifindex, VTY_NEWLINE);
return CMD_SUCCESS;
}