unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
* static-networking-service-type: Using a static network bridge
@ 2023-03-22  0:32 Denis 'GNUtoo' Carikli
  2023-03-22  6:24 ` Julien Lepiller
  0 siblings, 1 reply; 6+ messages in thread
From: Denis 'GNUtoo' Carikli @ 2023-03-22  0:32 UTC (permalink / raw)
  To: help-guix

[-- Attachment #1: Type: text/plain, Size: 1231 bytes --]

Hi,

Is it possible to do something like that in a system configuration?:
> ip link add lan0 type bridge
> ip link set dev eth0 master lan0
> ip addr add 192.168.1.5/24 dev lan0
> ip route add default via 192.168.1.1 dev lan0

I've tried it with something like that (with the IP addresses and "eth0"
changed):
> (service static-networking-service-type
>   (list
>     (static-networking
>       (addresses (list (network-address
>                                         (device "lan0")
>                                         (value "192.168.1.5/24"))))
>        (links (list (network-link (name "lan0")
>                                (type 'bridge)
>                                (arguments '()))
>                                (network-link
>                                (name "eth0")
>                                (type #f)
>                                (arguments '("master" "lan0")))))
>     (name-servers '("192.168.10.1"))
>     (routes (list (network-route (destination "default")
>                                  (gateway "192.168.1.1")))))))
but the issue is that the bridge isn't even created.

Did I do something wrong, or is that configuration not supported?

Denis.

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: static-networking-service-type: Using a static network bridge
  2023-03-22  0:32 static-networking-service-type: Using a static network bridge Denis 'GNUtoo' Carikli
@ 2023-03-22  6:24 ` Julien Lepiller
  2023-03-23 23:08   ` Denis 'GNUtoo' Carikli
  0 siblings, 1 reply; 6+ messages in thread
From: Julien Lepiller @ 2023-03-22  6:24 UTC (permalink / raw)
  To: help-guix, Denis 'GNUtoo' Carikli

You specified type twice, with #f the last time. Maybe that's tge issue?

Le 22 mars 2023 01:32:48 GMT+01:00, Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> a écrit :
>Hi,
>
>Is it possible to do something like that in a system configuration?:
>> ip link add lan0 type bridge
>> ip link set dev eth0 master lan0
>> ip addr add 192.168.1.5/24 dev lan0
>> ip route add default via 192.168.1.1 dev lan0
>
>I've tried it with something like that (with the IP addresses and "eth0"
>changed):
>> (service static-networking-service-type
>>   (list
>>     (static-networking
>>       (addresses (list (network-address
>>                                         (device "lan0")
>>                                         (value "192.168.1.5/24"))))
>>        (links (list (network-link (name "lan0")
>>                                (type 'bridge)
>>                                (arguments '()))
>>                                (network-link
>>                                (name "eth0")
>>                                (type #f)
>>                                (arguments '("master" "lan0")))))
>>     (name-servers '("192.168.10.1"))
>>     (routes (list (network-route (destination "default")
>>                                  (gateway "192.168.1.1")))))))
>but the issue is that the bridge isn't even created.
>
>Did I do something wrong, or is that configuration not supported?
>
>Denis.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: static-networking-service-type: Using a static network bridge
  2023-03-22  6:24 ` Julien Lepiller
@ 2023-03-23 23:08   ` Denis 'GNUtoo' Carikli
  2023-03-24 17:14     ` Julien Lepiller
  0 siblings, 1 reply; 6+ messages in thread
From: Denis 'GNUtoo' Carikli @ 2023-03-23 23:08 UTC (permalink / raw)
  To: Julien Lepiller; +Cc: help-guix

[-- Attachment #1: Type: text/plain, Size: 2537 bytes --]

On Wed, 22 Mar 2023 07:24:01 +0100
Julien Lepiller <julien@lepiller.eu> wrote:

> You specified type twice, with #f the last time. Maybe that's tge
> issue?
Sorry my bad: I messed up the indentation, so it makes it look like
type is specified twice.

When doing sudo guix system reconfigure I get that:
> guix system: warning: exception caught while executing 'start' on
> service 'networking':
> Throw to key `no-such-device' with args `("lan0")'.
> guix system: warning: some services could not be upgraded
> hint: To allow changes to all the system services to take effect, you
> will need to reboot.

So I'll try to rephrase and split the question: Is the following correct
to create a bridge:
> (network-link (name "lan0")
>               (type 'bridge)
>               (arguments '()))
Or is that supposed to only work on existing interfaces? Or am I
supposed to add something inside arguments to create the bridge?

The issue is that I only managed to understand what to put in name and
type with the Guix manual. The documentation describes arguments as
"List of arguments for this type of link.", and it then point to "Link
in Guile-Netlink Manual" which points to
https://git.lepiller.eu/guile-netlink/manual/manual.html#Link

But it doesn't tell how the correspondence between arguments and that
manual section is made. Do arguments expect some string? some state
(like IF_OPER_UP?), the same arguments than type-args?, a link datatype?

Though the guile-netlink documentation is very easy to use to create a
bridge and give it an address:
> (link-add "lan0" "bridge")
> (addr-add "lan0" "192.168.10.7/24")
but I've no idea how to translate that in Guix configuration.

As for making a device join a bridge I'm also unsure how to do that. I
didn't find any infos for that in the Guix manual or the guile-netlink
documentation, so maybe that's not supported?

If that's not supported, udev can still be used to run commands with
things like that:
> (udev-rule "bridge.rules"
> "SUBSYSTEM==\"net\", [some way to indentify the interface], \\
> ACTION==\"add\", \\
> RUN+=\"/run/current-system/[...]/ip link set dev $name master
> lan0\""))
and it works for other things (like changing MAC addresses with
macchanger, etc).

So does udev run late enough to already have the bridge interface
created when something like that would run? Or is there something that
could work with Guix static-networking-service-type somehow?

Thanks a lot in advance for the help.

Denis.

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: static-networking-service-type: Using a static network bridge
  2023-03-23 23:08   ` Denis 'GNUtoo' Carikli
@ 2023-03-24 17:14     ` Julien Lepiller
  2023-03-27 17:37       ` Denis 'GNUtoo' Carikli
  0 siblings, 1 reply; 6+ messages in thread
From: Julien Lepiller @ 2023-03-24 17:14 UTC (permalink / raw)
  To: Denis 'GNUtoo' Carikli; +Cc: help-guix

The type should be a string, so "bridge" would be correct. However, it's not supported by guile-netlink yet, sorry. Do you think you could send me a scenario with iproute2 commands so I ean test an implementation?

Le 24 mars 2023 00:08:50 GMT+01:00, Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> a écrit :
>On Wed, 22 Mar 2023 07:24:01 +0100
>Julien Lepiller <julien@lepiller.eu> wrote:
>
>> You specified type twice, with #f the last time. Maybe that's tge
>> issue?
>Sorry my bad: I messed up the indentation, so it makes it look like
>type is specified twice.
>
>When doing sudo guix system reconfigure I get that:
>> guix system: warning: exception caught while executing 'start' on
>> service 'networking':
>> Throw to key `no-such-device' with args `("lan0")'.
>> guix system: warning: some services could not be upgraded
>> hint: To allow changes to all the system services to take effect, you
>> will need to reboot.
>
>So I'll try to rephrase and split the question: Is the following correct
>to create a bridge:
>> (network-link (name "lan0")
>>               (type 'bridge)
>>               (arguments '()))
>Or is that supposed to only work on existing interfaces? Or am I
>supposed to add something inside arguments to create the bridge?
>
>The issue is that I only managed to understand what to put in name and
>type with the Guix manual. The documentation describes arguments as
>"List of arguments for this type of link.", and it then point to "Link
>in Guile-Netlink Manual" which points to
>https://git.lepiller.eu/guile-netlink/manual/manual.html#Link
>
>But it doesn't tell how the correspondence between arguments and that
>manual section is made. Do arguments expect some string? some state
>(like IF_OPER_UP?), the same arguments than type-args?, a link datatype?
>
>Though the guile-netlink documentation is very easy to use to create a
>bridge and give it an address:
>> (link-add "lan0" "bridge")
>> (addr-add "lan0" "192.168.10.7/24")
>but I've no idea how to translate that in Guix configuration.
>
>As for making a device join a bridge I'm also unsure how to do that. I
>didn't find any infos for that in the Guix manual or the guile-netlink
>documentation, so maybe that's not supported?
>
>If that's not supported, udev can still be used to run commands with
>things like that:
>> (udev-rule "bridge.rules"
>> "SUBSYSTEM==\"net\", [some way to indentify the interface], \\
>> ACTION==\"add\", \\
>> RUN+=\"/run/current-system/[...]/ip link set dev $name master
>> lan0\""))
>and it works for other things (like changing MAC addresses with
>macchanger, etc).
>
>So does udev run late enough to already have the bridge interface
>created when something like that would run? Or is there something that
>could work with Guix static-networking-service-type somehow?
>
>Thanks a lot in advance for the help.
>
>Denis.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: static-networking-service-type: Using a static network bridge
  2023-03-24 17:14     ` Julien Lepiller
@ 2023-03-27 17:37       ` Denis 'GNUtoo' Carikli
  2023-03-29 18:27         ` Julien Lepiller
  0 siblings, 1 reply; 6+ messages in thread
From: Denis 'GNUtoo' Carikli @ 2023-03-27 17:37 UTC (permalink / raw)
  To: Julien Lepiller; +Cc: help-guix

[-- Attachment #1: Type: text/plain, Size: 2563 bytes --]

On Fri, 24 Mar 2023 18:14:48 +0100
Julien Lepiller <julien@lepiller.eu> wrote:

> The type should be a string, so "bridge" would be correct. However,
> it's not supported by guile-netlink yet, sorry. Do you think you
> could send me a scenario with iproute2 commands so I ean test an
> implementation?
What is a scenario here?

If it's about reproducing a setup with bridges something like that is
probably the easiest for the creation of the bridge:

                    +-->[eth0]<---->Local network<-->Router<-->Internet
                    |
+----------+        v      +----------+
| VM1 [eth0]<--> [br0] <-->[eth0] VM2 |
+----------+               +----------+

The bridge would be created with:
> sudo ip link add br0 type bridge
> ip link set dev br0 up

Then the host eth0 can joint it like that:
> sudo ip link set dev eth0 master br0
> sudo ip link set dev eth0 up

I've only tested that setup with eth0 being unconfigured (no IP
address), and by having br0 get the IP address instead.

So if you use DHCP, you can use 'dhclient br0' instead of the usual
'dhclient eth0', or you can set the static IP address to br0 instead of
eth0.

For the VM, you'd need to setup two qemu-kvm VMs with virt-manager.

Once you have a VM, there is a "Add hardware" button. You then need to
select "Network" for the type of hardware to add and fill some
information: "Network source" should be set to Bridge device, and
"Device name:" should be set to the bridge name on the host (like br0
for instance).

The equivalent libvirt XML for the VM network interface looks like that:
> <interface type="bridge">
>   <mac address="XX:XX:XX:XX:XX:XX"/>
>   <source bridge="lan0"/>
>   <model type="virtio"/>
>   <address type="pci" domain="0x0000" bus="0x00" slot="0x03"
> function="0x0"/> </interface>

Then you can setup a static IP address to the Ethernet interface inside
the VMs, and ping the static IP address of one VM from the other VM or
ping your router from a VM or vice versa.

Maybe there are easier ways to test that without VMs or physical
network but I don't have ideas about that yet.

In my case the bridge is used for 2 different things:
- making the VMs join the local network and be treated like any other
  physical machine.
- Enabling GNU/Linux smartphones connected to my laptop though USB to
  also join the local network: when a smartphone is connected, an usb0
  Ethernet interface appears, and an udev rule makes it join the bridge.

Thanks a lot for the infos and the help.

Denis.

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: static-networking-service-type: Using a static network bridge
  2023-03-27 17:37       ` Denis 'GNUtoo' Carikli
@ 2023-03-29 18:27         ` Julien Lepiller
  0 siblings, 0 replies; 6+ messages in thread
From: Julien Lepiller @ 2023-03-29 18:27 UTC (permalink / raw)
  To: Denis 'GNUtoo' Carikli; +Cc: help-guix

Le Mon, 27 Mar 2023 19:37:53 +0200,
Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> a écrit :

> On Fri, 24 Mar 2023 18:14:48 +0100
> Julien Lepiller <julien@lepiller.eu> wrote:
> 
> > The type should be a string, so "bridge" would be correct. However,
> > it's not supported by guile-netlink yet, sorry. Do you think you
> > could send me a scenario with iproute2 commands so I ean test an
> > implementation?  
> What is a scenario here?
> 
> If it's about reproducing a setup with bridges something like that is
> probably the easiest for the creation of the bridge:
> 
>                     +-->[eth0]<---->Local
> network<-->Router<-->Internet |
> +----------+        v      +----------+
> | VM1 [eth0]<--> [br0] <-->[eth0] VM2 |
> +----------+               +----------+
> 
> The bridge would be created with:
> > sudo ip link add br0 type bridge
> > ip link set dev br0 up  
> 
> Then the host eth0 can joint it like that:
> > sudo ip link set dev eth0 master br0
> > sudo ip link set dev eth0 up  

OK, I figured it out. So, bridges are actually supported in
guile-netlink, and here is how you would do that with guile-netlink:

> (link-add "br0" "bridge")
> (link-set "br0" #:master "eth0")

So, you should be able to add the bridge with

> (network-link (name "br0")
>               (type "bridge"))

However, I don't see link-set being used except for setting interfaces
UP in the networking-service in Guix, so I think this is not yet
supported. It should not be too difficult to do though.

Probably, adding some more optional fields in static-networking-link
for the arguments supported by link-set, then call link-set with these
arguments when they are set. Do you think you could come up with a
patch for that?

If you want to add an IP address to the new link, we probably also need
to reverse the link and addr order in network-set-up/linux.

With such a patch, you should then be able to write something like

> (network-link (name "br0")
>               (type "bridge")
>               (master "eth0"))

WDYT?


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-03-29 18:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-22  0:32 static-networking-service-type: Using a static network bridge Denis 'GNUtoo' Carikli
2023-03-22  6:24 ` Julien Lepiller
2023-03-23 23:08   ` Denis 'GNUtoo' Carikli
2023-03-24 17:14     ` Julien Lepiller
2023-03-27 17:37       ` Denis 'GNUtoo' Carikli
2023-03-29 18:27         ` Julien Lepiller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).