Misc. small bugfixes
by David Lutterkort
These patches address a few problems that Dan Berrange spotted.
David
14 years, 7 months
[PATCH] Fix interface listing.
by Laine Stump
Count errors during SIOCGIFFLAGS as "down"; treating them as errors
was causing us to fail at listing interfaces when an interface early
in the list failed is_active (which uses SIOCGIFFLAGS).
This also pointed out that we were missing some ERR_BAILs - even
though if_is_active threw an error, we were continuing rather than
aborting.
---
src/drv_initscripts.c | 2 ++
src/dutil.c | 1 -
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/src/drv_initscripts.c b/src/drv_initscripts.c
index 8e36fab..d3927f7 100644
--- a/src/drv_initscripts.c
+++ b/src/drv_initscripts.c
@@ -527,12 +527,14 @@ static int list_interface_ids(struct netcf *ncf,
aug = get_augeas(ncf);
ERR_BAIL(ncf);
nint = list_interfaces(ncf, &intf);
+ ERR_BAIL(ncf);
if (!names) {
maxnames = nint; /* if not returning list, ignore maxnames too */
}
for (result = 0; (result < nint) && (nqualified < maxnames); result++) {
nmatches = aug_fmt_match(ncf, &matches,
"%s/%s", intf[result], id_attr);
+ ERR_BAIL(ncf);
if (nmatches > 0) {
const char *name;
int is_qualified = ((flags & (NETCF_IFACE_ACTIVE|NETCF_IFACE_INACTIVE))
diff --git a/src/dutil.c b/src/dutil.c
index 817ec6d..8604e1f 100644
--- a/src/dutil.c
+++ b/src/dutil.c
@@ -439,7 +439,6 @@ int if_is_active(struct netcf *ncf, const char *intf) {
strncpy(ifr.ifr_name, intf, sizeof(ifr.ifr_name));
ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
if (ioctl(ncf->driver->ioctl_fd, SIOCGIFFLAGS, &ifr)) {
- report_error(ncf, NETCF_EIOCTL, "Failed to get interface flags for %s", intf);
return 0;
}
return ((ifr.ifr_flags & IFF_UP) == IFF_UP);
--
1.6.2.5
14 years, 7 months
[PATCH] Detect and report live interface type.
by Laine Stump
Poke around in sysfs and procfs to determine the type of an interface,
and set the "type" attribute in the xml appropriately. If no clue is
found, default to "ethernet", which is the current behavior elsewhere
in netcf as well.
---
src/drv_initscripts.c | 3 +++
src/dutil.c | 33 +++++++++++++++++++++++++++++++++
src/dutil.h | 5 +++++
3 files changed, 41 insertions(+), 0 deletions(-)
diff --git a/src/drv_initscripts.c b/src/drv_initscripts.c
index 8e36fab..ead5b9f 100644
--- a/src/drv_initscripts.c
+++ b/src/drv_initscripts.c
@@ -775,6 +775,9 @@ char *drv_xml_state(struct netcf_if *nif) {
prop = xmlNewProp(root, BAD_CAST "name", BAD_CAST nif->name);
ERR_NOMEM(prop == NULL, ncf);
+ prop = xmlSetProp(root, BAD_CAST "type", BAD_CAST if_type(ncf, nif->name));
+ ERR_NOMEM(prop == NULL, ncf);
+
/* get the current IP address and prefix, and add both to the
* document.
*/
diff --git a/src/dutil.c b/src/dutil.c
index 817ec6d..9c8e575 100644
--- a/src/dutil.c
+++ b/src/dutil.c
@@ -499,6 +499,39 @@ int if_ipv4_prefix(struct netcf *ncf, const char *intf) {
return prefix;
}
+const char *if_type(struct netcf *ncf, const char *intf) {
+ char *path;
+ struct stat stats;
+ const char *ret = NULL;
+
+ xasprintf(&path, "/proc/net/vlan/%s", intf);
+ ERR_NOMEM(path == NULL, ncf);
+ if ((stat (path, &stats) == 0) && S_ISREG (stats.st_mode)) {
+ ret = "vlan";
+ }
+ FREE(path);
+
+ if (ret == NULL) {
+ xasprintf(&path, "/sys/class/net/%s/bridge", intf);
+ ERR_NOMEM(path == NULL, ncf);
+ if (stat (path, &stats) == 0 && S_ISDIR (stats.st_mode))
+ return "bridge";
+ FREE(path);
+ }
+ if (ret == NULL) {
+ xasprintf(&path, "/sys/class/net/%s/bonding", intf);
+ ERR_NOMEM(path == NULL, ncf);
+ if (stat (path, &stats) == 0 && S_ISDIR (stats.st_mode))
+ return "bond";
+ FREE(path);
+ }
+
+error:
+ if (ret == NULL)
+ ret = "ethernet";
+ return ret;
+}
+
/* Create a new netcf if instance for interface NAME */
struct netcf_if *make_netcf_if(struct netcf *ncf, char *name) {
int r;
diff --git a/src/dutil.h b/src/dutil.h
index 0a9715f..74d0023 100644
--- a/src/dutil.h
+++ b/src/dutil.h
@@ -123,6 +123,11 @@ unsigned int if_ipv4_netmask(struct netcf *ncf, const char *intf);
int if_ipv4_prefix(struct netcf *ncf, const char *intf);
+/* return the type of the interface - "ethernet" (physical device),
+ * "bridge", "bond", or "vlan"
+ */
+const char *if_type(struct netcf *ncf, const char *intf);
+
/* Create a new netcf if instance for interface NAME */
struct netcf_if *make_netcf_if(struct netcf *ncf, char *name);
--
1.6.2.5
14 years, 7 months
[PATCH 0/2] simpler ncf_if_xml_state
by Laine Stump
This is the result of discussion yesterday on libvirt list about
whether ncf_if_xml_state should return live + config data and add an
extra attribute to the live data, or return *only* live data. It looks
like we can all agree on the scheme of returning only live data, so
here's a patch that implements that. It's based on the current head of
master (ie it supercedes the patch series I sent on 9/29)
14 years, 7 months
feature request: control host-wide configuration
by Dan Kenigsberg
I've been bitten by letting users set GATEWAY per interface.
It may sometimes be useful, but it mostly opens the door for a lot of
mess, as only one "random" GATEWAY gets used.
What I should have really done is let users control the system-wide
GATEWAY, sitting in (initscript's) /etc/sysconfig/network. Other
system-wide config may be useful too.
It does not seem that netcf can do that in its interface-centric API. Do
you agree that it should?
Dan.
14 years, 7 months
[PATCH] schema: allow ipv4 and ipv6 addresses in any order
by David Lutterkort
---
data/xml/interface.rng | 108 ++++++++++++++++++++++++++---------------------
1 files changed, 60 insertions(+), 48 deletions(-)
diff --git a/data/xml/interface.rng b/data/xml/interface.rng
index 8393c17..a6193f8 100644
--- a/data/xml/interface.rng
+++ b/data/xml/interface.rng
@@ -271,63 +271,75 @@
different protocols
-->
<define name="interface-addressing">
- <optional>
- <element name="protocol">
- <ref name="protocol-ipv4"/>
- </element>
- </optional>
- <optional v:since="3">
- <element name="protocol">
- <ref name="protocol-ipv6"/>
- </element>
- </optional>
- </define>
-
- <define name="protocol-ipv4">
- <attribute name="family">
- <value>ipv4</value>
- </attribute>
<choice>
- <ref name="dhcp-element"/>
<group>
- <element name="ip">
- <attribute name="address"><ref name="ipv4-addr"/></attribute>
- <optional>
- <attribute name="prefix"><ref name="ipv4-prefix"/></attribute>
- </optional>
- </element>
<optional>
- <element name="route">
- <attribute name="gateway"><ref name="ipv4-addr"/></attribute>
- </element>
+ <ref name="protocol-ipv4"/>
+ </optional>
+ <optional v:since="3">
+ <ref name="protocol-ipv6"/>
+ </optional>
+ </group>
+ <group>
+ <optional v:since="3">
+ <ref name="protocol-ipv6"/>
+ </optional>
+ <optional>
+ <ref name="protocol-ipv4"/>
</optional>
</group>
</choice>
</define>
+ <define name="protocol-ipv4">
+ <element name="protocol">
+ <attribute name="family">
+ <value>ipv4</value>
+ </attribute>
+ <choice>
+ <ref name="dhcp-element"/>
+ <group>
+ <element name="ip">
+ <attribute name="address"><ref name="ipv4-addr"/></attribute>
+ <optional>
+ <attribute name="prefix"><ref name="ipv4-prefix"/></attribute>
+ </optional>
+ </element>
+ <optional>
+ <element name="route">
+ <attribute name="gateway"><ref name="ipv4-addr"/></attribute>
+ </element>
+ </optional>
+ </group>
+ </choice>
+ </element>
+ </define>
+
<define name="protocol-ipv6">
- <attribute name="family">
- <value>ipv6</value>
- </attribute>
- <optional>
- <element name="autoconf"><empty/></element>
- </optional>
- <optional>
- <ref name="dhcp-element"/>
- </optional>
- <zeroOrMore>
- <element name="ip">
- <attribute name="address"><ref name="ipv6-addr"/></attribute>
- <optional>
- <attribute name="prefix"><ref name="ipv6-prefix"/></attribute>
- </optional>
- </element>
- </zeroOrMore>
- <optional>
- <element name="route">
- <attribute name="gateway"><ref name="ipv6-addr"/></attribute>
- </element>
- </optional>
+ <element name="protocol">
+ <attribute name="family">
+ <value>ipv6</value>
+ </attribute>
+ <optional>
+ <element name="autoconf"><empty/></element>
+ </optional>
+ <optional>
+ <ref name="dhcp-element"/>
+ </optional>
+ <zeroOrMore>
+ <element name="ip">
+ <attribute name="address"><ref name="ipv6-addr"/></attribute>
+ <optional>
+ <attribute name="prefix"><ref name="ipv6-prefix"/></attribute>
+ </optional>
+ </element>
+ </zeroOrMore>
+ <optional>
+ <element name="route">
+ <attribute name="gateway"><ref name="ipv6-addr"/></attribute>
+ </element>
+ </optional>
+ </element>
</define>
<define name="dhcp-element">
--
1.6.2.5
14 years, 7 months