[netcf-devel] [PATCH] Implement ncf_if_status()

Laine Stump laine at laine.org
Mon Oct 26 17:28:06 UTC 2009


New version. This one reuses an existing enum (netcf_if_flag_t) rather
than creating a new enum. Also, the API passes the flags as unsigned
int* rather than an enum.

ncf_if_status returns various status bits about the given interface,
as described in the definition of the enum type
netcf_if_flag_t. Currently that defines two bits:

       NETCF_IFACE_INACTIVE
       NETCF_IFACE_ACTIVE

If the interface is currently up (active), NETCF_IFACE_ACTIVE is set,
otherwise NETCF_IFACE_INACTIVE is set. By definition, one or the other
of these bits will always be set (unless an error is encountered),
never both, so you can safely just check one of them.

The value of all other bits should be considered random by an
application program, as later versions of netcf may use them. In other
words, you should always mask out all the other bits when checking.
---
 src/drv_initscripts.c |   18 ++++++++++++++++++
 src/internal.h        |    1 +
 src/netcf.c           |    8 ++++++++
 src/netcf.h           |    6 ++++++
 src/netcf_public.syms |    5 +++++
 5 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/src/drv_initscripts.c b/src/drv_initscripts.c
index 6d03baa..8e082b6 100644
--- a/src/drv_initscripts.c
+++ b/src/drv_initscripts.c
@@ -807,6 +807,24 @@ char *drv_xml_state(struct netcf_if *nif) {
     goto done;
 }
 
+/* Report various status info about the interface as bits in
+ * "flags". Returns 0 on success, -1 on failure
+ */
+int drv_if_status(struct netcf_if *nif, unsigned int *flags) {
+    int is_active;
+
+    ERR_THROW(flags == NULL, nif->ncf, EOTHER, "NULL pointer for flags in ncf_if_status");
+    *flags = 0;
+    is_active = if_is_active(nif->ncf, nif->name);
+    if (is_active)
+        *flags |= NETCF_IFACE_ACTIVE;
+    else
+        *flags |= NETCF_IFACE_INACTIVE;
+    return 0;
+error:
+    return -1;
+}
+
 /* Get the content of /interface/@name. Result must be freed with xmlFree()
  *
  * The name on VLAN interfaces is optional; if there is no
diff --git a/src/internal.h b/src/internal.h
index ca9a0ef..d06665d 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -180,6 +180,7 @@ int drv_lookup_by_mac_string(struct netcf *, const char *mac,
                              int maxifaces, struct netcf_if **ifaces);
 char *drv_xml_desc(struct netcf_if *);
 char *drv_xml_state(struct netcf_if *);
+int drv_if_status(struct netcf_if *nif, unsigned int *flags);
 const char *drv_mac_string(struct netcf_if *nif);
 struct netcf_if *drv_define(struct netcf *ncf, const char *xml);
 int drv_undefine(struct netcf_if *nif);
diff --git a/src/netcf.c b/src/netcf.c
index 1cd7aed..7c4969b 100644
--- a/src/netcf.c
+++ b/src/netcf.c
@@ -212,6 +212,14 @@ char *ncf_if_xml_state(struct netcf_if *nif) {
     return drv_xml_state(nif);
 }
 
+/* Report various status info about the interface as bits in
+ * "flags". Returns 0 on success, -1 on failure
+ */
+int ncf_if_status(struct netcf_if *nif, unsigned int *flags) {
+    API_ENTRY(nif->ncf);
+    return drv_if_status(nif, flags);
+}
+
 /* Release any resources used by this NETCF_IF; the pointer is invalid
  * after this call
  */
diff --git a/src/netcf.h b/src/netcf.h
index a8619f5..bf5e4e2 100644
--- a/src/netcf.h
+++ b/src/netcf.h
@@ -163,6 +163,12 @@ char *ncf_if_xml_desc(struct netcf_if *);
  */
 char *ncf_if_xml_state(struct netcf_if *);
 
+/* Report various status info about the interface as bits in
+ * "flags". The meaning of the bits is in the enum type netcf_if_flag_t.
+ * Returns 0 on success, -1 on failure
+ */
+int ncf_if_status(struct netcf_if *nif, unsigned int *flags);
+
 /* Release any resources used by this NETCF_IF; the pointer is invalid
  * after this call
  */
diff --git a/src/netcf_public.syms b/src/netcf_public.syms
index 61464a5..9180614 100644
--- a/src/netcf_public.syms
+++ b/src/netcf_public.syms
@@ -23,3 +23,8 @@ NETCF_1.2.0 {
     global:
       ncf_if_xml_state;
 } NETCF_1.0.0;
+
+NETCF_1.3.0 {
+    global:
+      ncf_if_status;
+} NETCF_1.2.0;
-- 
1.6.5.15.gc274d



More information about the netcf-devel mailing list