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

Laine Stump laine at laine.org
Fri Oct 23 14:34:54 UTC 2009


A couple of questions on this topic:

1) I didn't add anything to ncftool that exercises this new 
functionality.  Do you see any use to this? (The information is given 
implicitly by "list").

2) Would it be useful to also add this information to the xml of 
ncf_if_xml_state()? If so, any suggestions on what it should look like?

On 10/22/2009 05:37 PM, Laine Stump wrote:
> Here's a first draft of a suggested new API, subject to change based
> on comments.
>
> ncf_if_status returns various status bits about the given interface. As a
> start, only a single bit is defined:
>
>         NETCF_IFACE_STATUS_UP
>
> This bit is set if the interface is currently up (active) and not set if it
> is currently down (inactive).
>
> 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.
> ---
>   src/drv_initscripts.c |   16 ++++++++++++++++
>   src/internal.h        |    1 +
>   src/netcf.c           |    8 ++++++++
>   src/netcf.h           |    9 +++++++++
>   src/netcf_public.syms |    5 +++++
>   5 files changed, 39 insertions(+), 0 deletions(-)
>
> diff --git a/src/drv_initscripts.c b/src/drv_initscripts.c
> index 6d03baa..17fad00 100644
> --- a/src/drv_initscripts.c
> +++ b/src/drv_initscripts.c
> @@ -807,6 +807,22 @@ 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, ncf_if_status_flags *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_STATUS_UP;
> +    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..abdc01d 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, ncf_if_status_flags *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..3cf045c 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, ncf_if_status_flags *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..0e1d4bd 100644
> --- a/src/netcf.h
> +++ b/src/netcf.h
> @@ -163,6 +163,15 @@ char *ncf_if_xml_desc(struct netcf_if *);
>    */
>   char *ncf_if_xml_state(struct netcf_if *);
>
> +typedef enum {
> +    NETCF_IFACE_STATUS_UP = 1,
> +} ncf_if_status_flags;
> +
> +/* 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, ncf_if_status_flags *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;
>    



More information about the netcf-devel mailing list