[PATCH] Avoid to define a IF which's name exceeds the maximum length.
by jmiao
drv_define() doesn't check the length of IF's name, so the IF's name
may be trancated to maxium length(IFNAMSIZ - 1).
Signed-off-by: jmiao <jmiao(a)redhat.com>
---
AUTHORS | 3 ++-
src/drv_debian.c | 3 +++
src/drv_redhat.c | 3 +++
src/drv_suse.c | 3 +++
4 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/AUTHORS b/AUTHORS
index 6188570..bee6abe 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -21,4 +21,5 @@ Contributions by:
Hendrik Schwartke <hendrik(a)os-t.de>
Ting Liu <b28495(a)freescale.com>
Satoru SATOH <ssato(a)redhat.com>
- Martin Wilck <martin.wilck(a)ts.fujitsu.com>
\ No newline at end of file
+ Martin Wilck <martin.wilck(a)ts.fujitsu.com>
+ Jincheng Miao <jmiao(a)redhat.com>
diff --git a/src/drv_debian.c b/src/drv_debian.c
index def0c0e..342777c 100644
--- a/src/drv_debian.c
+++ b/src/drv_debian.c
@@ -925,6 +925,9 @@ struct netcf_if *drv_define(struct netcf *ncf, const char *xml_str) {
name = device_name_from_xml(ncf, ncf_xml);
ERR_COND_BAIL(name == NULL, ncf, EINTERNAL);
+ ERR_THROW(strlen(name) >= IFNAMSIZ, ncf, EINTERNAL,
+ "The interface name '%s' exceeds the maximum length: %d",
+ name, IFNAMSIZ - 1);
rm_all_interfaces(ncf, ncf_xml);
ERR_BAIL(ncf);
diff --git a/src/drv_redhat.c b/src/drv_redhat.c
index 3697473..c40d7fb 100644
--- a/src/drv_redhat.c
+++ b/src/drv_redhat.c
@@ -878,6 +878,9 @@ struct netcf_if *drv_define(struct netcf *ncf, const char *xml_str) {
name = device_name_from_xml(ncf, ncf_xml);
ERR_COND_BAIL(name == NULL, ncf, EINTERNAL);
+ ERR_THROW(strlen(name) >= IFNAMSIZ, ncf, EINTERNAL,
+ "The interface name '%s' exceeds the maximum length: %d",
+ name, IFNAMSIZ - 1);
rm_all_interfaces(ncf, ncf_xml);
ERR_BAIL(ncf);
diff --git a/src/drv_suse.c b/src/drv_suse.c
index 666d802..782d366 100644
--- a/src/drv_suse.c
+++ b/src/drv_suse.c
@@ -1020,6 +1020,9 @@ struct netcf_if *drv_define(struct netcf *ncf, const char *xml_str) {
name = device_name_from_xml(ncf, ncf_xml);
ERR_COND_BAIL(name == NULL, ncf, EINTERNAL);
+ ERR_THROW(strlen(name) >= IFNAMSIZ, ncf, EINTERNAL,
+ "The interface name '%s' exceeds the maximum length: %d",
+ name, IFNAMSIZ - 1);
rm_all_interfaces(ncf, ncf_xml);
ERR_BAIL(ncf);
--
1.8.2.1
9 years, 11 months
[PATCH] fix wrong status of bridge devices
by Hendrik Schwartke
The IFF_RUNNING flag is not set on a bridge device if there are no
devices attached to it. So bridges without attached devices are reported
as inactive. Destroying inactive devices leads to an error and thus the
device can't be removed (easily) from the operating system.
This patch checks if the device is a bridge and if so ignores the IFF_RUNNING
flag.
---
src/dutil_linux.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/dutil_linux.c b/src/dutil_linux.c
index 7af741e..2db166a 100644
--- a/src/dutil_linux.c
+++ b/src/dutil_linux.c
@@ -456,6 +456,15 @@ void modprobed_unalias_bond(struct netcf *ncf, const char *name) {
int if_is_active(struct netcf *ncf, const char *intf) {
struct ifreq ifr;
+ short flags_to_check = IFF_UP;
+
+ /*
+ * IFF_RUNNING is set on a bridge only if there is at least one
+ * network device attached.
+ */
+ if(if_type(ncf, intf) != NETCF_IFACE_TYPE_BRIDGE) {
+ flags_to_check |= IFF_RUNNING;
+ }
MEMZERO(&ifr, 1);
strncpy(ifr.ifr_name, intf, sizeof(ifr.ifr_name));
@@ -463,7 +472,7 @@ int if_is_active(struct netcf *ncf, const char *intf) {
if (ioctl(ncf->driver->ioctl_fd, SIOCGIFFLAGS, &ifr)) {
return 0;
}
- return ((ifr.ifr_flags & (IFF_UP|IFF_RUNNING)) == (IFF_UP|IFF_RUNNING));
+ return ((ifr.ifr_flags & flags_to_check) == flags_to_check);
}
netcf_if_type_t if_type(struct netcf *ncf, const char *intf) {
--
1.9.1
9 years, 11 months