The organization method of these patches seems to be "stream of
consciousness" (as if Jack Kerouac decided to write a netcf port on a
scroll of paper :-)). That's definitely the right way to go while
developing it (that way you don't lose any ideas during subsequent
edits), but for the final version that's sent to the list, you'll want
it to be much more succint - maybe an initial patch (or two or three) to
re-factor existing code that will be useful for your port (e.g., moving
the augeas-related functions into dutil_augeas.*), a 2nd patch to deal
with the autotools and makefile changes, and (if you like) add simple
stubs for the most toplevel functions that need to be supported by a
platform, then a third and final patch to flesh out all of the toplevel
functions along with the new utility functions they need.
On 05/18/2012 12:38 PM, Sean Bruno wrote:
---
src/Makefile.am | 2 +-
src/drv_fbsd.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++
src/dutil_fbsd.c | 27 ---------------
src/dutil_fbsd.h | 40 +++++++++--------------
src/dutil_linux.c | 73 +++++++++++++++++++++++++++++++++--------
I haven't yet looked at what changes you made to dutil_linux.c, but
based on what I've seen in the previous patches, you should instead be
adding new functions to dutil_freebsd.c
5 files changed, 171 insertions(+), 65 deletions(-)
delete mode 100644 src/dutil_fbsd.c
diff --git a/src/Makefile.am b/src/Makefile.am
index e431eff..81aaadc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -16,7 +16,7 @@ noinst_PROGRAMS = ncftransform
endif
DRIVER_SOURCES_COMMON = dutil.h dutil.c
-DRIVER_SOURCES_FBSD = dutil_fbsd.h dutil_fbsd.c drv_fbsd.c
+DRIVER_SOURCES_FBSD = dutil_fbsd.h drv_fbsd.c
So you added dutil_fbsd.c, then removed it. As I said above, I think you
really will want it, but if not then you shouldn't add it in the first
place (tl;dr - liberal use of "git rebase -i" will be appreciated :-)
DRIVER_SOURCES_LINUX = dutil_linux.h dutil_linux.c
DRIVER_SOURCES_MSWINDOWS = dutil_mswindows.h dutil_mswindows.c drv_mswindows.c
DRIVER_SOURCES_REDHAT = drv_redhat.c
diff --git a/src/drv_fbsd.c b/src/drv_fbsd.c
index 1b3bb87..0ae2b8e 100644
--- a/src/drv_fbsd.c
+++ b/src/drv_fbsd.c
@@ -59,6 +59,32 @@ void drv_close(struct netcf *ncf) {
}
+void drv_entry (struct netcf *ncf ATTRIBUTE_UNUSED) {
+}
+
+static int list_interfaces(struct netcf *ncf, char ***intf) {
+ int nint = 0, result = 0;
+ struct augeas *aug = NULL;
+ FILE *hackery;
+
+ aug = get_augeas(ncf);
+ ERR_BAIL(ncf);
+
+ /* Look for all interfaces */
+ hackery = popen("r+","ifconfig|grep flags|awk '{print $1}'|wc
-l"); // HACKERY
+ read(&nint, sizeof(nint), 1, hackery);
+ printf ("nint == %d\n");
+ pclose(hackery);
+ ERR_BAIL(ncf);
+ result = nint;
+
+ /* TODO filter out slave interfaces */
+ return result;
+ error:
+ free_matches(nint, intf);
+ return -1;
+}
+
static int list_interface_ids(struct netcf *ncf,
int maxnames,
char **names, unsigned int flags ATTRIBUTE_UNUSED) {
@@ -230,3 +256,71 @@ drv_change_commit(struct netcf *ncf, unsigned int flags
ATTRIBUTE_UNUSED)
error:
return result;
}
+
+/*
+ * Test interface
+ */
+static int drv_get_aug(struct netcf *ncf, const char *ncf_xml, char **aug_xml) {
+ xmlDocPtr ncf_doc = NULL, aug_doc = NULL;
+ int result = -1;
+
+ ncf_doc = parse_xml(ncf, ncf_xml);
+ ERR_BAIL(ncf);
+
+ rng_validate(ncf, ncf_doc);
+ ERR_BAIL(ncf);
+
+ *aug_xml = apply_stylesheet_to_string(ncf, ncf->driver->get, ncf_doc);
+ ERR_BAIL(ncf);
+
+ /* fallthrough intentional */
+ result = 0;
+ error:
+ xmlFreeDoc(ncf_doc);
+ xmlFreeDoc(aug_doc);
+ return result;
+}
+
+/* Transform the Augeas XML AUG_XML into interface XML NCF_XML */
+static int drv_put_aug(struct netcf *ncf, const char *aug_xml, char **ncf_xml) {
+ xmlDocPtr ncf_doc = NULL, aug_doc = NULL;
+ int result = -1;
+
+ aug_doc = parse_xml(ncf, aug_xml);
+ ERR_BAIL(ncf);
+
+ *ncf_xml = apply_stylesheet_to_string(ncf, ncf->driver->put, aug_doc);
+ ERR_BAIL(ncf);
+
+ /* fallthrough intentional */
+ result = 0;
+ error:
+ xmlFreeDoc(ncf_doc);
+ xmlFreeDoc(aug_doc);
+ return result;
+}
+
+/*
+ * Test interface
+ */
+int ncf_get_aug(struct netcf *ncf, const char *ncf_xml, char **aug_xml) {
+ API_ENTRY(ncf);
+
+ return drv_get_aug(ncf, ncf_xml, aug_xml);
+}
+
+int ncf_put_aug(struct netcf *ncf, const char *aug_xml, char **ncf_xml) {
+ API_ENTRY(ncf);
+
+ return drv_put_aug(ncf, aug_xml, ncf_xml);
+}
+
+/*
+ * Local variables:
+ * indent-tabs-mode: nil
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */
+/* vim: set ts=4 sw=4 et: */
diff --git a/src/dutil_fbsd.c b/src/dutil_fbsd.c
deleted file mode 100644
index 3f98319..0000000
--- a/src/dutil_fbsd.c
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * dutil_mswindows.c: Windows utility functions for driver backends.
- *
- * Copyright (C) 2010 Red Hat Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Adam Stokes <astokes(a)fedoraproject.org>
- */
-
-#include <config.h>
-#include <internal.h>
-
-#include "dutil.h"
-#include "dutil_mswindows.h"
diff --git a/src/dutil_fbsd.h b/src/dutil_fbsd.h
index 78295b5..6409099 100644
--- a/src/dutil_fbsd.h
+++ b/src/dutil_fbsd.h
@@ -1,30 +1,22 @@
/*
- * dutil_mswindows.h: Window utility functions for driver backends.
- *
- * Copyright (C) 2010 Red Hat Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Adam Stokes <astokes(a)fedoraproject.org>
+ * dutil_fbsd.c: FreeBSD utility functions for driver backends.
*/
-#ifndef DUTIL_MSWINDOWS_H_
-#define DUTIL_MSWINDOWS_H_
+#include <config.h>
+#include <internal.h>
+
+#include "dutil.h"
struct driver {
- int padding;
+ struct augeas *augeas;
+ xsltStylesheetPtr put;
+ xsltStylesheetPtr get;
+ int ioctl_fd;
+ struct nl_handle *nl_sock;
+ struct nl_cache *link_cache;
+ struct nl_cache *addr_cache;
+ unsigned int load_augeas : 1;
+ unsigned int copy_augeas_xfm : 1;
+ unsigned int augeas_xfm_num_tables;
+ const struct augeas_xfm_table **augeas_xfm_tables;
};
-
-#endif /* DUTIL_MSWINDOWS_H_ */
diff --git a/src/dutil_linux.c b/src/dutil_linux.c
index e36c8e3..4651592 100644
--- a/src/dutil_linux.c
+++ b/src/dutil_linux.c
@@ -877,6 +877,10 @@ struct nl_ip_callback_data {
/* add all ip addresses for the given interface to the xml document
*/
+#ifdef __FreeBSD__
+static void add_ip_info_cb(struct nl_object *obj, void *arg) {
+}
+#else
static void add_ip_info_cb(struct nl_object *obj, void *arg) {
struct nl_ip_callback_data *cb_data = arg;
struct rtnl_addr *addr = (struct rtnl_addr *)obj;
@@ -955,7 +959,15 @@ static void add_ip_info_cb(struct nl_object *obj, void *arg) {
error:
return;
}
+#endif
+#ifdef __FreeBSD__
+static void add_ip_info(struct netcf *ncf,
+ const char *ifname ATTRIBUTE_UNUSED, int ifindex,
+ xmlDocPtr doc, xmlNodePtr root) {
+ return;
+}
+#else
static void add_ip_info(struct netcf *ncf,
const char *ifname ATTRIBUTE_UNUSED, int ifindex,
xmlDocPtr doc, xmlNodePtr root) {
@@ -975,7 +987,7 @@ error:
rtnl_addr_put(filter_addr);
return;
}
-
+#endif
struct nl_ethernet_callback_data {
xmlDocPtr doc;
@@ -1008,6 +1020,13 @@ error:
return;
}
+#ifdef __FreeBSD__
+static void add_ethernet_info(struct netcf *ncf,
+ const char *ifname ATTRIBUTE_UNUSED, int ifindex,
+ xmlDocPtr doc, xmlNodePtr root) {
+ return;
+}
+#else
static void add_ethernet_info(struct netcf *ncf,
const char *ifname ATTRIBUTE_UNUSED, int ifindex,
xmlDocPtr doc, xmlNodePtr root) {
@@ -1015,11 +1034,9 @@ static void add_ethernet_info(struct netcf *ncf,
= { doc, root, NULL, ncf };
struct rtnl_link *filter_link = NULL;
-#ifndef __FreeBSD__
/* if interface isn't currently available, nothing to add */
if (ifindex == RTNL_LINK_NOT_FOUND)
return;
-#endif
filter_link = rtnl_link_alloc();
ERR_NOMEM(filter_link == NULL, ncf);
@@ -1033,6 +1050,7 @@ error:
rtnl_link_put(filter_link);
return;
}
+#endif
struct nl_vlan_callback_data {
xmlDocPtr doc;
@@ -1041,6 +1059,11 @@ struct nl_vlan_callback_data {
struct netcf *ncf;
};
+#ifdef __FreeBSD__
+static void add_vlan_info_cb(struct nl_object *obj, void *arg) {
+ return;
+}
+#else
static void add_vlan_info_cb(struct nl_object *obj, void *arg) {
struct nl_vlan_callback_data *cb_data = arg;
struct rtnl_link *iflink = (struct rtnl_link *)obj;
@@ -1064,10 +1087,8 @@ static void add_vlan_info_cb(struct nl_object *obj, void *arg) {
return;
l_link = rtnl_link_get_link(iflink);
-#ifndef __FreeBSD__
if (l_link == RTNL_LINK_NOT_FOUND)
return;
-#endif
master_link = rtnl_link_get(nl_object_get_cache(obj), l_link);
if (master_link == NULL)
@@ -1091,18 +1112,24 @@ static void add_vlan_info_cb(struct nl_object *obj, void *arg) {
/* Add in type-specific info of master interface */
master_ifindex = rtnl_link_name2i(ncf->driver->link_cache, master_name);
-#ifndef __FreeBSD__
ERR_THROW((master_ifindex == RTNL_LINK_NOT_FOUND), ncf, ENETLINK,
"couldn't find ifindex for vlan master interface `%s`",
master_name);
-#endif
add_type_specific_info(ncf, master_name, master_ifindex,
cb_data->doc, interface_node);
error:
return;
}
+#endif
+#ifdef __FreeBSD__
+static void add_vlan_info(struct netcf *ncf,
+ const char *ifname ATTRIBUTE_UNUSED, int ifindex,
+ xmlDocPtr doc, xmlNodePtr root) {
+ return;
+}
+#else
static void add_vlan_info(struct netcf *ncf,
const char *ifname ATTRIBUTE_UNUSED, int ifindex,
xmlDocPtr doc, xmlNodePtr root) {
@@ -1110,11 +1137,9 @@ static void add_vlan_info(struct netcf *ncf,
= { doc, root, NULL, ncf };
struct rtnl_link *filter_link = NULL;
-#ifndef __FreeBSD__
/* if interface isn't currently available, nothing to add */
if (ifindex == RTNL_LINK_NOT_FOUND)
return;
-#endif
filter_link = rtnl_link_alloc();
ERR_NOMEM(filter_link == NULL, ncf);
@@ -1129,7 +1154,15 @@ error:
rtnl_link_put(filter_link);
return;
}
+#endif
+#ifdef __FreeBSD__
+static void add_bridge_info(struct netcf *ncf,
+ const char *ifname, int ifindex ATTRIBUTE_UNUSED,
+ xmlDocPtr doc, xmlNodePtr root) {
+ return;
+}
+#else
static void add_bridge_info(struct netcf *ncf,
const char *ifname, int ifindex ATTRIBUTE_UNUSED,
xmlDocPtr doc, xmlNodePtr root) {
@@ -1171,6 +1204,7 @@ error:
FREE(phys_names[ii]);
FREE(phys_names);
}
+#endif
struct nl_bond_callback_data {
@@ -1181,6 +1215,12 @@ struct nl_bond_callback_data {
struct netcf *ncf;
};
+#ifdef __FreeBSD__
+static void add_bond_info_cb(struct nl_object *obj,
+ void *arg ATTRIBUTE_UNUSED) {
+ return;
+}
+#else
static void add_bond_info_cb(struct nl_object *obj,
void *arg ATTRIBUTE_UNUSED) {
struct nl_bond_callback_data *cb_data = arg;
@@ -1189,7 +1229,6 @@ static void add_bond_info_cb(struct nl_object *obj,
xmlNodePtr interface_node;
-#ifndef __FreeBSD__
/* If this is a slave link, and the master is master_ifindex, add the
* interface info to the bond.
*/
@@ -1197,7 +1236,6 @@ static void add_bond_info_cb(struct nl_object *obj,
if (!(rtnl_link_get_flags(iflink) & IFF_SLAVE)
|| rtnl_link_get_master(iflink) != cb_data->master_ifindex)
return;
-#endif
cb_data->bond = xml_node(cb_data->doc, cb_data->root, "bond");
ERR_NOMEM(cb_data->bond == NULL, ncf);
@@ -1222,21 +1260,28 @@ static void add_bond_info_cb(struct nl_object *obj,
error:
return;
}
+#endif
+#ifdef __FreeBSD__
+static void add_bond_info(struct netcf *ncf,
+ const char *ifname ATTRIBUTE_UNUSED, int ifindex,
+ xmlDocPtr doc, xmlNodePtr root) {
+ return;
+}
+#else
static void add_bond_info(struct netcf *ncf,
const char *ifname ATTRIBUTE_UNUSED, int ifindex,
xmlDocPtr doc, xmlNodePtr root) {
struct nl_bond_callback_data cb_data
= { doc, root, NULL, ifindex, ncf };
-#ifndef __FreeBSD__
/* if interface isn't currently available, nothing to add */
if (ifindex == RTNL_LINK_NOT_FOUND)
return;
-#endif
nl_cache_foreach(ncf->driver->link_cache, add_bond_info_cb, &cb_data);
}
+#endif
static void add_type_specific_info(struct netcf *ncf,
@@ -1288,6 +1333,7 @@ void add_state_to_xml_doc(struct netcf_if *nif, xmlDocPtr doc) {
ERR_THROW(!xmlStrEqual(root->name, BAD_CAST "interface"),
nif->ncf, EINTERNAL, "root document is not an interface");
+#ifndef __FreeBSD__
/* Update the caches with any recent changes */
code = nl_cache_refill(nif->ncf->driver->nl_sock,
nif->ncf->driver->link_cache);
@@ -1299,6 +1345,7 @@ void add_state_to_xml_doc(struct netcf_if *nif, xmlDocPtr doc) {
"failed to refill interface address cache");
ifindex = rtnl_link_name2i(nif->ncf->driver->link_cache, nif->name);
+#endif
/* We ignore an error return here, because that usually just
* means the interface isn't currently running. The
* type-specific functions will recognize this from the