Fixed a bug in netcf when netmask is bigger than 24
by Jens Nyberg
Hi,
I noticed a bug in netcf when setting a netmask larger than /24.
This patch consist of:
* Removed a -1 in the inet_ntop call which is the actual bug that made the string incorrect.
* Changed the way you calculate the netmask ip in a more intuitive way - feel free to ignore it if you want.
--- xslt_ext.c 2011-10-26 17:42:54.000000000 +0200
+++ xslt_ext.c.new 2011-10-26 17:39:16.000000000 +0200
@@ -71,10 +71,10 @@
struct in_addr netmask;
xmlChar netmask_str[16];
- netmask.s_addr = htonl(~((1 << (32 - prefix)) - 1));
+ netmask.s_addr = htonl(~(0xffffffff >> prefix));
if (! inet_ntop(AF_INET, &netmask,
- (char *) netmask_str, sizeof(netmask_str) - 1)) {
+ (char *) netmask_str, sizeof(netmask_str))) {
xsltTransformError(xsltXPathGetTransformContext(ctxt), NULL, NULL,
"ipcalc:netmask: internal error: inet_ntop failed");
goto error;
12 years, 4 months
Fix to allow definitions with multiple ipv4 addresses for arp monitoring
by Jens Nyberg
Hi!
It's me again and I have a new patch. I don't know if I went about this the correct way but it solved a problem we had.
We wanted to define multiple targets for arp monitoring. Having multiple targets actually works except it is disallowed by the parser so I created a new definition called ipv4-multi-addr to solve it.
This might not be the correct solution so please advice me on how to further improve this in order to better suit the netcf code base.
Thanks!
// Jens
Patch:
--- interface.rng 2010-06-17 15:40:45.000000000 +0200
+++ interface.rng.new 2011-10-31 14:56:36.000000000 +0100
@@ -202,7 +202,7 @@
</element>
<element name="arpmon">
<attribute name="interval"><ref name="uint"/></attribute>
- <attribute name="target"><ref name="ipv4-addr"/></attribute>
+ <attribute name="target"><ref name="ipv4-multi-addr"/></attribute>
<optional>
<attribute name="validate">
<choice>
@@ -446,6 +446,12 @@
</data>
</define>
+ <define name='ipv4-multi-addr'>
+ <data type='string'>
+ <param name="pattern">(((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2}))\.){3}((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2}))(,(((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2}))\.){3}((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2})))*</param>
+ </data>
+ </define>
+
<define name='ipv4-prefix'>
<data type='unsignedInt'>
<param name="maxInclusive">32</param>
12 years, 4 months
debian version
by Serge Hallyn
Hi,
for the last two days I've been trying to get the debian version of ncftool
(I think not much changes since I put it up at
http://people.canonical.com/~serge/netcf - I should put up a source tree, I
know) to actually write out a new /etc/network/interfaces files when doing
ncftool define br.xml. It claims success, but /etc/network/interfaces never
gets written, even though aug_save() gets called.
I've instrumented augeas's aug_set() and tree_store_value() to verify that
the following are being set:
aug_set: setting /files/etc/network/interfaces/auto[3]/1 to br0
aug_set: setting /files/etc/network/interfaces/iface[3] to br0
aug_set: setting /files/etc/network/interfaces/iface[3]/family to inet
aug_set: setting /files/etc/network/interfaces/iface[3]/method to dhcp
aug_set: setting /files/etc/network/interfaces/iface[3]/mtu to 1500
aug_set: setting /files/etc/network/interfaces/iface[3]/bridge_ports to eth0
aug_set: setting /files/etc/network/interfaces/iface[3]/bridge_stp to off
aug_set: setting /files/etc/network/interfaces/iface[3]/bridge_fd to 0.01
tree_store_value() now looks as follows, in case you're wondering:
void tree_store_value(struct tree *tree, char **value) {
#if 0
if (streqv(tree->value, *value)) {
free(*value);
*value = NULL;
return;
}
#endif
if (tree->value != NULL) {
free(tree->value);
tree->value = NULL;
}
if (*value != NULL) {
tree->value = *value;
*value = NULL;
}
{
FILE *f = fopen("/tmp/log4", "a");
if (f) {
fprintf(f, "tree_set_value: setting %s to %s\n",
tree->label, tree->value);
fclose(f);
}
}
tree_mark_dirty(tree);
}
and log4 does get populated with entries for each of the above (showing
only the last part of the path of course). So it seems there should be
no doubt that the values are, in fact being set.
But when I do
{
FILE *f = fopen("/tmp/log7", "a");
aug_print(aug, f, NULL);
fclose(f);
}
either before or after the aug_save in drv_define, the new rules are not
there! (no 'bridge_ports' to be found at all in the output, for instance)
So the rules are disappearing before we get to aug_save(0).
Any ideas?
-serge
PS - I've used augtool by hand to verify that doing
set /files/etc/network/interfaces/auto[3]/1 br0
set /files/etc/network/interfaces/iface[3] br0
set /files/etc/network/interfaces/iface[3]/family inet
set /files/etc/network/interfaces/iface[3]/method dhcp
set /files/etc/network/interfaces/iface[3]/mtu 1500
set /files/etc/network/interfaces/iface[3]/bridge_ports eth0
set /files/etc/network/interfaces/iface[3]/bridge_stp off
set /files/etc/network/interfaces/iface[3]/bridge_fd 0.01
save
creates the right new /etc/network/interfaces file.
PPS - here is the br.xml I'm using:
<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="eth0">
<!-- <mac address="ab:bb:cc:dd:ee:ff"/>-->
</interface>
</bridge>
</interface>
12 years, 6 months
Not possible to define more than two ARP target using virsh tools
by ehiwere.matthew@ieee.org
I created an xml file for bonding
<interface type='bond' name='bond0'>
<start mode='onboot'/>
<protocol family='ipv4'>
<ip address='192.168.10.2' prefix='24'/>
</protocol>
<bond mode='active-backup'>
<arpmon interval='500' target='192.168.10.254,192.168.1.254'
validate='all'/>
<interface type='ethernet' name='eth0'>
<mac address='00:21:28:a7:a7:10'/>
</interface>
<interface type='ethernet' name='eth1'>
<mac address='00:21:28:a7:a7:10'/>
</interface>
</bond>
</interface>
When i try Defining it.
virsh iface-define bond.xml
# virsh iface-define bond0.xml
error: Failed to define interface from bond0.xml
error: XML description for could not get interface XML description (netcf:
XML invalid - Element arpmon failed to validate attributes
) is not well formed or invalid
What am i doing wrong here.
--
Ehiwere Matthew.
Graduate Student.
Sweden
+46736942168
MOTTO: The past is my heritage,
The present is my responsibility
The future is my challenge
"Chose to stand,not because there is no seat but because I want to be
counted"
12 years, 6 months
[PATCH] Fix build errors when using -Werror=unused-but-set-variable
by Laine Stump
From: Laine Stump <laine(a)vlap.laine.org>
The following errors appeared when I began building on Fedora 16. In
all cases, the variables really are never used, so they've been
removed.
drv_redhat.c: In function 'find_ifcfg_path_by_device':
drv_redhat.c:169:20: error: variable 'aug' set but not used
[-Werror=unused-but-set-variable]
drv_redhat.c: In function 'list_interfaces':
drv_redhat.c:315:20: error: variable 'aug' set but not used
[-Werror=unused-but-set-variable]
drv_redhat.c: In function 'drv_lookup_by_name':
drv_redhat.c:465:20: error: variable 'aug' set but not used
[-Werror=unused-but-set-variable]
drv_redhat.c: In function 'aug_put_xml':
drv_redhat.c:555:13: error: variable 'toplevel' set but not used
[-Werror=unused-but-set-variable]
drv_redhat.c: In function 'drv_lookup_by_mac_string':
drv_redhat.c:942:20: error: variable 'aug' set but not used
[-Werror=unused-but-set-variable]
---
src/drv_redhat.c | 17 ++++-------------
1 files changed, 4 insertions(+), 13 deletions(-)
diff --git a/src/drv_redhat.c b/src/drv_redhat.c
index f290cdb..d2c7971 100644
--- a/src/drv_redhat.c
+++ b/src/drv_redhat.c
@@ -166,11 +166,10 @@ static char *find_ifcfg_path_by_hwaddr(struct netcf *ncf, const char *mac) {
* interface by checking for an entry 'DEVICE=NAME'
*/
static char *find_ifcfg_path_by_device(struct netcf *ncf, const char *name) {
- struct augeas *aug = NULL;
int ndevs = 0;
char **devs = NULL;
- aug = get_augeas(ncf);
+ get_augeas(ncf);
ERR_BAIL(ncf);
ndevs = aug_fmt_match(ncf, &devs, "%s[DEVICE = '%s']",
@@ -312,9 +311,8 @@ static int list_ifcfg_paths(struct netcf *ncf, char ***intf) {
static int list_interfaces(struct netcf *ncf, char ***intf) {
int nint = 0, result = 0;
- struct augeas *aug = NULL;
- aug = get_augeas(ncf);
+ get_augeas(ncf);
ERR_BAIL(ncf);
/* Look in augeas for all interfaces */
@@ -462,9 +460,8 @@ struct netcf_if *drv_lookup_by_name(struct netcf *ncf, const char *name) {
struct netcf_if *nif = NULL;
char *pathx = NULL;
char *name_dup = NULL;
- struct augeas *aug;
- aug = get_augeas(ncf);
+ get_augeas(ncf);
ERR_BAIL(ncf);
pathx = find_ifcfg_path(ncf, name);
@@ -552,17 +549,12 @@ static int aug_put_xml(struct netcf *ncf, xmlDocPtr xml) {
EINTERNAL, "expected node labeled 'tree', not '%s'",
tree->name);
path = xml_prop(tree, "path");
- int toplevel = 1;
/* This is a little drastic, since it clears out the file entirely */
r = aug_rm(aug, path);
ERR_THROW(r < 0, ncf, EINTERNAL, "aug_rm of '%s' failed", path);
list_for_each(node, tree->children) {
label = xml_prop(node, "label");
value = xml_prop(node, "value");
- /* We should mark the toplevel interface from the XSLT */
- if (STREQ(label, "BRIDGE") || STREQ(label, "MASTER")) {
- toplevel = 0;
- }
r = xasprintf(&lpath, "%s/%s", path, label);
ERR_NOMEM(r < 0, ncf);
@@ -939,7 +931,6 @@ int drv_undefine(struct netcf_if *nif) {
int drv_lookup_by_mac_string(struct netcf *ncf, const char *mac,
int maxifaces, struct netcf_if **ifaces)
{
- struct augeas *aug = NULL;
char *path = NULL, *ifcfg = NULL;
const char **names = NULL;
int nmatches = 0;
@@ -949,7 +940,7 @@ int drv_lookup_by_mac_string(struct netcf *ncf, const char *mac,
MEMZERO(ifaces, maxifaces);
- aug = get_augeas(ncf);
+ get_augeas(ncf);
ERR_BAIL(ncf);
nmatches = aug_match_mac(ncf, mac, &matches);
--
1.7.6.4
12 years, 6 months