Re: [libvirt] [PATCH] v2:Support for adding a static route to a bridge

2013-04-10 Thread Gene Czarcinski

On 04/10/2013 03:09 PM, Laine Stump wrote:

On 04/09/2013 04:28 PM, Gene Czarcinski wrote:

On 04/04/2013 12:08 PM, Laine Stump wrote:

Except that it's obvious from your response that I misunderstood your
patch, and thought that you were trying to make the route to an
otherwise unreachable network a part of the unreachable network's config
:-) (my defense is that the dual usage of the  element to define a
route confused me)

You were correct to be confused.  At first, I thought your suggestions
for  were just cosmetic but then I realized that, in general,
an  definition resulted in a specific ".1" or ":1" device address
would be assigned to an interface (bridge).  The net address looked
similar but there would be no device address assigned to the
interface/bridge but there would be an entry for a (static) route.

While the backend will continue to be more or less the same and
instantiate the static route, the "front" end will add a new element:
.  I intend to keep "via" for specifying the gateway rather
than using "gateway.".  This makes it consistent with the ip-route
command.  So, to add a static would, the text would look like:
 
or
 

More work:  I will need to go back and "fix" the virt-manager code.

Based on my now corrected understanding that the route is added to the
config of the network which is directly connected to the gateway (rather
than the network *beyond* the gateway), I have two comments/requests:

1) I think a separate  element is a better idea than trying to
make  dual purpose. Aside from confusing simple-minded people like
me, when things are intertwined like that it has the potential to lead
to an ambiguous situation further down the road. Also, using a separate
 element is closer to the system config files as well as more
similar to the xml used by the virInterface APIs (aka netcf).

Right on ... see above.

2) Although /sbin/ip uses the term "via", I do think that "gateway"
would be the preferred term, since that's been in use for many years
with the (admittedly now deprecated) /sbin/route command, as well as
what is used in the system ifcfg-* and route-* files.

OK, how about having it both ways.  If we can have both mask and
prefix, why not both via and gateway.


Having both mask and prefix was kind of forced by circumstance - when
networks were first created, and there was only support for IPv4, the
people who came up with the XML chose to use netmask; when I later added
IPv6 support, netmask was inappropriate - nobody uses a netmask with
IPv6, they always use prefix. Since prefix was now present, I made it
also recognized for IPv4, but 1) you can only have one or the other, 2)
whichever one you supply is what you get back with dumpxml. That's a
different situation from simultaneously adding two attributes that have
exactly the same purpose and same data type.
Picture an IPv6 mask.  Now picture having to figure out just mean it 
means.  Ugly!


BTW, another reason I prefer "gateway" over "via" is that the xml for
virInterface (netcf) uses "gateway" for the same information in its
 element:

  


  
  

  
  


   I know gateway has some history attached to it but the new /sbin/ip
uses via.


But remember that the goal isn't necessarily to make the xml be similar
to any particular backend, but to make it generic enough that the
backend could be replaced by something else. In this case either term
would work, but I think "gateway" is more widely used and generally
understandable to someone who isn't familiar with /sbin/ip.

(I would still prefer if at least one other person voiced an opinion
though - I don't want to seem like a "patch bully" :-)



I am just trying to keep a line of text being as close to not
exceeding 80 characters as practical.


That's eventually a losing battle :-)



Correct me if I am wrong but all of this is suppose to be free-form
and this should be valid:

 

(I think you meant to say "family='ipv6'" here...)


 gateway='fd00:dead:beef:10::2'  />

Of course, when it gets written back out by code it will all be on a
"single" line.


OK, OK ... I give up.  It will be "gateway" rather than "via" in the 
patch I submit.


One reason I am giving up is that while I was creating the 
formatnetwork.html documentation update, I found that using "via" became 
a little confusing and that "gateway" made more sense.


I must say that I have been impressed with the libvirt development 
cycle.  Releases and updates come out often and they are substantial.


Gene

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] v2:Support for adding a static route to a bridge

2013-04-10 Thread Laine Stump
On 04/10/2013 01:38 PM, Gene Czarcinski wrote:
> On 04/09/2013 04:28 PM, Gene Czarcinski wrote:
>> OK, how about having it both ways.  If we can have both mask and
>> prefix, why not both via and gateway.  I know gateway has some
>> history attached to it but the new /sbin/ip uses via.  I am just
>> trying to keep a line of text being as close to not exceeding 80
>> characters as practical.  Correct me if I am wrong but all of this is
>> suppose to be free-form and this should be valid:
>>
>> > gateway='fd00:dead:beef:10::2'  />
>>
>> Of course, when it gets written back out by code it will all be on a
>> "single" line.
>>
>> How about one of you other folks chiming in on this.  gateway? ...
>> via? ... anybody (besides the two of us) care??
> OK, unless someone can present a convincing argument, I am going with
> "via" and not "gateway".  Thus, the general form is:
> 
> 
>
> Why "via" and not "gateway".  Well, /sbin/ip uses "via" whereas
> /sbin/route uses "gateway".  If there was a convincing argument to
> keep gateway instead off via, the /sbin/ip code would be different or
> would be changed to  gateway.  BTW, IMHO, netmask could disappear also
> and have prefix= only.


Nope. In libvirt *nothing* can ever disappear. We try our hardest to
provide 100% backward compatibility for existing applications (and have
so far been successful at it).

>
> Also, the current implementation enforces that the address specified
> with via= must be resolvable into a network-address which has been
> defined for the interface.  That is, you cannot point via= off into
> some address that the virtualization host has no idea where it is.

Right. It must be directly reachable by the network/interface it's added to.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] v2:Support for adding a static route to a bridge

2013-04-10 Thread Laine Stump
On 04/09/2013 04:28 PM, Gene Czarcinski wrote:
> On 04/04/2013 12:08 PM, Laine Stump wrote:
>> Except that it's obvious from your response that I misunderstood your
>> patch, and thought that you were trying to make the route to an
>> otherwise unreachable network a part of the unreachable network's config
>> :-) (my defense is that the dual usage of the  element to define a
>> route confused me)
> You were correct to be confused.  At first, I thought your suggestions
> for  were just cosmetic but then I realized that, in general,
> an  definition resulted in a specific ".1" or ":1" device address
> would be assigned to an interface (bridge).  The net address looked
> similar but there would be no device address assigned to the
> interface/bridge but there would be an entry for a (static) route.
>
> While the backend will continue to be more or less the same and
> instantiate the static route, the "front" end will add a new element:
> .  I intend to keep "via" for specifying the gateway rather
> than using "gateway.".  This makes it consistent with the ip-route
> command.  So, to add a static would, the text would look like:
>  via='' />
> or
>  via=''  />
>
> More work:  I will need to go back and "fix" the virt-manager code.
>>
>> Based on my now corrected understanding that the route is added to the
>> config of the network which is directly connected to the gateway (rather
>> than the network *beyond* the gateway), I have two comments/requests:
>>
>> 1) I think a separate  element is a better idea than trying to
>> make  dual purpose. Aside from confusing simple-minded people like
>> me, when things are intertwined like that it has the potential to lead
>> to an ambiguous situation further down the road. Also, using a separate
>>  element is closer to the system config files as well as more
>> similar to the xml used by the virInterface APIs (aka netcf).
> Right on ... see above.
>>
>> 2) Although /sbin/ip uses the term "via", I do think that "gateway"
>> would be the preferred term, since that's been in use for many years
>> with the (admittedly now deprecated) /sbin/route command, as well as
>> what is used in the system ifcfg-* and route-* files.
> OK, how about having it both ways.  If we can have both mask and
> prefix, why not both via and gateway.


Having both mask and prefix was kind of forced by circumstance - when
networks were first created, and there was only support for IPv4, the
people who came up with the XML chose to use netmask; when I later added
IPv6 support, netmask was inappropriate - nobody uses a netmask with
IPv6, they always use prefix. Since prefix was now present, I made it
also recognized for IPv4, but 1) you can only have one or the other, 2)
whichever one you supply is what you get back with dumpxml. That's a
different situation from simultaneously adding two attributes that have
exactly the same purpose and same data type.

BTW, another reason I prefer "gateway" over "via" is that the xml for
virInterface (netcf) uses "gateway" for the same information in its
 element:

 
   
   
 
 
   
 
 

>   I know gateway has some history attached to it but the new /sbin/ip
> uses via. 


But remember that the goal isn't necessarily to make the xml be similar
to any particular backend, but to make it generic enough that the
backend could be replaced by something else. In this case either term
would work, but I think "gateway" is more widely used and generally
understandable to someone who isn't familiar with /sbin/ip.

(I would still prefer if at least one other person voiced an opinion
though - I don't want to seem like a "patch bully" :-)


> I am just trying to keep a line of text being as close to not
> exceeding 80 characters as practical.


That's eventually a losing battle :-)


> Correct me if I am wrong but all of this is suppose to be free-form
> and this should be valid:
>
>  gateway='fd00:dead:beef:10::2'  />
>
> Of course, when it gets written back out by code it will all be on a
> "single" line.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] v2:Support for adding a static route to a bridge

2013-04-10 Thread Gene Czarcinski

On 04/09/2013 04:28 PM, Gene Czarcinski wrote:
OK, how about having it both ways.  If we can have both mask and 
prefix, why not both via and gateway.  I know gateway has some history 
attached to it but the new /sbin/ip uses via.  I am just trying to 
keep a line of text being as close to not exceeding 80 characters as 
practical.  Correct me if I am wrong but all of this is suppose to be 
free-form and this should be valid:




Of course, when it gets written back out by code it will all be on a 
"single" line.


How about one of you other folks chiming in on this.  gateway? ... 
via? ... anybody (besides the two of us) care??
OK, unless someone can present a convincing argument, I am going with 
"via" and not "gateway".  Thus, the general form is:




Why "via" and not "gateway".  Well, /sbin/ip uses "via" whereas 
/sbin/route uses "gateway".  If there was a convincing argument to keep 
gateway instead off via, the /sbin/ip code would be different or would 
be changed to  gateway.  BTW, IMHO, netmask could disappear also and 
have prefix= only.


Also, the current implementation enforces that the address specified 
with via= must be resolvable into a network-address which has been 
defined for the interface.  That is, you cannot point via= off into some 
address that the virtualization host has no idea where it is.


Reworked update "real soon now".

Gene

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] v2:Support for adding a static route to a bridge

2013-04-09 Thread Gene Czarcinski

On 04/04/2013 12:08 PM, Laine Stump wrote:

On 04/03/2013 04:02 PM, Gene Czarcinski wrote:

On 04/02/2013 03:31 PM, Laine Stump wrote:

On 03/15/2013 02:10 PM, Gene Czarcinski wrote:

This patch adds support for adding a static route for
a network.  The "via" specifies the gateway's IP
address.  Both IPv4 and IPv6 static routes are
supported although it is expected that this
functionality will have more use with IPv6.

(First I want to make sure I correctly understand what you're wanting to
do, so I'm going to try and explain it in my own words...)

>From reading your earlier messages, my understanding is that the aim of
this patch is to automatically setup a route to a virtual network whose
bridge device has no IP address assigned, and is therefore reachable
only via one of the guests, is this correct?

In other words, let's say that I have the following two networks defined
(using IPv4 and all static IPs for brevity, but the entire discussion is
equally applicable to IPv6):


 
   netVisibleToHost
   
   
   
 

 
   netHiddenFromHost
   
 

and you have a guestDirect that has two interfaces:

   
   
 
   
   
 

and another guestIndirect that has only one interface:

   
   
 

Additionally, the default route on guestDirect points to 192.168.200.1,
and the default route on guestIndirect points to 192.168.201.1.

(Presumably you don't want to simply add an IP address to
netHiddenFromHost because (while it would solve your routing problems)
it would violate some security policy you've built into your network
topology - namely that all traffic to and from netHiddenFromHost *must*
go through guestDirect.)

Traffic outbound from guestIndirect would have no problem reaching its
destination - it would go across netHiddenFromHost to guestDirect
(192.168.201.1), which would know to forward it to the host
(192.168.200.1) via netVisibleToHost, and the host presumably knows how
to get to anywhere. The problem comes when trying to route the
*response* destined for 192.168.201.2 (guestIndirect) - the outside
world may know that those packets have to be sent to the host, but the
host doesn't have a route for 192.168.201.0/24 - only guestDirect does.

So, the solution is to add a route on the *host* that points traffic
destined for 192.168.201.0/24 to guestDirect, a.k.a. 192.168.200.2.

Since there's no place in /etc/sysconfig/network-scripts/route-* to put
static routes with destinations that are only reachable through a
transient interface such as the bridge devices created by libvirt, the
obvious solution is to cause libvirt to add such a route, and the way
you propose to do that is to add an  element in the network named
"netUnreachable".

Am I understanding the issue so far?

I believe you do understand.

OK, I am back from virt-manager.

Except that it's obvious from your response that I misunderstood your
patch, and thought that you were trying to make the route to an
otherwise unreachable network a part of the unreachable network's config
:-) (my defense is that the dual usage of the  element to define a
route confused me)
You were correct to be confused.  At first, I thought your suggestions 
for  were just cosmetic but then I realized that, in general, an 
 definition resulted in a specific ".1" or ":1" device address would 
be assigned to an interface (bridge).  The net address looked similar 
but there would be no device address assigned to the interface/bridge 
but there would be an entry for a (static) route.


While the backend will continue to be more or less the same and 
instantiate the static route, the "front" end will add a new element: 
.  I intend to keep "via" for specifying the gateway rather than 
using "gateway.".  This makes it consistent with the ip-route command.  
So, to add a static would, the text would look like:
via='' />

or
via=''  />


More work:  I will need to go back and "fix" the virt-manager code.


Based on my now corrected understanding that the route is added to the
config of the network which is directly connected to the gateway (rather
than the network *beyond* the gateway), I have two comments/requests:

1) I think a separate  element is a better idea than trying to
make  dual purpose. Aside from confusing simple-minded people like
me, when things are intertwined like that it has the potential to lead
to an ambiguous situation further down the road. Also, using a separate
 element is closer to the system config files as well as more
similar to the xml used by the virInterface APIs (aka netcf).

Right on ... see above.


2) Although /sbin/ip uses the term "via", I do think that "gateway"
would be the preferred term, since that's been in use for many years
with the (admittedly now deprecated) /sbin/route command, as well as
what is used in the system ifcfg-* and route-* files.
OK, how about having it both ways.  If we can have both mask and prefix, 
why not both via and gateway.  

Re: [libvirt] [PATCH] v2:Support for adding a static route to a bridge

2013-04-04 Thread Laine Stump
On 03/15/2013 02:10 PM, Gene Czarcinski wrote:
> diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
> index 296871c..c90b3d2 100644
> --- a/src/util/virnetdev.c
> +++ b/src/util/virnetdev.c
> @@ -729,6 +729,7 @@ int virNetDevGetVLanID(const char *ifname 
> ATTRIBUTE_UNUSED,
>   * Add an IP address to an interface. This function *does not* remove
>   * any previously added IP addresses - that must be done separately with
>   * brDelInetAddress.
> + * TODO: what is "brDelInetAddress"?

That is a left-over comment from long ago. The function has been renamed
to virNetDevClearIPv4Address.

(A very useful separate patch would be one to rename
virNetDev(Set|Clear)IPv4Address to virNetDev(Set|Clear)IPAddress (since
they really *can* be (and are being) used to set both IPv4 and IPv6
addresses), then reimplement them using netlink/libnl calls.

Likewise, it would be much nicer if virNetDevSetGateway() was
implemented using netlink/libnl.


>   *
>   * Returns 0 in case of success or -1 in case of error.
>   */
> @@ -769,6 +770,52 @@ cleanup:
>  }
>  
>  /**
> + * virNetDevSetGateway:

I'm thinking maybe this would be better named "virNetDevAddRoute", since
the thing it's adding is a route (of which the gateway is one attribute).

> + * @ifname: the interface name
> + * @addr: the IP network address (IPv4 or IPv6)
> + * @prefix: number of 1 bits in the netmask
> + * @gateway: via address for route (same as @addr)
> + *
> + * Add a route for a network IP address to an interface. This function
> + * *does not* remove any previously added IP static routes.
> + *
> + * Returns 0 in case of success or -1 in case of error.
> + */
> +
> +int virNetDevSetGateway(const char *ifname,
> +virSocketAddr *addr,
> +unsigned int prefix,
> +virSocketAddr *gateway)
> +{
> +virCommandPtr cmd = NULL;
> +char *addrstr = NULL, *gatewaystr = NULL;
> +int ret = -1;
> +
> +if (!(addrstr = virSocketAddrFormat(addr)))
> +goto cleanup;
> +if (!(gatewaystr = virSocketAddrFormat(gateway)))
> +goto cleanup;
> +cmd = virCommandNew(IP_PATH);
> +virCommandAddArgList(cmd, "route", "add", NULL);
> +virCommandAddArgFormat(cmd, "%s/%u", addrstr, prefix);
> +virCommandAddArgList(cmd, "via", NULL);
That one could have been a simple virCommandAddArg().

> +virCommandAddArgFormat(cmd, "%s", gatewaystr);
> +virCommandAddArgList(cmd, "dev", ifname, NULL);
> +virCommandAddArgList(cmd, "proto", "static", "metric", NULL);
> +virCommandAddArgFormat(cmd, "%u", 1);
Are all of those necessary?

Partial answer to myself: "proto static" is needed because otherwise
"proto boot" is assumed, and if a routing daemon is started on the host,
any route added with "proto boot" will be purged, which *isn't* what we
want.

I'm not sure about metric...

> +
> +if (virCommandRun(cmd, NULL) < 0)
> +goto cleanup;
> +
> +ret = 0;
> +cleanup:
> +VIR_FREE(addrstr);
> +VIR_FREE(gatewaystr);
> +virCommandFree(cmd);
> +return ret;
> +}
> +
> +/**
>   * virNetDevClearIPv4Address:
>   * @ifname: the interface name
>   * @addr: the IP address (IPv4 or IPv6)
> diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h
> index 06d0650..8b94ea8 100644
> --- a/src/util/virnetdev.h
> +++ b/src/util/virnetdev.h
> @@ -42,6 +42,11 @@ int virNetDevSetIPv4Address(const char *ifname,
>  virSocketAddr *addr,
>  unsigned int prefix)
>  ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
> +int virNetDevSetGateway(const char *ifname,
> +virSocketAddr *addr,
> +unsigned int prefix,
> +virSocketAddr *gateway)
> +ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
>  int virNetDevClearIPv4Address(const char *ifname,
>virSocketAddr *addr,
>unsigned int prefix)
> diff --git a/tests/networkxml2xmlin/dhcp6host-routed-network.xml 
> b/tests/networkxml2xmlin/dhcp6host-routed-network.xml
> index 2693d87..dcad62d 100644
> --- a/tests/networkxml2xmlin/dhcp6host-routed-network.xml
> +++ b/tests/networkxml2xmlin/dhcp6host-routed-network.xml
> @@ -19,4 +19,8 @@
> ip='2001:db8:ac10:fd01::1:24' />
>  
>
> +  
> +  
> +   via="2001:db8:ac10:fd01::1:24">
> +  
>  
> diff --git a/tests/networkxml2xmlout/dhcp6host-routed-network.xml 
> b/tests/networkxml2xmlout/dhcp6host-routed-network.xml
> index 7305043..880c2dd 100644
> --- a/tests/networkxml2xmlout/dhcp6host-routed-network.xml
> +++ b/tests/networkxml2xmlout/dhcp6host-routed-network.xml
> @@ -21,4 +21,8 @@
> ip='2001:db8:ac10:fd01::1:24' />
>  
>
> +  
> +  
> +   via='2001:db8:ac10:fd01::1:24'>
> +  
>  

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] v2:Support for adding a static route to a bridge

2013-04-04 Thread Laine Stump
On 04/03/2013 04:02 PM, Gene Czarcinski wrote:
> On 04/02/2013 03:31 PM, Laine Stump wrote:
>> On 03/15/2013 02:10 PM, Gene Czarcinski wrote:
>>> This patch adds support for adding a static route for
>>> a network.  The "via" specifies the gateway's IP
>>> address.  Both IPv4 and IPv6 static routes are
>>> supported although it is expected that this
>>> functionality will have more use with IPv6.
>>
>> (First I want to make sure I correctly understand what you're wanting to
>> do, so I'm going to try and explain it in my own words...)
>>
>> >From reading your earlier messages, my understanding is that the aim of
>> this patch is to automatically setup a route to a virtual network whose
>> bridge device has no IP address assigned, and is therefore reachable
>> only via one of the guests, is this correct?
>>
>> In other words, let's say that I have the following two networks defined
>> (using IPv4 and all static IPs for brevity, but the entire discussion is
>> equally applicable to IPv6):
>>
>>
>> 
>>   netVisibleToHost
>>   
>>   
>>   
>> 
>>
>> 
>>   netHiddenFromHost
>>   
>> 
>>
>> and you have a guestDirect that has two interfaces:
>>
>>   
>>   
>> 
>>   
>>   
>> 
>>
>> and another guestIndirect that has only one interface:
>>
>>   
>>   
>> 
>>
>> Additionally, the default route on guestDirect points to 192.168.200.1,
>> and the default route on guestIndirect points to 192.168.201.1.
>>
>> (Presumably you don't want to simply add an IP address to
>> netHiddenFromHost because (while it would solve your routing problems)
>> it would violate some security policy you've built into your network
>> topology - namely that all traffic to and from netHiddenFromHost *must*
>> go through guestDirect.)
>>
>> Traffic outbound from guestIndirect would have no problem reaching its
>> destination - it would go across netHiddenFromHost to guestDirect
>> (192.168.201.1), which would know to forward it to the host
>> (192.168.200.1) via netVisibleToHost, and the host presumably knows how
>> to get to anywhere. The problem comes when trying to route the
>> *response* destined for 192.168.201.2 (guestIndirect) - the outside
>> world may know that those packets have to be sent to the host, but the
>> host doesn't have a route for 192.168.201.0/24 - only guestDirect does.
>>
>> So, the solution is to add a route on the *host* that points traffic
>> destined for 192.168.201.0/24 to guestDirect, a.k.a. 192.168.200.2.
>>
>> Since there's no place in /etc/sysconfig/network-scripts/route-* to put
>> static routes with destinations that are only reachable through a
>> transient interface such as the bridge devices created by libvirt, the
>> obvious solution is to cause libvirt to add such a route, and the way
>> you propose to do that is to add an  element in the network named
>> "netUnreachable".
>>
>> Am I understanding the issue so far?
>
> I believe you do understand.

Except that it's obvious from your response that I misunderstood your
patch, and thought that you were trying to make the route to an
otherwise unreachable network a part of the unreachable network's config
:-) (my defense is that the dual usage of the  element to define a
route confused me)

Based on my now corrected understanding that the route is added to the
config of the network which is directly connected to the gateway (rather
than the network *beyond* the gateway), I have two comments/requests:

1) I think a separate  element is a better idea than trying to
make  dual purpose. Aside from confusing simple-minded people like
me, when things are intertwined like that it has the potential to lead
to an ambiguous situation further down the road. Also, using a separate
 element is closer to the system config files as well as more
similar to the xml used by the virInterface APIs (aka netcf).

2) Although /sbin/ip uses the term "via", I do think that "gateway"
would be the preferred term, since that's been in use for many years
with the (admittedly now deprecated) /sbin/route command, as well as
what is used in the system ifcfg-* and route-* files.

3) I would prefer to eliminate use of /sbin/ip and do this directly via
netlink/libnl. I would be willing to have this done in a separate patch
that also re-wrote virNetDev(Set|Clear)IPAddress.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] v2:Support for adding a static route to a bridge

2013-04-03 Thread Gene Czarcinski

On 04/02/2013 03:31 PM, Laine Stump wrote:

On 03/15/2013 02:10 PM, Gene Czarcinski wrote:

This patch adds support for adding a static route for
a network.  The "via" specifies the gateway's IP
address.  Both IPv4 and IPv6 static routes are
supported although it is expected that this
functionality will have more use with IPv6.


(First I want to make sure I correctly understand what you're wanting to
do, so I'm going to try and explain it in my own words...)

>From reading your earlier messages, my understanding is that the aim of
this patch is to automatically setup a route to a virtual network whose
bridge device has no IP address assigned, and is therefore reachable
only via one of the guests, is this correct?

In other words, let's say that I have the following two networks defined
(using IPv4 and all static IPs for brevity, but the entire discussion is
equally applicable to IPv6):



  netVisibleToHost
  
  
  



  netHiddenFromHost
  


and you have a guestDirect that has two interfaces:

  
  

  
  


and another guestIndirect that has only one interface:

  
  


Additionally, the default route on guestDirect points to 192.168.200.1,
and the default route on guestIndirect points to 192.168.201.1.

(Presumably you don't want to simply add an IP address to
netHiddenFromHost because (while it would solve your routing problems)
it would violate some security policy you've built into your network
topology - namely that all traffic to and from netHiddenFromHost *must*
go through guestDirect.)

Traffic outbound from guestIndirect would have no problem reaching its
destination - it would go across netHiddenFromHost to guestDirect
(192.168.201.1), which would know to forward it to the host
(192.168.200.1) via netVisibleToHost, and the host presumably knows how
to get to anywhere. The problem comes when trying to route the
*response* destined for 192.168.201.2 (guestIndirect) - the outside
world may know that those packets have to be sent to the host, but the
host doesn't have a route for 192.168.201.0/24 - only guestDirect does.

So, the solution is to add a route on the *host* that points traffic
destined for 192.168.201.0/24 to guestDirect, a.k.a. 192.168.200.2.

Since there's no place in /etc/sysconfig/network-scripts/route-* to put
static routes with destinations that are only reachable through a
transient interface such as the bridge devices created by libvirt, the
obvious solution is to cause libvirt to add such a route, and the way
you propose to do that is to add an  element in the network named
"netUnreachable".

Am I understanding the issue so far?


I believe you do understand.

I have not read the rest of your message yet but I did want to bring up 
one point.


With IPv4 I can get a lot of this functionality by the cleaver use of 
NAT but with IPv6 there is no NAT and everything is routed.  The big 
issue with IPv6 (and the reason I did this) is to provide the 
virtualization host with information needed to route response packets 
back to the "hidden" guest.  Without this, the can can send any packet 
it wants but will never get a reply.  That is the basic problem being 
addressed.


Assuming that I am, then as far as I can see, the correct place to
configure this route isn't in the setup for netHiddenFromHost, but
rather in netVisibleToHost - this is more in line with the way static
routes are configured in the standard host network config (route-*
files), and eliminates the problem that would occur if netHiddenFromHost
was started before netVisibleToHost existed (the route would be added
pointing at the wrong interface, if at all)
You are correct.  The "route-via" must be defined in the "visible" 
network definition.  There is an additional constraint that the gateway 
address must be in the range of the visible network.  IIRC, tere are a 
couple examples in the code I added for tests.


So, what I'm proposing is that, to automatically setup the route in the
above example, netHiddenFromHost would remain unchanged, and
netVisibleToHost would look something like this:


  netVisibleToHost
  
  
  
  


The route element could also have a family attribute just as  does
(although it's fairly simple to figure out the family just by trying to
parse address and/or gateway). You might instead want to make  a
subelement of , then validate that the gateway address is directly
reachable from the given ip address (i.e. that it's on the same subnet).
The  above is similar to what I implemented.  Since I am defining 
a network which is "somehow" reachable via this network interface, I 
used the "regular"  element to define the network and then added the 
"via=" (instead of "gateway=").  One reason I chose to use "via=" rather 
than "gateway=" is that when you run the

ip  -6  routeorip  -4  route

you get:
via 

Here is a part of a definition I have:

  net7
...
  

  

  

Re: [libvirt] [PATCH] v2:Support for adding a static route to a bridge

2013-04-02 Thread Laine Stump
On 03/15/2013 02:10 PM, Gene Czarcinski wrote:
> This patch adds support for adding a static route for
> a network.  The "via" specifies the gateway's IP
> address.  Both IPv4 and IPv6 static routes are
> supported although it is expected that this
> functionality will have more use with IPv6.


(First I want to make sure I correctly understand what you're wanting to
do, so I'm going to try and explain it in my own words...)

>From reading your earlier messages, my understanding is that the aim of
this patch is to automatically setup a route to a virtual network whose
bridge device has no IP address assigned, and is therefore reachable
only via one of the guests, is this correct?

In other words, let's say that I have the following two networks defined
(using IPv4 and all static IPs for brevity, but the entire discussion is
equally applicable to IPv6):


   
 netVisibleToHost
 
 
 
   

   
 netHiddenFromHost
 
   

and you have a guestDirect that has two interfaces:

 
 
   
 
 
   

and another guestIndirect that has only one interface:

 
 
   

Additionally, the default route on guestDirect points to 192.168.200.1,
and the default route on guestIndirect points to 192.168.201.1.

(Presumably you don't want to simply add an IP address to
netHiddenFromHost because (while it would solve your routing problems)
it would violate some security policy you've built into your network
topology - namely that all traffic to and from netHiddenFromHost *must*
go through guestDirect.)

Traffic outbound from guestIndirect would have no problem reaching its
destination - it would go across netHiddenFromHost to guestDirect
(192.168.201.1), which would know to forward it to the host
(192.168.200.1) via netVisibleToHost, and the host presumably knows how
to get to anywhere. The problem comes when trying to route the
*response* destined for 192.168.201.2 (guestIndirect) - the outside
world may know that those packets have to be sent to the host, but the
host doesn't have a route for 192.168.201.0/24 - only guestDirect does.

So, the solution is to add a route on the *host* that points traffic
destined for 192.168.201.0/24 to guestDirect, a.k.a. 192.168.200.2.

Since there's no place in /etc/sysconfig/network-scripts/route-* to put
static routes with destinations that are only reachable through a
transient interface such as the bridge devices created by libvirt, the
obvious solution is to cause libvirt to add such a route, and the way
you propose to do that is to add an  element in the network named
"netUnreachable".

Am I understanding the issue so far?

Assuming that I am, then as far as I can see, the correct place to
configure this route isn't in the setup for netHiddenFromHost, but
rather in netVisibleToHost - this is more in line with the way static
routes are configured in the standard host network config (route-*
files), and eliminates the problem that would occur if netHiddenFromHost
was started before netVisibleToHost existed (the route would be added
pointing at the wrong interface, if at all)

So, what I'm proposing is that, to automatically setup the route in the
above example, netHiddenFromHost would remain unchanged, and
netVisibleToHost would look something like this:

   
 netVisibleToHost
 
 
 
 
   

The route element could also have a family attribute just as  does
(although it's fairly simple to figure out the family just by trying to
parse address and/or gateway). You might instead want to make  a
subelement of , then validate that the gateway address is directly
reachable from the given ip address (i.e. that it's on the same subnet).

By putting the configuration here, you could be assured that the
interface that will be used for the route will always exist at the time
the route is added. Also it is conceptually more similar to the way that
the routes in /etc/sysconfig/route-ethX all have gateways that are
directly reachable via "ethX".

*OR* (following is what I think is a bad idea, but maybe someone can
tweak and salvage it :-)

Here is an alternate proposal that has the advantage of tying the
existence of the static route to the existence of not just the bridge,
but of even the guest interface will be the gateway: instead of putting
the route in the configuration of the netVisibleToHost network, put it
directly in the configuration of the guest interface itself. That way
when the guest is started the route will be added, and when the guest is
shutdown, the route (which will anyway now be useless) will be removed.
That could be added to the  definition something like this:


 
 
 
   

If this was done correctly, you could even hotplug a guest interface
that would then be immediately used for a route, as well as updating an
existing guest interface to add a route. The route added would use the
information in the  element plus the bridge device the guest's
tap device was connected to.

I do have several reservations about t

Re: [libvirt] [PATCH] v2:Support for adding a static route to a bridge

2013-04-02 Thread Gene Czarcinski

On 03/20/2013 11:17 AM, Laine Stump wrote:

On 03/20/2013 10:57 AM, Gene Czarcinski wrote:

On 03/16/2013 09:32 AM, Gene Czarcinski wrote:

On 03/15/2013 03:48 PM, Gene Czarcinski wrote:

On 03/15/2013 02:10 PM, Gene Czarcinski wrote:

This patch adds support for adding a static route for
a network.  The "via" specifies the gateway's IP
address.  Both IPv4 and IPv6 static routes are
supported although it is expected that this
functionality will have more use with IPv6.

ping

Sorry, I've had a reply "almost" done for several days, but got pulled
away to a fire drill. I'll finish it up and send it as soon as I can.

ping

Gene

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] v2:Support for adding a static route to a bridge

2013-03-20 Thread Laine Stump
On 03/20/2013 10:57 AM, Gene Czarcinski wrote:
> On 03/16/2013 09:32 AM, Gene Czarcinski wrote:
>> On 03/15/2013 03:48 PM, Gene Czarcinski wrote:
>>> On 03/15/2013 02:10 PM, Gene Czarcinski wrote:
 This patch adds support for adding a static route for
 a network.  The "via" specifies the gateway's IP
 address.  Both IPv4 and IPv6 static routes are
 supported although it is expected that this
 functionality will have more use with IPv6.
> ping

Sorry, I've had a reply "almost" done for several days, but got pulled
away to a fire drill. I'll finish it up and send it as soon as I can.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] v2:Support for adding a static route to a bridge

2013-03-20 Thread Gene Czarcinski

On 03/16/2013 09:32 AM, Gene Czarcinski wrote:

On 03/15/2013 03:48 PM, Gene Czarcinski wrote:

On 03/15/2013 02:10 PM, Gene Czarcinski wrote:

This patch adds support for adding a static route for
a network.  The "via" specifies the gateway's IP
address.  Both IPv4 and IPv6 static routes are
supported although it is expected that this
functionality will have more use with IPv6.

ping

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] v2:Support for adding a static route to a bridge

2013-03-16 Thread Gene Czarcinski

On 03/15/2013 03:48 PM, Gene Czarcinski wrote:

On 03/15/2013 02:10 PM, Gene Czarcinski wrote:

This patch adds support for adding a static route for
a network.  The "via" specifies the gateway's IP
address.  Both IPv4 and IPv6 static routes are
supported although it is expected that this
functionality will have more use with IPv6.

Extensive tests are done to validate that the input
definitions are correct.  For example, for a static
route ip definition, the address must be for a network
and not a host.  Additional checks are added to ensure
that the specified gateway has a network defined on
this bridge.

Whan a static route is added to a bridge, there is a slight
possibility that the gateway address will be incorrect.  If
this is handled as an error, that bridge becomes unusable and
can only be recovered by rebooting.  If the error is
ignored, then that network can be destroyed and the network
definition file edited to correct the problem.  Unfortunately,
the error message only appears in syslog.  However, with
the checks performed when the network definition file is parsed,
it is unlikely that this condition will ever occur.

The command used is of the following form:

ip route add / via  dev  \
proto static metric 1
When you examine that part of the patch in virNetworkIPdefParseXML() 
in network_conf.c, you will nitice that I have added a large number of 
tests/check that the data entered is valid.  These checks and the 
associated error messages are intended for the situation where you are 
using virsh net-edit.  As such, I believe these are quite good with 
respect to providing some guidance to the user.


Unfortuately, these same parse function is used by libvert without 
virsh and, when that occurs and the network definition (xml) file is 
found to be flawed, libvert will ignore that network definition. 
Better diagnostics and recovery is needed here but (currently) it is 
not clear how to provide it.


It would be nice if there was some way to "force" virsh net-edit to 
edit the xml file regardless of errors which could then be corrected 
as if a good file was being edited and bad configuration was entered. 
[any suggestions welcome]


OK, I believe I have found a way to get things correct and NOT require a 
libvirtd restart.  It does not ijvolve code but instead uses a process 
of existing functions.


Assume you have a network such as net3 defined (there is a net3.xml 
file) but the network does not show up in a net-list but you know it is 
there.  OK, simply use:

 virsh net-define /etc/libvirt/qemu/networks/net3.xml
If the network definition is good, it will be loaded.  If it is not, 
there a diagnostic message will be issued pointing to the error. Use vi 
to correct the error and then run net-define again.  Repeat until the 
network is defined.


This was obvious after I realized what I could do but not so obvious 
before that.  I am going to add some documentation in the 
docs/formatnetwork.html.in file to describe this process.


Question: should some additional diagnostic messaging be issued when 
net-edit, net-start, net-destroy, etc. to use net-define or net-create 
to determine the problem with the network (xml) definition file.


Gene

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] v2:Support for adding a static route to a bridge

2013-03-15 Thread Gene Czarcinski

On 03/15/2013 02:10 PM, Gene Czarcinski wrote:

This patch adds support for adding a static route for
a network.  The "via" specifies the gateway's IP
address.  Both IPv4 and IPv6 static routes are
supported although it is expected that this
functionality will have more use with IPv6.

Extensive tests are done to validate that the input
definitions are correct.  For example, for a static
route ip definition, the address must be for a network
and not a host.  Additional checks are added to ensure
that the specified gateway has a network defined on
this bridge.

Whan a static route is added to a bridge, there is a slight
possibility that the gateway address will be incorrect.  If
this is handled as an error, that bridge becomes unusable and
can only be recovered by rebooting.  If the error is
ignored, then that network can be destroyed and the network
definition file edited to correct the problem.  Unfortunately,
the error message only appears in syslog.  However, with
the checks performed when the network definition file is parsed,
it is unlikely that this condition will ever occur.

The command used is of the following form:

ip route add / via  dev  \
proto static metric 1
When you examine that part of the patch in virNetworkIPdefParseXML() in 
network_conf.c, you will nitice that I have added a large number of 
tests/check that the data entered is valid.  These checks and the 
associated error messages are intended for the situation where you are 
using virsh net-edit.  As such, I believe these are quite good with 
respect to providing some guidance to the user.


Unfortuately, these same parse function is used by libvert without virsh 
and, when that occurs and the network definition (xml) file is found to 
be flawed, libvert will ignore that network definition. Better 
diagnostics and recovery is needed here but (currently) it is not clear 
how to provide it.


It would be nice if there was some way to "force" virsh net-edit to edit 
the xml file regardless of errors which could then be corrected as if a 
good file was being edited and bad configuration was entered. [any 
suggestions welcome]


Gene

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list