* NCD, a light scripting language for network configs and much more
@ 2012-08-17 10:03 ` Ambroz Bizjak
0 siblings, 0 replies; 7+ messages in thread
From: Ambroz Bizjak @ 2012-08-17 10:03 UTC (permalink / raw)
To: linux-embedded, linux-hotplug, netfilter, linux-admin, torvalds
Hi. I'm developing a special kind of scripting language which many
might find useful: http://code.google.com/p/badvpn/wiki/NCD
It was (originally) designed for programming dynamic configuration of
network interfaces, iptables etc. For example, there are commands that
observe the presence and link status of network interfaces. Many
commands are reversible, which makes it very easy to do cleanup
automatically and implicitly, like removing IP addresses or routes
when the link goes down on an interface.
The major advantage of this language compared to existing systems like
NetworkManager and wicd is that it's extremely hackable; you can fine
tune almost any part of the process. For example, this simple script
will create a network bridge, ensure that interfaces eth0 and eth1 are
in the bridge whenever they exist (consider hotplugging USB
interfaces), and only after eth0 (!) is up and running will it obtain
an IP address on br0 (!) using DHCP (since we know DHCP server is on
eth0 not eth1).
process bridge {
# Choose name of bridge.
var("br6") bridge_dev;
# Create the bridge (and destroy it on deinit).
run({"/sbin/brctl", "addbr", bridge_dev},
{"/sbin/brctl", "delbr", bridge_dev});
# Set bridge up.
net.up(bridge_dev);
# Wake up ports.
provide("BRIDGE");
# Wait for port eth0 where we expect to have the DHCP server.
depend("BRIDGE-link");
# Obtain IP address.
net.ipv4.dhcp(bridge_dev) dhcp;
# Sanity check IP address.
ip_in_network(dhcp.addr, "127.0.0.0", "8") test_local;
ifnot(test_local);
# Assign IP address (and remove it when anything goes wrong,
# e.g. lease times out, eth0 disappears or loses link...).
net.ipv4.addr(bridge_dev, dhcp.addr, dhcp.prefix);
println("Got address: ", dhcp.addr, "/", dhcp.prefix);
rprintln("Lost address");
}
process bridge_port_eth0 {
depend("BRIDGE") br;
# Choose name of device.
var("eth0") dev;
# Wait for device to start existing (and trigger deinit
# when it stops existing).
net.backend.waitdevice(dev);
# Add it to the bridge (and remove it when it stops
# existing or we're quitting).
run({"/sbin/brctl", "addif", br.bridge_dev, dev},
{"/sbin/brctl", "delif", br.bridge_dev, dev});
# Set device up.
net.up(dev);
# Wait for link.
net.backend.waitlink(dev);
# Wake up bridge process so it can start DHCP.
provide("BRIDGE-link");
}
# other ports: same as above, just no need to wait for link
process bridge_port_eth1 {
depend("BRIDGE") br;
var("eth1") dev;
net.backend.waitdevice(dev);
run({"/sbin/brctl", "addif", br.bridge_dev, dev},
{"/sbin/brctl", "delif", br.bridge_dev, dev});
net.up(dev);
}
Note that nothing is ever leaked here. When the NCD interpreter
receives SIGTERM, it automatically cleans up everything (removes IP
addresses, destroys bridge...).
The language is suitable for much more than network configs. For
instance, it allows receiving input/evdev events from a single device
with only a few lines of code:
process main {
sys.evdev("/dev/input/by-id/usb-BTC_USB_Multimedia_Keyboard-event-kbd")
evdev;
println("Event: ", evdev.type, " ", evdev.value, " ", evdev.code);
val_equal(evdev.code, "KEY_ENTER") is_enter;
If (is_enter) {
println("You pressed enter!");
};
evdev->nextevent();
}
With some more code it's possible to automatically listen on all event
devices as they come and go.
I think it would also make a great base to build an init system upon
(implement init process in NCD language). I've toyed a little with
this and got something very simple working, see
http://code.google.com/p/ncdinit/ .
Best regards,
Ambroz Bizjak
^ permalink raw reply [flat|nested] 7+ messages in thread
* NCD, a light scripting language for network configs and much more
@ 2012-08-17 10:03 ` Ambroz Bizjak
0 siblings, 0 replies; 7+ messages in thread
From: Ambroz Bizjak @ 2012-08-17 10:03 UTC (permalink / raw)
To: linux-hotplug
Hi. I'm developing a special kind of scripting language which many
might find useful: http://code.google.com/p/badvpn/wiki/NCD
It was (originally) designed for programming dynamic configuration of
network interfaces, iptables etc. For example, there are commands that
observe the presence and link status of network interfaces. Many
commands are reversible, which makes it very easy to do cleanup
automatically and implicitly, like removing IP addresses or routes
when the link goes down on an interface.
The major advantage of this language compared to existing systems like
NetworkManager and wicd is that it's extremely hackable; you can fine
tune almost any part of the process. For example, this simple script
will create a network bridge, ensure that interfaces eth0 and eth1 are
in the bridge whenever they exist (consider hotplugging USB
interfaces), and only after eth0 (!) is up and running will it obtain
an IP address on br0 (!) using DHCP (since we know DHCP server is on
eth0 not eth1).
process bridge {
# Choose name of bridge.
var("br6") bridge_dev;
# Create the bridge (and destroy it on deinit).
run({"/sbin/brctl", "addbr", bridge_dev},
{"/sbin/brctl", "delbr", bridge_dev});
# Set bridge up.
net.up(bridge_dev);
# Wake up ports.
provide("BRIDGE");
# Wait for port eth0 where we expect to have the DHCP server.
depend("BRIDGE-link");
# Obtain IP address.
net.ipv4.dhcp(bridge_dev) dhcp;
# Sanity check IP address.
ip_in_network(dhcp.addr, "127.0.0.0", "8") test_local;
ifnot(test_local);
# Assign IP address (and remove it when anything goes wrong,
# e.g. lease times out, eth0 disappears or loses link...).
net.ipv4.addr(bridge_dev, dhcp.addr, dhcp.prefix);
println("Got address: ", dhcp.addr, "/", dhcp.prefix);
rprintln("Lost address");
}
process bridge_port_eth0 {
depend("BRIDGE") br;
# Choose name of device.
var("eth0") dev;
# Wait for device to start existing (and trigger deinit
# when it stops existing).
net.backend.waitdevice(dev);
# Add it to the bridge (and remove it when it stops
# existing or we're quitting).
run({"/sbin/brctl", "addif", br.bridge_dev, dev},
{"/sbin/brctl", "delif", br.bridge_dev, dev});
# Set device up.
net.up(dev);
# Wait for link.
net.backend.waitlink(dev);
# Wake up bridge process so it can start DHCP.
provide("BRIDGE-link");
}
# other ports: same as above, just no need to wait for link
process bridge_port_eth1 {
depend("BRIDGE") br;
var("eth1") dev;
net.backend.waitdevice(dev);
run({"/sbin/brctl", "addif", br.bridge_dev, dev},
{"/sbin/brctl", "delif", br.bridge_dev, dev});
net.up(dev);
}
Note that nothing is ever leaked here. When the NCD interpreter
receives SIGTERM, it automatically cleans up everything (removes IP
addresses, destroys bridge...).
The language is suitable for much more than network configs. For
instance, it allows receiving input/evdev events from a single device
with only a few lines of code:
process main {
sys.evdev("/dev/input/by-id/usb-BTC_USB_Multimedia_Keyboard-event-kbd")
evdev;
println("Event: ", evdev.type, " ", evdev.value, " ", evdev.code);
val_equal(evdev.code, "KEY_ENTER") is_enter;
If (is_enter) {
println("You pressed enter!");
};
evdev->nextevent();
}
With some more code it's possible to automatically listen on all event
devices as they come and go.
I think it would also make a great base to build an init system upon
(implement init process in NCD language). I've toyed a little with
this and got something very simple working, see
http://code.google.com/p/ncdinit/ .
Best regards,
Ambroz Bizjak
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: NCD, a light scripting language for network configs and much more
2012-08-17 10:03 ` Ambroz Bizjak
@ 2012-08-17 16:22 ` Stephen Hemminger
-1 siblings, 0 replies; 7+ messages in thread
From: Stephen Hemminger @ 2012-08-17 16:22 UTC (permalink / raw)
To: Ambroz Bizjak
Cc: linux-embedded, linux-hotplug, netfilter, linux-admin, torvalds
On Fri, 17 Aug 2012 12:03:55 +0200
Ambroz Bizjak <ambrop7@gmail.com> wrote:
> Hi. I'm developing a special kind of scripting language which many
> might find useful: http://code.google.com/p/badvpn/wiki/NCD
>
> It was (originally) designed for programming dynamic configuration of
> network interfaces, iptables etc. For example, there are commands that
> observe the presence and link status of network interfaces. Many
> commands are reversible, which makes it very easy to do cleanup
> automatically and implicitly, like removing IP addresses or routes
> when the link goes down on an interface.
>
> The major advantage of this language compared to existing systems like
> NetworkManager and wicd is that it's extremely hackable; you can fine
> tune almost any part of the process. For example, this simple script
> will create a network bridge, ensure that interfaces eth0 and eth1 are
> in the bridge whenever they exist (consider hotplugging USB
> interfaces), and only after eth0 (!) is up and running will it obtain
> an IP address on br0 (!) using DHCP (since we know DHCP server is on
> eth0 not eth1).
>
> process bridge {
> # Choose name of bridge.
> var("br6") bridge_dev;
>
> # Create the bridge (and destroy it on deinit).
> run({"/sbin/brctl", "addbr", bridge_dev},
> {"/sbin/brctl", "delbr", bridge_dev});
>
> # Set bridge up.
> net.up(bridge_dev);
>
> # Wake up ports.
> provide("BRIDGE");
FYI - you can use ip commands now to control bridge.
For all the new features planned, they won't be controllable via brctl.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: NCD, a light scripting language for network configs and much more
@ 2012-08-17 16:22 ` Stephen Hemminger
0 siblings, 0 replies; 7+ messages in thread
From: Stephen Hemminger @ 2012-08-17 16:22 UTC (permalink / raw)
To: linux-hotplug
On Fri, 17 Aug 2012 12:03:55 +0200
Ambroz Bizjak <ambrop7@gmail.com> wrote:
> Hi. I'm developing a special kind of scripting language which many
> might find useful: http://code.google.com/p/badvpn/wiki/NCD
>
> It was (originally) designed for programming dynamic configuration of
> network interfaces, iptables etc. For example, there are commands that
> observe the presence and link status of network interfaces. Many
> commands are reversible, which makes it very easy to do cleanup
> automatically and implicitly, like removing IP addresses or routes
> when the link goes down on an interface.
>
> The major advantage of this language compared to existing systems like
> NetworkManager and wicd is that it's extremely hackable; you can fine
> tune almost any part of the process. For example, this simple script
> will create a network bridge, ensure that interfaces eth0 and eth1 are
> in the bridge whenever they exist (consider hotplugging USB
> interfaces), and only after eth0 (!) is up and running will it obtain
> an IP address on br0 (!) using DHCP (since we know DHCP server is on
> eth0 not eth1).
>
> process bridge {
> # Choose name of bridge.
> var("br6") bridge_dev;
>
> # Create the bridge (and destroy it on deinit).
> run({"/sbin/brctl", "addbr", bridge_dev},
> {"/sbin/brctl", "delbr", bridge_dev});
>
> # Set bridge up.
> net.up(bridge_dev);
>
> # Wake up ports.
> provide("BRIDGE");
FYI - you can use ip commands now to control bridge.
For all the new features planned, they won't be controllable via brctl.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: NCD, a light scripting language for network configs and much more
2012-08-17 16:22 ` Stephen Hemminger
(?)
@ 2012-08-17 19:04 ` Ambroz Bizjak
2012-08-17 19:07 ` Stephen Hemminger
-1 siblings, 1 reply; 7+ messages in thread
From: Ambroz Bizjak @ 2012-08-17 19:04 UTC (permalink / raw)
To: Stephen Hemminger, netfilter
Huh, really? I can't seem to find those commands. I only see a
"bridge" program added to iproute2 which does "forwarding database
management", and doesn't seem to have the usual addbr/addif commands.
Anyway, if brctl did suddenly disappear, imagine how easier it would
be to fix that script I showed you compared to fixing something
hardcoded like NetworkManager :)
On Fri, Aug 17, 2012 at 6:22 PM, Stephen Hemminger
<shemminger@vyatta.com> wrote:
>
> FYI - you can use ip commands now to control bridge.
> For all the new features planned, they won't be controllable via brctl.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: NCD, a light scripting language for network configs and much more
2012-08-17 19:04 ` Ambroz Bizjak
@ 2012-08-17 19:07 ` Stephen Hemminger
2012-08-17 19:16 ` Ambroz Bizjak
0 siblings, 1 reply; 7+ messages in thread
From: Stephen Hemminger @ 2012-08-17 19:07 UTC (permalink / raw)
To: Ambroz Bizjak; +Cc: netfilter
On Fri, 17 Aug 2012 21:04:04 +0200
Ambroz Bizjak <ambrop7@gmail.com> wrote:
> Huh, really? I can't seem to find those commands. I only see a
> "bridge" program added to iproute2 which does "forwarding database
> management", and doesn't seem to have the usual addbr/addif commands.
> Anyway, if brctl did suddenly disappear, imagine how easier it would
> be to fix that script I showed you compared to fixing something
> hardcoded like NetworkManager :)
>
> On Fri, Aug 17, 2012 at 6:22 PM, Stephen Hemminger
> <shemminger@vyatta.com> wrote:
> >
> > FYI - you can use ip commands now to control bridge.
> > For all the new features planned, they won't be controllable via brctl.
You can make a bridge with:
# ip link add br3 type bridge
and delete with
# ip link del br3
To add device to bridge
# ip li set dev eth2 master br3
To take out of bridge
# ip li set dev eth2 nomaster
The point is that bridge isn't special.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: NCD, a light scripting language for network configs and much more
2012-08-17 19:07 ` Stephen Hemminger
@ 2012-08-17 19:16 ` Ambroz Bizjak
0 siblings, 0 replies; 7+ messages in thread
From: Ambroz Bizjak @ 2012-08-17 19:16 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netfilter
I see, thanks, it's even mentioned in the ip-link manpage. I think it
would be nice if it was a little less hidden though. I would never
guess "set master" is how you add a device to a bridge. Still, it's
good all the network config stuff is getting into a single command.
On Fri, Aug 17, 2012 at 9:07 PM, Stephen Hemminger
<shemminger@vyatta.com> wrote:
> You can make a bridge with:
> # ip link add br3 type bridge
>
> and delete with
> # ip link del br3
>
> To add device to bridge
> # ip li set dev eth2 master br3
>
> To take out of bridge
> # ip li set dev eth2 nomaster
>
> The point is that bridge isn't special.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-08-17 19:16 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-17 10:03 NCD, a light scripting language for network configs and much more Ambroz Bizjak
2012-08-17 10:03 ` Ambroz Bizjak
2012-08-17 16:22 ` Stephen Hemminger
2012-08-17 16:22 ` Stephen Hemminger
2012-08-17 19:04 ` Ambroz Bizjak
2012-08-17 19:07 ` Stephen Hemminger
2012-08-17 19:16 ` Ambroz Bizjak
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.