Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
linux
Commits
a734e8de
Commit
a734e8de
authored
Jul 19, 2003
by
Jeff Garzik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[bonding] sync ifenslave with 2.4 (pulls in several bug fixes)
parent
58e3b621
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
232 additions
and
114 deletions
+232
-114
Documentation/networking/ifenslave.c
Documentation/networking/ifenslave.c
+232
-114
No files found.
Documentation/networking/ifenslave.c
View file @
a734e8de
...
@@ -27,7 +27,7 @@
...
@@ -27,7 +27,7 @@
* - 2001/02/16 Chad N. Tindel <ctindel at ieee dot org> :
* - 2001/02/16 Chad N. Tindel <ctindel at ieee dot org> :
* - Master is now brought down before setting the MAC address. In
* - Master is now brought down before setting the MAC address. In
* the 2.4 kernel you can't change the MAC address while the device is
* the 2.4 kernel you can't change the MAC address while the device is
* up because you get EBUSY.
* up because you get EBUSY.
*
*
* - 2001/09/13 Takao Indoh <indou dot takao at jp dot fujitsu dot com>
* - 2001/09/13 Takao Indoh <indou dot takao at jp dot fujitsu dot com>
* - Added the ability to change the active interface on a mode 1 bond
* - Added the ability to change the active interface on a mode 1 bond
...
@@ -44,17 +44,60 @@
...
@@ -44,17 +44,60 @@
*
*
* - 2002/10/31 Tony Cureington <tony.cureington * hp_com> :
* - 2002/10/31 Tony Cureington <tony.cureington * hp_com> :
* - If the master does not have a hardware address when the first slave
* - If the master does not have a hardware address when the first slave
* is enslaved, the master is assigned the hardware address of that
* is enslaved, the master is assigned the hardware address of that
* slave - there is a comment in bonding.c stating "ifenslave takes
* slave - there is a comment in bonding.c stating "ifenslave takes
* care of this now." This corrects the problem of slaves having
* care of this now." This corrects the problem of slaves having
* different hardware addresses in active-backup mode when
* different hardware addresses in active-backup mode when
* multiple interfaces are specified on a single ifenslave command
* multiple interfaces are specified on a single ifenslave command
* (ifenslave bond0 eth0 eth1).
* (ifenslave bond0 eth0 eth1).
*
*
* - 2003/03/18 - Tsippy Mendelson <tsippy.mendelson at intel dot com> and
* Shmulik Hen <shmulik.hen at intel dot com>
* - Moved setting the slave's mac address and openning it, from
* the application to the driver. This enables support of modes
* that need to use the unique mac address of each slave.
* The driver also takes care of closing the slave and restoring its
* original mac address upon release.
* In addition, block possibility of enslaving before the master is up.
* This prevents putting the system in an undefined state.
*
* - 2003/05/01 - Amir Noam <amir.noam at intel dot com>
* - Added ABI version control to restore compatibility between
* new/old ifenslave and new/old bonding.
* - Prevent adding an adapter that is already a slave.
* Fixes the problem of stalling the transmission and leaving
* the slave in a down state.
*
* - 2003/05/01 - Shmulik Hen <shmulik.hen at intel dot com>
* - Prevent enslaving if the bond device is down.
* Fixes the problem of leaving the system in unstable state and
* halting when trying to remove the module.
* - Close socket on all abnormal exists.
* - Add versioning scheme that follows that of the bonding driver.
* current version is 1.0.0 as a base line.
*
* - 2003/05/22 - Jay Vosburgh <fubar at us dot ibm dot com>
* - ifenslave -c was broken; it's now fixed
* - Fixed problem with routes vanishing from master during enslave
* processing.
*
* - 2003/05/27 - Amir Noam <amir.noam at intel dot com>
* - Fix backward compatibility issues:
* For drivers not using ABI versions, slave was set down while
* it should be left up before enslaving.
* Also, master was not set down and the default set_mac_address()
* would fail and generate an error message in the system log.
* - For opt_c: slave should not be set to the master's setting
* while it is running. It was already set during enslave. To
* simplify things, it is now handeled separately.
*/
*/
#define APP_VERSION "1.0.12"
#define APP_RELDATE "June 30, 2003"
#define APP_NAME "ifenslave"
static
char
*
version
=
static
char
*
version
=
"ifenslave.c:v0.07 9/9/97
Donald Becker (becker@cesdis.gsfc.nasa.gov).
\n
"
APP_NAME
".c:v"
APP_VERSION
" ("
APP_RELDATE
") "
"
\n
Donald Becker (becker@cesdis.gsfc.nasa.gov).
\n
"
"detach support added on 2000/10/02 by Willy Tarreau (willy at meta-x.org).
\n
"
"detach support added on 2000/10/02 by Willy Tarreau (willy at meta-x.org).
\n
"
"2.4 kernel support added on 2001/02/16 by Chad N. Tindel (ctindel at ieee dot org.
\n
"
;
"2.4 kernel support added on 2001/02/16 by Chad N. Tindel (ctindel at ieee dot org.
\n
"
;
...
@@ -103,6 +146,12 @@ static const char *howto_msg =
...
@@ -103,6 +146,12 @@ static const char *howto_msg =
#include <linux/if_bonding.h>
#include <linux/if_bonding.h>
#include <linux/sockios.h>
#include <linux/sockios.h>
typedef
unsigned
long
long
u64
;
/* hack, so we may include kernel's ethtool.h */
typedef
__uint32_t
u32
;
/* ditto */
typedef
__uint16_t
u16
;
/* ditto */
typedef
__uint8_t
u8
;
/* ditto */
#include <linux/ethtool.h>
struct
option
longopts
[]
=
{
struct
option
longopts
[]
=
{
/* { name has_arg *flag val } */
/* { name has_arg *flag val } */
{
"all-interfaces"
,
0
,
0
,
'a'
},
/* Show all interfaces. */
{
"all-interfaces"
,
0
,
0
,
'a'
},
/* Show all interfaces. */
...
@@ -130,18 +179,19 @@ opt_howto = 0;
...
@@ -130,18 +179,19 @@ opt_howto = 0;
int
skfd
=
-
1
;
/* AF_INET socket for ioctl() calls. */
int
skfd
=
-
1
;
/* AF_INET socket for ioctl() calls. */
static
void
if_print
(
char
*
ifname
);
static
void
if_print
(
char
*
ifname
);
static
int
get_abi_ver
(
char
*
master_ifname
);
int
int
main
(
int
argc
,
char
**
argv
)
main
(
int
argc
,
char
**
argv
)
{
{
struct
ifreq
ifr2
,
if_hwaddr
,
if_ipaddr
,
if_metric
,
if_mtu
,
if_dstaddr
;
struct
ifreq
ifr2
,
if_hwaddr
,
if_ipaddr
,
if_metric
,
if_mtu
,
if_dstaddr
;
struct
ifreq
if_netmask
,
if_brdaddr
,
if_flags
;
struct
ifreq
if_netmask
,
if_brdaddr
,
if_flags
;
int
goterr
=
0
;
int
rv
,
goterr
=
0
;
int
c
,
errflag
=
0
;
int
c
,
errflag
=
0
;
sa_family_t
master_family
;
sa_family_t
master_family
;
char
**
spp
,
*
master_ifname
,
*
slave_ifname
;
char
**
spp
,
*
master_ifname
,
*
slave_ifname
;
int
hwaddr_notset
;
int
hwaddr_notset
;
int
master_up
;
int
abi_ver
=
0
;
while
((
c
=
getopt_long
(
argc
,
argv
,
"acdfrvV?h"
,
longopts
,
0
))
!=
EOF
)
while
((
c
=
getopt_long
(
argc
,
argv
,
"acdfrvV?h"
,
longopts
,
0
))
!=
EOF
)
switch
(
c
)
{
switch
(
c
)
{
...
@@ -207,6 +257,7 @@ main(int argc, char **argv)
...
@@ -207,6 +257,7 @@ main(int argc, char **argv)
char
**
tempp
=
spp
;
char
**
tempp
=
spp
;
if
((
master_ifname
==
NULL
)
||
(
slave_ifname
==
NULL
)
||
(
*
tempp
++
!=
NULL
))
{
if
((
master_ifname
==
NULL
)
||
(
slave_ifname
==
NULL
)
||
(
*
tempp
++
!=
NULL
))
{
fprintf
(
stderr
,
usage_msg
);
fprintf
(
stderr
,
usage_msg
);
(
void
)
close
(
skfd
);
return
2
;
return
2
;
}
}
}
}
...
@@ -218,6 +269,13 @@ main(int argc, char **argv)
...
@@ -218,6 +269,13 @@ main(int argc, char **argv)
exit
(
0
);
exit
(
0
);
}
}
/* exchange abi version with bonding driver */
abi_ver
=
get_abi_ver
(
master_ifname
);
if
(
abi_ver
<
0
)
{
(
void
)
close
(
skfd
);
exit
(
1
);
}
/* Get the vitals from the master interface. */
/* Get the vitals from the master interface. */
{
{
struct
ifreq
*
ifra
[
7
]
=
{
&
if_ipaddr
,
&
if_mtu
,
&
if_dstaddr
,
struct
ifreq
*
ifra
[
7
]
=
{
&
if_ipaddr
,
&
if_mtu
,
&
if_dstaddr
,
...
@@ -242,6 +300,13 @@ main(int argc, char **argv)
...
@@ -242,6 +300,13 @@ main(int argc, char **argv)
}
}
}
}
/* check if master is up; if not then fail any operation */
if
(
!
(
if_flags
.
ifr_flags
&
IFF_UP
))
{
fprintf
(
stderr
,
"Illegal operation; the specified master interface '%s' is not up.
\n
"
,
master_ifname
);
(
void
)
close
(
skfd
);
exit
(
1
);
}
hwaddr_notset
=
1
;
/* assume master's address not set yet */
hwaddr_notset
=
1
;
/* assume master's address not set yet */
for
(
i
=
0
;
hwaddr_notset
&&
(
i
<
6
);
i
++
)
{
for
(
i
=
0
;
hwaddr_notset
&&
(
i
<
6
);
i
++
)
{
hwaddr_notset
&=
((
unsigned
char
*
)
if_hwaddr
.
ifr_hwaddr
.
sa_data
)[
i
]
==
0
;
hwaddr_notset
&=
((
unsigned
char
*
)
if_hwaddr
.
ifr_hwaddr
.
sa_data
)[
i
]
==
0
;
...
@@ -254,7 +319,7 @@ main(int argc, char **argv)
...
@@ -254,7 +319,7 @@ main(int argc, char **argv)
" with ethernet-like network interfaces.
\n
"
" with ethernet-like network interfaces.
\n
"
" Use the '-f' option to force the operation.
\n
"
,
" Use the '-f' option to force the operation.
\n
"
,
master_ifname
);
master_ifname
);
(
void
)
close
(
skfd
);
exit
(
1
);
exit
(
1
);
}
}
master_family
=
if_hwaddr
.
ifr_hwaddr
.
sa_family
;
master_family
=
if_hwaddr
.
ifr_hwaddr
.
sa_family
;
...
@@ -278,143 +343,153 @@ main(int argc, char **argv)
...
@@ -278,143 +343,153 @@ main(int argc, char **argv)
fprintf
(
stderr
,
"SIOCBONDRELEASE: cannot detach %s from %s. errno=%s.
\n
"
,
fprintf
(
stderr
,
"SIOCBONDRELEASE: cannot detach %s from %s. errno=%s.
\n
"
,
slave_ifname
,
master_ifname
,
strerror
(
errno
));
slave_ifname
,
master_ifname
,
strerror
(
errno
));
}
}
else
{
/* we'll set the interface down to avoid any conflicts due to
else
if
(
abi_ver
<
1
)
{
same IP/MAC */
/* The driver is using an old ABI, so we'll set the interface
* down to avoid any conflicts due to same IP/MAC
*/
strncpy
(
ifr2
.
ifr_name
,
slave_ifname
,
IFNAMSIZ
);
strncpy
(
ifr2
.
ifr_name
,
slave_ifname
,
IFNAMSIZ
);
if
(
ioctl
(
skfd
,
SIOCGIFFLAGS
,
&
ifr2
)
<
0
)
{
if
(
ioctl
(
skfd
,
SIOCGIFFLAGS
,
&
ifr2
)
<
0
)
{
int
saved_errno
=
errno
;
int
saved_errno
=
errno
;
fprintf
(
stderr
,
"SIOCGIFFLAGS on %s failed: %s
\n
"
,
slave_ifname
,
fprintf
(
stderr
,
"SIOCGIFFLAGS on %s failed: %s
\n
"
,
slave_ifname
,
strerror
(
saved_errno
));
strerror
(
saved_errno
));
}
}
else
{
else
{
ifr2
.
ifr_flags
&=
~
(
IFF_UP
|
IFF_RUNNING
);
ifr2
.
ifr_flags
&=
~
(
IFF_UP
|
IFF_RUNNING
);
if
(
ioctl
(
skfd
,
SIOCSIFFLAGS
,
&
ifr2
)
<
0
)
{
if
(
ioctl
(
skfd
,
SIOCSIFFLAGS
,
&
ifr2
)
<
0
)
{
int
saved_errno
=
errno
;
int
saved_errno
=
errno
;
fprintf
(
stderr
,
"Shutting down interface %s failed: %s
\n
"
,
fprintf
(
stderr
,
"Shutting down interface %s failed: %s
\n
"
,
slave_ifname
,
strerror
(
saved_errno
));
slave_ifname
,
strerror
(
saved_errno
));
}
}
}
}
}
}
}
}
else
if
(
opt_c
)
{
/* change primary slave */
else
{
/* attach a slave interface to the master */
strncpy
(
if_flags
.
ifr_name
,
master_ifname
,
IFNAMSIZ
);
/* two possibilities :
strncpy
(
if_flags
.
ifr_slave
,
slave_ifname
,
IFNAMSIZ
);
- if hwaddr_notset, do nothing. The bond will assign the
if
((
ioctl
(
skfd
,
SIOCBONDCHANGEACTIVE
,
&
if_flags
)
<
0
)
&&
hwaddr from its first slave.
(
ioctl
(
skfd
,
BOND_CHANGE_ACTIVE_OLD
,
&
if_flags
)
<
0
))
{
- if !hwaddr_notset, assign the master's hwaddr to each slave
fprintf
(
stderr
,
"SIOCBONDCHANGEACTIVE: %s.
\n
"
,
strerror
(
errno
));
*/
}
}
else
{
/* attach a slave interface to the master */
strncpy
(
ifr2
.
ifr_name
,
slave_ifname
,
IFNAMSIZ
);
strncpy
(
ifr2
.
ifr_name
,
slave_ifname
,
IFNAMSIZ
);
if
(
ioctl
(
skfd
,
SIOCGIFFLAGS
,
&
ifr2
)
<
0
)
{
if
(
ioctl
(
skfd
,
SIOCGIFFLAGS
,
&
ifr2
)
<
0
)
{
int
saved_errno
=
errno
;
int
saved_errno
=
errno
;
fprintf
(
stderr
,
"SIOCGIFFLAGS on %s failed: %s
\n
"
,
slave_ifname
,
fprintf
(
stderr
,
"SIOCGIFFLAGS on %s failed: %s
\n
"
,
slave_ifname
,
strerror
(
saved_errno
));
strerror
(
saved_errno
));
(
void
)
close
(
skfd
);
return
1
;
return
1
;
}
}
if
((
ifr2
.
ifr_flags
&
IFF_SLAVE
)
&&
!
opt_r
)
{
fprintf
(
stderr
,
"%s is already a slave
\n
"
,
slave_ifname
);
(
void
)
close
(
skfd
);
return
1
;
}
/* if hwaddr_notset, assign the slave hw address to the master */
if
(
hwaddr_notset
)
{
if
(
hwaddr_notset
)
{
/* assign the slave hw address to the
/* assign the slave hw address to the
* master since it currently does not
* master since it currently does not
* have one; otherwise, slaves may
* have one; otherwise, slaves may
* have different hw addresses in
* have different hw addresses in
* active-backup mode as seen when enslaving
* active-backup mode as seen when enslaving
* using "ifenslave bond0 eth0 eth1" because
* using "ifenslave bond0 eth0 eth1" because
* hwaddr_notset is set outside this loop.
* hwaddr_notset is set outside this loop.
* TODO: put this and the "else" portion in
* TODO: put this and the "else" portion in
* a function.
* a function.
*/
*/
goterr
=
0
;
/* get the slaves MAC address */
master_up
=
0
;
strncpy
(
if_hwaddr
.
ifr_name
,
slave_ifname
,
if
(
if_flags
.
ifr_flags
&
IFF_UP
)
{
IFNAMSIZ
);
if_flags
.
ifr_flags
&=
~
IFF_UP
;
rv
=
ioctl
(
skfd
,
SIOCGIFHWADDR
,
&
if_hwaddr
);
if
(
ioctl
(
skfd
,
SIOCSIFFLAGS
,
if
(
-
1
==
rv
)
{
&
if_flags
)
<
0
)
{
fprintf
(
stderr
,
"Could not get MAC "
goterr
=
1
;
"address of %s: %s
\n
"
,
fprintf
(
stderr
,
slave_ifname
,
"Shutting down "
strerror
(
errno
));
"interface %s failed: "
strncpy
(
if_hwaddr
.
ifr_name
,
"%s
\n
"
,
master_ifname
,
IFNAMSIZ
);
master_ifname
,
goterr
=
1
;
strerror
(
errno
));
}
else
{
/* we took the master down,
* so we must bring it up
*/
master_up
=
1
;
}
}
}
if
(
!
goterr
)
{
if
(
!
goterr
)
{
/* get the slaves MAC address */
if
(
abi_ver
<
1
)
{
strncpy
(
if_hwaddr
.
ifr_name
,
/* In ABI versions older than 1, the
slave_ifname
,
IFNAMSIZ
);
* master's set_mac routine couldn't
if
(
ioctl
(
skfd
,
SIOCGIFHWADDR
,
* work if it was up, because it
&
if_hwaddr
)
<
0
)
{
* used the default ethernet set_mac
fprintf
(
stderr
,
* function.
"Could not get MAC "
*/
"address of %s: %s
\n
"
,
/* bring master down */
slave_ifname
,
if_flags
.
ifr_flags
&=
~
IFF_UP
;
strerror
(
errno
));
if
(
ioctl
(
skfd
,
SIOCSIFFLAGS
,
strncpy
(
if_hwaddr
.
ifr_name
,
&
if_flags
)
<
0
)
{
master_ifname
,
goterr
=
1
;
IFNAMSIZ
);
fprintf
(
stderr
,
goterr
=
1
;
"Shutting down "
"interface %s failed: "
"%s
\n
"
,
master_ifname
,
strerror
(
errno
));
}
}
}
}
if
(
!
goterr
)
{
strncpy
(
if_hwaddr
.
ifr_name
,
strncpy
(
if_hwaddr
.
ifr_name
,
master_ifname
,
IFNAMSIZ
);
master_ifname
,
IFNAMSIZ
);
if
(
ioctl
(
skfd
,
SIOCSIFHWADDR
,
if
(
ioctl
(
skfd
,
SIOCSIFHWADDR
,
&
if_hwaddr
)
<
0
)
{
&
if_hwaddr
)
<
0
)
{
fprintf
(
stderr
,
fprintf
(
stderr
,
"Could not set MAC "
"Could not set MAC "
"address of %s: %s
\n
"
,
"address of %s: %s
\n
"
,
master_ifname
,
master_ifname
,
strerror
(
errno
));
strerror
(
errno
));
goterr
=
1
;
goterr
=
1
;
}
else
{
}
else
{
hwaddr_notset
=
0
;
hwaddr_notset
=
0
;
}
}
}
if
(
master_up
)
{
if
(
abi_ver
<
1
)
{
if_flags
.
ifr_flags
|=
IFF_UP
;
/* bring master back up */
if
(
ioctl
(
skfd
,
SIOCSIFFLAGS
,
if_flags
.
ifr_flags
|=
IFF_UP
;
&
if_flags
)
<
0
)
{
if
(
ioctl
(
skfd
,
SIOCSIFFLAGS
,
fprintf
(
stderr
,
&
if_flags
)
<
0
)
{
"Bringing up interface "
fprintf
(
stderr
,
"%s failed: %s
\n
"
,
"Bringing up interface "
master_ifname
,
"%s failed: %s
\n
"
,
strerror
(
errno
));
master_ifname
,
strerror
(
errno
));
}
}
}
}
}
}
else
if
(
abi_ver
<
1
)
{
/* if (hwaddr_notset) */
}
else
{
/* The driver is using an old ABI, so we'll set the interface
/* we'll assign master's hwaddr to this slave */
* down and assign the master's hwaddr to it
*/
if
(
ifr2
.
ifr_flags
&
IFF_UP
)
{
if
(
ifr2
.
ifr_flags
&
IFF_UP
)
{
ifr2
.
ifr_flags
&=
~
IFF_UP
;
ifr2
.
ifr_flags
&=
~
IFF_UP
;
if
(
ioctl
(
skfd
,
SIOCSIFFLAGS
,
&
ifr2
)
<
0
)
{
if
(
ioctl
(
skfd
,
SIOCSIFFLAGS
,
&
ifr2
)
<
0
)
{
int
saved_errno
=
errno
;
int
saved_errno
=
errno
;
fprintf
(
stderr
,
"Shutting down interface %s failed: %s
\n
"
,
fprintf
(
stderr
,
"Shutting down interface %s failed: %s
\n
"
,
slave_ifname
,
strerror
(
saved_errno
));
slave_ifname
,
strerror
(
saved_errno
));
}
}
}
}
strncpy
(
if_hwaddr
.
ifr_name
,
slave_ifname
,
IFNAMSIZ
);
strncpy
(
if_hwaddr
.
ifr_name
,
slave_ifname
,
IFNAMSIZ
);
if
(
ioctl
(
skfd
,
SIOCSIFHWADDR
,
&
if_hwaddr
)
<
0
)
{
if
(
ioctl
(
skfd
,
SIOCSIFHWADDR
,
&
if_hwaddr
)
<
0
)
{
int
saved_errno
=
errno
;
int
saved_errno
=
errno
;
fprintf
(
stderr
,
"SIOCSIFHWADDR on %s failed: %s
\n
"
,
if_hwaddr
.
ifr_name
,
fprintf
(
stderr
,
"SIOCSIFHWADDR on %s failed: %s
\n
"
,
if_hwaddr
.
ifr_name
,
strerror
(
saved_errno
));
strerror
(
saved_errno
));
if
(
saved_errno
==
EBUSY
)
if
(
saved_errno
==
EBUSY
)
fprintf
(
stderr
,
" The slave device %s is busy: it must be"
fprintf
(
stderr
,
" The slave device %s is busy: it must be"
" idle before running this command.
\n
"
,
slave_ifname
);
" idle before running this command.
\n
"
,
slave_ifname
);
else
if
(
saved_errno
==
EOPNOTSUPP
)
else
if
(
saved_errno
==
EOPNOTSUPP
)
fprintf
(
stderr
,
" The slave device you specified does not support"
fprintf
(
stderr
,
" The slave device you specified does not support"
" setting the MAC address.
\n
Your kernel likely does not"
" setting the MAC address.
\n
Your kernel likely does not"
" support slave devices.
\n
"
);
" support slave devices.
\n
"
);
else
if
(
saved_errno
==
EINVAL
)
else
if
(
saved_errno
==
EINVAL
)
fprintf
(
stderr
,
" The slave device's address type does not match"
fprintf
(
stderr
,
" The slave device's address type does not match"
" the master's address type.
\n
"
);
" the master's address type.
\n
"
);
}
else
{
}
else
{
if
(
verbose
)
{
if
(
verbose
)
{
unsigned
char
*
hwaddr
=
if_hwaddr
.
ifr_hwaddr
.
sa_data
;
unsigned
char
*
hwaddr
=
if_hwaddr
.
ifr_hwaddr
.
sa_data
;
...
@@ -424,10 +499,11 @@ main(int argc, char **argv)
...
@@ -424,10 +499,11 @@ main(int argc, char **argv)
}
}
}
}
}
}
if
(
*
spp
&&
!
strcmp
(
*
spp
,
"metric"
))
{
if
(
*
spp
&&
!
strcmp
(
*
spp
,
"metric"
))
{
if
(
*++
spp
==
NULL
)
{
if
(
*++
spp
==
NULL
)
{
fprintf
(
stderr
,
usage_msg
);
fprintf
(
stderr
,
usage_msg
);
(
void
)
close
(
skfd
);
exit
(
2
);
exit
(
2
);
}
}
if_metric
.
ifr_metric
=
atoi
(
*
spp
);
if_metric
.
ifr_metric
=
atoi
(
*
spp
);
...
@@ -439,7 +515,7 @@ main(int argc, char **argv)
...
@@ -439,7 +515,7 @@ main(int argc, char **argv)
}
}
spp
++
;
spp
++
;
}
}
if
(
strncpy
(
if_ipaddr
.
ifr_name
,
slave_ifname
,
IFNAMSIZ
)
<=
0
if
(
strncpy
(
if_ipaddr
.
ifr_name
,
slave_ifname
,
IFNAMSIZ
)
<=
0
||
ioctl
(
skfd
,
SIOCSIFADDR
,
&
if_ipaddr
)
<
0
)
{
||
ioctl
(
skfd
,
SIOCSIFADDR
,
&
if_ipaddr
)
<
0
)
{
fprintf
(
stderr
,
fprintf
(
stderr
,
...
@@ -452,16 +528,16 @@ main(int argc, char **argv)
...
@@ -452,16 +528,16 @@ main(int argc, char **argv)
slave_ifname
,
ipaddr
[
0
],
ipaddr
[
1
],
ipaddr
[
2
],
ipaddr
[
3
]);
slave_ifname
,
ipaddr
[
0
],
ipaddr
[
1
],
ipaddr
[
2
],
ipaddr
[
3
]);
}
}
}
}
if
(
strncpy
(
if_mtu
.
ifr_name
,
slave_ifname
,
IFNAMSIZ
)
<=
0
if
(
strncpy
(
if_mtu
.
ifr_name
,
slave_ifname
,
IFNAMSIZ
)
<=
0
||
ioctl
(
skfd
,
SIOCSIFMTU
,
&
if_mtu
)
<
0
)
{
||
ioctl
(
skfd
,
SIOCSIFMTU
,
&
if_mtu
)
<
0
)
{
fprintf
(
stderr
,
"Something broke setting the slave MTU: %s.
\n
"
,
fprintf
(
stderr
,
"Something broke setting the slave MTU: %s.
\n
"
,
strerror
(
errno
));
strerror
(
errno
));
}
else
{
}
else
{
if
(
verbose
)
if
(
verbose
)
printf
(
"Set the slave's (%s) MTU to %d.
\n
"
,
slave_ifname
,
if_mtu
.
ifr_mtu
);
printf
(
"Set the slave's (%s) MTU to %d.
\n
"
,
slave_ifname
,
if_mtu
.
ifr_mtu
);
}
}
if
(
strncpy
(
if_dstaddr
.
ifr_name
,
slave_ifname
,
IFNAMSIZ
)
<=
0
if
(
strncpy
(
if_dstaddr
.
ifr_name
,
slave_ifname
,
IFNAMSIZ
)
<=
0
||
ioctl
(
skfd
,
SIOCSIFDSTADDR
,
&
if_dstaddr
)
<
0
)
{
||
ioctl
(
skfd
,
SIOCSIFDSTADDR
,
&
if_dstaddr
)
<
0
)
{
fprintf
(
stderr
,
"Error setting the slave (%s) with SIOCSIFDSTADDR: %s.
\n
"
,
fprintf
(
stderr
,
"Error setting the slave (%s) with SIOCSIFDSTADDR: %s.
\n
"
,
...
@@ -473,7 +549,7 @@ main(int argc, char **argv)
...
@@ -473,7 +549,7 @@ main(int argc, char **argv)
slave_ifname
,
ipaddr
[
0
],
ipaddr
[
1
],
ipaddr
[
2
],
ipaddr
[
3
]);
slave_ifname
,
ipaddr
[
0
],
ipaddr
[
1
],
ipaddr
[
2
],
ipaddr
[
3
]);
}
}
}
}
if
(
strncpy
(
if_brdaddr
.
ifr_name
,
slave_ifname
,
IFNAMSIZ
)
<=
0
if
(
strncpy
(
if_brdaddr
.
ifr_name
,
slave_ifname
,
IFNAMSIZ
)
<=
0
||
ioctl
(
skfd
,
SIOCSIFBRDADDR
,
&
if_brdaddr
)
<
0
)
{
||
ioctl
(
skfd
,
SIOCSIFBRDADDR
,
&
if_brdaddr
)
<
0
)
{
fprintf
(
stderr
,
fprintf
(
stderr
,
...
@@ -486,7 +562,7 @@ main(int argc, char **argv)
...
@@ -486,7 +562,7 @@ main(int argc, char **argv)
slave_ifname
,
ipaddr
[
0
],
ipaddr
[
1
],
ipaddr
[
2
],
ipaddr
[
3
]);
slave_ifname
,
ipaddr
[
0
],
ipaddr
[
1
],
ipaddr
[
2
],
ipaddr
[
3
]);
}
}
}
}
if
(
strncpy
(
if_netmask
.
ifr_name
,
slave_ifname
,
IFNAMSIZ
)
<=
0
if
(
strncpy
(
if_netmask
.
ifr_name
,
slave_ifname
,
IFNAMSIZ
)
<=
0
||
ioctl
(
skfd
,
SIOCSIFNETMASK
,
&
if_netmask
)
<
0
)
{
||
ioctl
(
skfd
,
SIOCSIFNETMASK
,
&
if_netmask
)
<
0
)
{
fprintf
(
stderr
,
fprintf
(
stderr
,
...
@@ -499,34 +575,45 @@ main(int argc, char **argv)
...
@@ -499,34 +575,45 @@ main(int argc, char **argv)
slave_ifname
,
ipaddr
[
0
],
ipaddr
[
1
],
ipaddr
[
2
],
ipaddr
[
3
]);
slave_ifname
,
ipaddr
[
0
],
ipaddr
[
1
],
ipaddr
[
2
],
ipaddr
[
3
]);
}
}
}
}
ifr2
.
ifr_flags
|=
IFF_UP
;
/* the interface will need to be up to be bonded */
if
(
abi_ver
<
1
)
{
if
((
ifr2
.
ifr_flags
&=
~
(
IFF_SLAVE
|
IFF_MASTER
))
==
0
||
strncpy
(
ifr2
.
ifr_name
,
slave_ifname
,
IFNAMSIZ
)
<=
0
/* The driver is using an old ABI, so we'll set the interface
||
ioctl
(
skfd
,
SIOCSIFFLAGS
,
&
ifr2
)
<
0
)
{
* up before enslaving it
fprintf
(
stderr
,
*/
"Something broke setting the slave (%s) flags: %s.
\n
"
,
ifr2
.
ifr_flags
|=
IFF_UP
;
slave_ifname
,
strerror
(
errno
));
if
((
ifr2
.
ifr_flags
&=
~
(
IFF_SLAVE
|
IFF_MASTER
))
==
0
||
strncpy
(
ifr2
.
ifr_name
,
slave_ifname
,
IFNAMSIZ
)
<=
0
||
ioctl
(
skfd
,
SIOCSIFFLAGS
,
&
ifr2
)
<
0
)
{
fprintf
(
stderr
,
"Something broke setting the slave (%s) flags: %s.
\n
"
,
slave_ifname
,
strerror
(
errno
));
}
else
{
if
(
verbose
)
printf
(
"Set the slave's (%s) flags %4.4x.
\n
"
,
slave_ifname
,
if_flags
.
ifr_flags
);
}
}
else
{
}
else
{
if
(
verbose
)
/* the bonding module takes care of setting the slave's mac address
printf
(
"Set the slave's (%s) flags %4.4x.
\n
"
,
slave_ifname
,
if_flags
.
ifr_flags
);
* and opening its interface
*/
if
(
ifr2
.
ifr_flags
&
IFF_UP
)
{
/* the interface will need to be down */
ifr2
.
ifr_flags
&=
~
IFF_UP
;
if
(
ioctl
(
skfd
,
SIOCSIFFLAGS
,
&
ifr2
)
<
0
)
{
int
saved_errno
=
errno
;
fprintf
(
stderr
,
"Shutting down interface %s failed: %s
\n
"
,
slave_ifname
,
strerror
(
saved_errno
));
}
}
}
}
/* Do the real thing */
/* Do the real thing */
if
(
!
opt_r
)
{
if
(
!
opt_r
)
{
strncpy
(
if_flags
.
ifr_name
,
master_ifname
,
IFNAMSIZ
);
strncpy
(
if_flags
.
ifr_name
,
master_ifname
,
IFNAMSIZ
);
strncpy
(
if_flags
.
ifr_slave
,
slave_ifname
,
IFNAMSIZ
);
strncpy
(
if_flags
.
ifr_slave
,
slave_ifname
,
IFNAMSIZ
);
if
(
!
opt_c
)
{
if
((
ioctl
(
skfd
,
SIOCBONDENSLAVE
,
&
if_flags
)
<
0
)
&&
if
((
ioctl
(
skfd
,
SIOCBONDENSLAVE
,
&
if_flags
)
<
0
)
&&
(
ioctl
(
skfd
,
BOND_ENSLAVE_OLD
,
&
if_flags
)
<
0
))
{
(
ioctl
(
skfd
,
BOND_ENSLAVE_OLD
,
&
if_flags
)
<
0
))
{
fprintf
(
stderr
,
"SIOCBONDENSLAVE: %s.
\n
"
,
strerror
(
errno
));
fprintf
(
stderr
,
"SIOCBONDENSLAVE: %s.
\n
"
,
strerror
(
errno
));
}
}
else
{
if
((
ioctl
(
skfd
,
SIOCBONDCHANGEACTIVE
,
&
if_flags
)
<
0
)
&&
(
ioctl
(
skfd
,
BOND_CHANGE_ACTIVE_OLD
,
&
if_flags
)
<
0
))
{
fprintf
(
stderr
,
"SIOCBONDCHANGEACTIVE: %s.
\n
"
,
strerror
(
errno
));
}
}
}
}
}
}
}
...
@@ -540,7 +627,7 @@ main(int argc, char **argv)
...
@@ -540,7 +627,7 @@ main(int argc, char **argv)
static
short
mif_flags
;
static
short
mif_flags
;
/* Get the inte
r
face configuration from the kernel. */
/* Get the inteface configuration from the kernel. */
static
int
if_getconfig
(
char
*
ifname
)
static
int
if_getconfig
(
char
*
ifname
)
{
{
struct
ifreq
ifr
;
struct
ifreq
ifr
;
...
@@ -639,7 +726,38 @@ static void if_print(char *ifname)
...
@@ -639,7 +726,38 @@ static void if_print(char *ifname)
}
}
}
}
static
int
get_abi_ver
(
char
*
master_ifname
)
{
struct
ifreq
ifr
;
struct
ethtool_drvinfo
info
;
int
abi_ver
=
0
;
memset
(
&
ifr
,
0
,
sizeof
(
ifr
));
strncpy
(
ifr
.
ifr_name
,
master_ifname
,
IFNAMSIZ
);
ifr
.
ifr_data
=
(
caddr_t
)
&
info
;
info
.
cmd
=
ETHTOOL_GDRVINFO
;
strncpy
(
info
.
driver
,
"ifenslave"
,
32
);
snprintf
(
info
.
fw_version
,
32
,
"%d"
,
BOND_ABI_VERSION
);
if
(
ioctl
(
skfd
,
SIOCETHTOOL
,
&
ifr
)
>=
0
)
{
char
*
endptr
;
abi_ver
=
strtoul
(
info
.
fw_version
,
&
endptr
,
0
);
if
(
*
endptr
)
{
fprintf
(
stderr
,
"Error: got invalid string as an ABI "
"version from the bonding module
\n
"
);
return
-
1
;
}
}
if
(
verbose
)
{
printf
(
"ABI ver is %d
\n
"
,
abi_ver
);
}
return
abi_ver
;
}
/*
/*
* Local variables:
* Local variables:
* version-control: t
* version-control: t
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment