Preparing for aditional drivers
by Jonas Eriksson
Hello,
This is the last set of patches before the amount of shared code
between the SuSE-driver (in its current state, at least) and the
current initscripts driver is almost nil.
The last two patches were only discussed briefly, so I kept them
at the end. Feel free to react, and note that it means that all
"variables" in an ifcfg-file will get single quotes. The lens is
however able to read unquoted variables from these files.
For the SuSE-driver, I currently lack VLAN-support (which on SuSE
is a mess in some aspects), and some tests. Hopefully, these
things won't take long to fix.
/Jonas
14 years, 7 months
[PATCH] Fix conversion of XML DOM's into strings
by David Lutterkort
We should not use xmlDocDumpFormatMemory to convert a DOM we got from
applying a stylesheet to a string; the proper API to use is
xsltSaveResultToString.
* src/dutil.h (apply_stylesheet_to_string): new function
* src/dutil.c (apply_stylesheet_to_string): new function
* src/dutil.c (dutil_get_aug, dutil_put_aug): use
apply_stylesheet_to_string
* src/drv_initscripts.c (drv_xml_desc): use apply_stylesheet_to_string
---
src/drv_initscripts.c | 6 +++---
src/dutil.c | 30 ++++++++++++++++++++++++------
src/dutil.h | 5 +++++
3 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/src/drv_initscripts.c b/src/drv_initscripts.c
index b9ef03c..3da9209 100644
--- a/src/drv_initscripts.c
+++ b/src/drv_initscripts.c
@@ -43,6 +43,7 @@
#include <libxslt/xslt.h>
#include <libxslt/xsltInternals.h>
#include <libxslt/transform.h>
+#include <libxslt/xsltutils.h>
static const char *const ifcfg_path =
"/files/etc/sysconfig/network-scripts/*";
@@ -498,10 +499,9 @@ char *drv_xml_desc(struct netcf_if *nif) {
ERR_BAIL(ncf);
aug_xml = aug_get_xml(ncf, nint, intf);
- ncf_xml = apply_stylesheet(ncf, ncf->driver->put, aug_xml);
- ERR_BAIL(ncf);
- xmlDocDumpFormatMemory(ncf_xml, (xmlChar **) &result, NULL, 1);
+ result = apply_stylesheet_to_string(ncf, ncf->driver->put, aug_xml);
+ ERR_BAIL(ncf);
done:
free_matches(nint, &intf);
diff --git a/src/dutil.c b/src/dutil.c
index 993f715..9c1481e 100644
--- a/src/dutil.c
+++ b/src/dutil.c
@@ -238,6 +238,28 @@ error:
xsltFreeTransformContext(ctxt);
return res;
}
+
+char *apply_stylesheet_to_string(struct netcf *ncf, xsltStylesheetPtr style,
+ xmlDocPtr doc) {
+ xmlDocPtr doc_xfm = NULL;
+ char *result = NULL;
+ int r, result_len;
+
+ doc_xfm = apply_stylesheet(ncf, style, doc);
+ ERR_BAIL(ncf);
+
+ r = xsltSaveResultToString((xmlChar **) &result, &result_len,
+ doc_xfm, style);
+ ERR_COND_BAIL(r < 0, ncf, ENOMEM);
+ xmlFree(doc_xfm);
+ return result;
+
+ error:
+ FREE(result);
+ xmlFreeDoc(doc_xfm);
+ return NULL;
+}
+
/* Callback for reporting RelaxNG errors */
void rng_error(void *ctx, const char *format, ...) {
struct netcf *ncf = ctx;
@@ -392,11 +414,9 @@ int dutil_get_aug(struct netcf *ncf, const char *ncf_xml, char **aug_xml) {
rng_validate(ncf, ncf_doc);
ERR_BAIL(ncf);
- aug_doc = apply_stylesheet(ncf, ncf->driver->get, ncf_doc);
+ *aug_xml = apply_stylesheet_to_string(ncf, ncf->driver->get, ncf_doc);
ERR_BAIL(ncf);
- xmlDocDumpFormatMemory(aug_doc, (xmlChar **) aug_xml, NULL, 1);
- ERR_COND_BAIL(*aug_xml == NULL, ncf, EXMLINVALID);
/* fallthrough intentional */
result = 0;
error:
@@ -413,11 +433,9 @@ int dutil_put_aug(struct netcf *ncf, const char *aug_xml, char **ncf_xml) {
aug_doc = parse_xml(ncf, aug_xml);
ERR_BAIL(ncf);
- ncf_doc = apply_stylesheet(ncf, ncf->driver->put, aug_doc);
+ *ncf_xml = apply_stylesheet_to_string(ncf, ncf->driver->put, aug_doc);
ERR_BAIL(ncf);
- xmlDocDumpFormatMemory(ncf_doc, (xmlChar **) ncf_xml, NULL, 1);
- ERR_COND_BAIL(*ncf_xml == NULL, ncf, EXMLINVALID);
/* fallthrough intentional */
result = 0;
error:
diff --git a/src/dutil.h b/src/dutil.h
index fbf11fb..38aec5f 100644
--- a/src/dutil.h
+++ b/src/dutil.h
@@ -68,6 +68,11 @@ xsltStylesheetPtr parse_stylesheet(struct netcf *ncf, const char *fname);
xmlDocPtr apply_stylesheet(struct netcf *ncf, xsltStylesheetPtr style,
xmlDocPtr doc);
+/* Same as APPLY_STYLESHEET, but convert the resulting XML document into a
+ * string */
+char *apply_stylesheet_to_string(struct netcf *ncf, xsltStylesheetPtr style,
+ xmlDocPtr doc);
+
/* Callback for reporting RelaxNG errors */
void rng_error(void *ctx, const char *format, ...);
--
1.6.2.5
14 years, 7 months
(no subject)
by David Lutterkort
here is a proposed fix for the segfaults you were seeing in the libvirt-cim
test suite, connected to netcf shutting down libxslt.
David
14 years, 8 months
[PATCH] enable automake-1.11 features: colorized and parallel tests, etc.
by David Lutterkort
Also enable automake's new "silent-rules" feature.
Use "make V=1" to see the usual, verbose-mode commands.
* configure.ac: Require automake-1.11.
Enable color-tests parallel-tests. Use AM_SILENT_RULES([yes])
Based on the same patch for Augeas by Jim Meyering
---
configure.ac | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/configure.ac b/configure.ac
index b10072c..d339c59 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,8 +2,8 @@ AC_INIT(netcf, 0.1.0)
AC_CONFIG_SRCDIR([src/netcf.c])
AC_CONFIG_AUX_DIR([build/aux])
AM_CONFIG_HEADER([config.h])
-AM_INIT_AUTOMAKE([-Wno-portability])
-
+AM_INIT_AUTOMAKE([-Wno-portability 1.11 color-tests parallel-tests])
+AM_SILENT_RULES([yes]) # make --enable-silent-rules the default.
AC_SUBST([LIBNETCF_VERSION_INFO], [1:0:0])
--
1.6.2.5
14 years, 8 months
[PATCH 1/1] Install util-*.xsl when running make install
by Jonas Eriksson
Makefile.am: Add data/xml/util-get.xsl and data/xml/util-put.xsl to
list of data files
---
Makefile.am | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 2b4e410..d61a752 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -12,6 +12,7 @@ xmldir=$(netcfdir)/xml
lensdir=$(netcfdir)/lenses
dist_xml_DATA=data/xml/augeas.rng data/xml/interface.rng \
+ data/xml/util-get.xsl data/xml/util-put.xsl \
data/xml/initscripts-get.xsl data/xml/initscripts-put.xsl
dist_netcf_DATA=data/iptables-forward-bridged
dist_lens_DATA=data/lenses/netcf.aug
--
1.6.2
14 years, 8 months
[PATCH] * src/ref.h (ref_make_ref): prevent inlining
by David Lutterkort
The assignment to '*(void **) ptrptr' makes gcc think it breaks strict
aliasing, and produces a compilation error when ref_make_ref is inlined.
---
src/internal.h | 4 ++++
src/ref.h | 6 +++++-
2 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/src/internal.h b/src/internal.h
index a11648b..3e1603a 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -70,11 +70,15 @@
#endif
#endif
+#ifndef ATTRIBUTE_NOINLINE
+#define ATTRIBUTE_NOINLINE __attribute__((__noinline__))
+#endif
#else
#define ATTRIBUTE_UNUSED
#define ATTRIBUTE_FORMAT(...)
#define ATTRIBUTE_PURE
#define ATTRIBUTE_RETURN_CHECK
+#define ATTRIBUTE_NOINLINE
#endif /* __GNUC__ */
/* This needs ATTRIBUTE_RETURN_CHECK */
diff --git a/src/ref.h b/src/ref.h
index f9faab7..3a84df9 100644
--- a/src/ref.h
+++ b/src/ref.h
@@ -44,7 +44,11 @@
typedef unsigned int ref_t;
-ATTRIBUTE_UNUSED ATTRIBUTE_RETURN_CHECK
+/* Prevent this function from being inlined; the compiler thinks that the
+ * assignment to PTRPTR breaks strict aliasing - it does not since we know
+ * that ptrptr is already of type (T **)
+ */
+ATTRIBUTE_UNUSED ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NOINLINE
static int ref_make_ref(void *ptrptr, size_t size, size_t ref_ofs) {
*(void**) ptrptr = calloc(1, size);
if (*(void **)ptrptr == NULL) {
--
1.6.2.5
14 years, 8 months
Enslaving already enslaved interfaces
by Jonas Eriksson
Hi,
When enslaving an interface already enslaved by another
interface, the initscripts driver overtakes this enslaved
interface:
---------
ncftool> dumpxml bond0
<?xml version="1.0"?>
<interface type="bond" name="bond0">
<start mode="onboot"/>
<protocol family="ipv4">
<ip address="10.0.1.27" prefix="24"/>
</protocol>
<bond mode="active-backup">
<interface type="ethernet" name="eth2"/>
<interface type="ethernet" name="eth1"/>
</bond>
</interface>
ncftool> define interface/bridge.xml
Defined interface br0
ncftool> dumpxml br0
<?xml version="1.0"?>
<interface type="bridge" name="br0">
<start mode="onboot"/>
<mtu size="1500"/>
<protocol family="ipv4">
<dhcp/>
</protocol>
<bridge stp="off" delay="0.01">
<interface type="ethernet" name="eth1"/>
<interface type="ethernet" name="eth2"/>
</bridge>
</interface>
ncftool> dumpxml bond0
<?xml version="1.0"?>
<interface type="ethernet" name="bond0">
<start mode="onboot"/>
<protocol family="ipv4">
<ip address="10.0.1.27" prefix="24"/>
</protocol>
</interface>
ncftool>
---------
This breaks the XML schema defined by interface.rng, as there
should be "oneOrMore" interfaces enslaved by the bonding
interface.
The SUSE driver solves this by raising an error instead of
taking over enslaved interfaces:
---------
(.. same state as above)
ncftool> define interface/bridge.xml
error: unspecified error
error: interface eth1 slave of interface bond0, unable to continue
ncftool>
---------
Which direction should netcf have for this? My opinion is that
raising an error would be best, as this would allow for better
control over the enslaved interfaces. It would also be simpler
to avoid pitfalls as the bond0 state above.
Regards,
Jonas
--
Jonas Eriksson
Consultant at AS/EAB/FLJ/IL
Combitech AB
Älvsjö, Sweden
14 years, 8 months
MAC lookup, alternative 2
by Jonas Eriksson
Hi,
This is another alternative when implementing the MAC lookup.
Four points about these mails:
* These are experimental and are not supposed to be committed as-is,
but rather commented on.
* normalize_if is a name inherited from earlier work, it should
perhaps be named something like interface_lookup.
* Some mix of these patches is not excluded.
* dutil.c now includes dutil_linux.h. Utility functions that should
exist on all platforms should be lifted out to dutil__os.h or
similar.
This patch set does not change any XML schemas, and do as little as
possible to include the functionality of MAC lookup to the initscripts
driver. This means that we have to lookup HWADDR by going through all
subnodes to /forest/tree before being able to write any infomation,
and that the path attribute have to be regenerated each time.
Feel free to comment.
/Jonas
14 years, 8 months
[PATCH] Check for MAC address 00:00:00:00:00:00
by Jonas Eriksson
src/dutil_linux.c: Running aug_get_mac on the interface lo will report
the MAC address to be 00:00:00:00:00:00. This is now treated as if
no MAC address was found.
---
src/dutil_linux.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/src/dutil_linux.c b/src/dutil_linux.c
index 864bced..350ee51 100644
--- a/src/dutil_linux.c
+++ b/src/dutil_linux.c
@@ -87,6 +87,12 @@ int aug_get_mac(struct netcf *ncf, const char *intf, const char **mac) {
r = aug_get(aug, path, mac);
/* Messages for a aug_match-fail are handled outside this function */
+ /* The lo interface will report a MAC address of 00:00:00:00:00:00 */
+ if (mac != NULL && STREQ(*mac, "00:00:00:00:00:00")) {
+ r = 0;
+ (*mac) = NULL;
+ }
+
/* fallthrough intentional */
error:
FREE(path);
--
1.6.2
14 years, 8 months
MAC lookup, alternative 1
by Jonas Eriksson
Hi,
Time to show some code for the MAC lookup. This is one of the
alternatives where I am pretty cruel to the internal XML schema
(augeas.rng) as well by replacing path with name. Don't get too upset
about this, as it is mostly an experiment to se what happens to the
code. As imagined, some things get easier and some things get harder.
Besides s/path/name/, a mac-attribute is added to the tree so that the
lookup can be made already when reading the tree-tag. The bonus is
that this is an indicator that this is handled by netcf, rather than
the backend.
/Jonas
14 years, 8 months