[OpenWrt-Devel] Fwd: NCD, a light scripting language for network configs and much more

2012-08-17 Thread Florian Fainelli

Seen on linux-embedded


 Message original 
Sujet: NCD, a light scripting language for network configs and much more
Date : Fri, 17 Aug 2012 12:03:55 +0200
De : Ambroz Bizjak ambr...@gmail.com
Pour : linux-embed...@vger.kernel.org, linux-hotp...@vger.kernel.org, 
netfil...@vger.kernel.org, linux-ad...@vger.kernel.org, torva...@osdl.org


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
--
To unsubscribe from this list: send the line unsubscribe linux-embedded in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] Running avahi-daemon without D-Bus

2012-08-17 Thread Mike Brady
Hi Damiano.

Even if you don't want avahi to support or need D-BUS, you still need the dbus 
package to be present in the build environment so that avahi's compilation 
dependencies can be satisfied. However, as I think you've discovered, libdbus 
won't be included in the runtime package.

Regards
Mike


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 2/2 v6][BCM63XX] Add BCMA SPROM support

2012-08-17 Thread Álvaro Fernández Rojas

Avoid getting a new mac address each time the sprom is checked.
Added array parenthesis.
Added pr_fmt().

Signed-off-by: Álvaro Fernández Rojas nolt...@gmail.com

Index: target/linux/brcm63xx/config-3.3
===
--- target/linux/brcm63xx/config-3.3(revisión: 32911)
+++ target/linux/brcm63xx/config-3.3(copia de trabajo)
@@ -15,6 +15,12 @@
 CONFIG_BCM63XX_ENET=y
 CONFIG_BCM63XX_PHY=y
 CONFIG_BCM63XX_WDT=y
+CONFIG_BCMA=y
+CONFIG_BCMA_DEBUG=y
+CONFIG_BCMA_DRIVER_MIPS=y
+CONFIG_BCMA_DRIVER_PCI_HOSTMODE=y
+CONFIG_BCMA_HOST_PCI=y
+CONFIG_BCMA_HOST_PCI_POSSIBLE=y
 CONFIG_BCMA_POSSIBLE=y
 CONFIG_BOARD_BCM963XX=y
 # CONFIG_BOARD_LIVEBOX is not set
Index: target/linux/brcm63xx/patches-3.3/901-bcm63xx_bcma_sprom.patch
===
--- target/linux/brcm63xx/patches-3.3/901-bcm63xx_bcma_sprom.patch  
(revisión: 0)
+++ target/linux/brcm63xx/patches-3.3/901-bcm63xx_bcma_sprom.patch  
(revisión: 0)
@@ -0,0 +1,891 @@
+--- a/arch/mips/bcm63xx/boards/board_bcm963xx.c
 b/arch/mips/bcm63xx/boards/board_bcm963xx.c
+@@ -35,6 +35,7 @@
+ #include bcm63xx_dev_spi.h
+ #include bcm63xx_dev_usb_ohci.h
+ #include bcm63xx_dev_usb_ehci.h
++#include bcm63xx_sprom_bcma.h
+ #include board_bcm963xx.h
+ #include bcm_tag.h
+ #include pci_ath9k_fixup.h
+@@ -3220,6 +3221,14 @@ int __init board_register_devices(void)
+   pr_err(PFX failed to register fallback SPROM\n);
+   }
+ #endif
++
++#ifdef CONFIG_BCMA_HOST_PCI
++  if (!board.has_caldata 
++  bcma_arch_register_fallback_sprom(
++  bcm63xx_get_bcma_fallback_sprom)  0)
++  pr_err(PFX failed to register BCMA fallback SPROM\n);
++#endif
++
+   bcm63xx_hsspi_register();
+
+   bcm63xx_spi_register();
+--- a/arch/mips/bcm63xx/Makefile
 b/arch/mips/bcm63xx/Makefile
+@@ -3,5 +3,6 @@ obj-y  += clk.o cpu.o cs.o gpio.o irq.o
+  dev-pcmcia.o dev-rng.o dev-spi.o dev-uart.o dev-usb-ehci.o \
+  dev-usb-ohci.o dev-wdt.o pci-ath9k-fixup.o
+ obj-$(CONFIG_EARLY_PRINTK)+= early_printk.o
++obj-$(CONFIG_BCMA)+= sprom_bcma.o
+
+ obj-y += boards/
+--- /dev/null
 b/arch/mips/bcm63xx/sprom_bcma.c
+@@ -0,0 +1,70 @@
++/*
++ * This file is subject to the terms and conditions of the GNU General Public
++ * License.  See the file COPYING in the main directory of this archive
++ * for more details.
++ *
++ * Copyright (C) 2012 Álvaro Fernández Rojas nolt...@gmail.com
++ */
++
++#define pr_fmt(fmt) bcm63xx_sprom_bcma:  fmt
++
++#include linux/if_ether.h
++
++#include bcm63xx_sprom_bcma.h
++#include bcm63xx_sprom_bcma_defs.h
++#include bcm63xx_nvram.h
++
++int bcm63xx_get_bcma_fallback_sprom(struct bcma_bus *bus, struct ssb_sprom 
*out)
++{
++  if (bus-hosttype == BCMA_HOSTTYPE_PCI) {
++  /* Copy SPROM params. */
++  switch (bus-chipinfo.id) {
++  case BCMA_CHIP_ID_BCM4313:
++  memcpy(out, bcm4313_sprom, sizeof(struct ssb_sprom));
++  break;
++  case BCMA_CHIP_ID_BCM4331:
++  memcpy(out, bcm4331_sprom, sizeof(struct ssb_sprom));
++  break;
++  case BCMA_CHIP_ID_BCM6362:
++  memcpy(out, bcm6362_sprom, sizeof(struct ssb_sprom));
++  break;
++  case BCMA_CHIP_ID_BCM43224:
++  memcpy(out, bcm43224_sprom, sizeof(struct ssb_sprom));
++  break;
++  case BCMA_CHIP_ID_BCM43225:
++  memcpy(out, bcm43225_sprom, sizeof(struct ssb_sprom));
++  break;
++  case BCMA_CHIP_ID_BCM43227:
++  memcpy(out, bcm43227_sprom, sizeof(struct ssb_sprom));
++  break;
++  case BCMA_CHIP_ID_BCM43228:
++  memcpy(out, bcm43228_sprom, sizeof(struct ssb_sprom));
++  break;
++  case BCMA_CHIP_ID_BCM43428:
++  memcpy(out, bcm43428_sprom, sizeof(struct ssb_sprom));
++  break;
++  default:
++  pr_err(unable to fill BCMA fallback 
++  SPROM for chip id 0x%x\n, bus-chipinfo.id);
++  return -EINVAL;
++  }
++
++  pr_info(filled BCMA SPROM for chip id 0x%x\n, 
bus-chipinfo.id);
++
++  /* Get MAC address. */
++  if (bcm63xx_nvram_get_sprom_mac_address(
++  PCI_FUNC(bus-host_pci-devfn),
++  PCI_SLOT(bus-host_pci-devfn),
++  out-il0mac)) {
++  pr_err(failed to get mac address\n);
++  return -EINVAL;
++  }
++  memcpy(out-et0mac, out-il0mac, ETH_ALEN);
++  memcpy(out-et1mac, out-il0mac, ETH_ALEN);

[OpenWrt-Devel] [PATCH 1/2 v6][BCM63XX] Add BCMA/SSB nvram mac sprom support

2012-08-17 Thread Álvaro Fernández Rojas

Assign mac addresses to each pci/pcie device and avoid getting new ones.

Signed-off-by: Jonas Gorski jonas.gor...@gmail.com
Signed-off-by: Álvaro Fernández Rojas nolt...@gmail.com

Index: target/linux/brcm63xx/patches-3.3/900-bcm63xx_nvram_sprom_mac.patch
===
--- target/linux/brcm63xx/patches-3.3/900-bcm63xx_nvram_sprom_mac.patch 
(revisión: 0)
+++ target/linux/brcm63xx/patches-3.3/900-bcm63xx_nvram_sprom_mac.patch 
(revisión: 0)
@@ -0,0 +1,68 @@
+--- a/arch/mips/bcm63xx/nvram.c
 b/arch/mips/bcm63xx/nvram.c
+@@ -93,6 +93,45 @@ int bcm63xx_nvram_get_mac_address(u8 *ma
+ }
+ EXPORT_SYMBOL(bcm63xx_nvram_get_mac_address);
+
++static int num_sproms;
++static struct pci_sprom wifi_sproms[NVRAM_MAX_SPROMS];
++
++int bcm63xx_nvram_get_sprom_mac_address(int bus, int slot, u8 *mac)
++{
++  int i;
++  struct pci_sprom *sprom = NULL;
++
++  for (i = 0; i  num_sproms; i++) {
++  if (wifi_sproms[i].bus == bus  wifi_sproms[i].slot == slot) {
++  *sprom = wifi_sproms[i];
++  break;
++  }
++  }
++
++  if (!sprom) {
++  if (num_sproms == NVRAM_MAX_SPROMS) {
++  pr_err(exceeded number of sproms\n);
++  return -EINVAL;
++  }
++
++  sprom = wifi_sprom[num_sproms];
++
++  if (bcm63xx_nvram_get_mac_address(sprom-macaddr)) {
++  pr_err(unable to get mac address\n);
++  return -EINVAL;
++  }
++
++  sprom-bus = bus;
++  sprom-slot = slot;
++  num_sproms++;
++  }
++
++  memcpy(mac, sprom-macaddr, ETH_ALEN);
++
++  return 0;
++}
++EXPORT_SYMBOL(bcm63xx_nvram_get_sprom_mac_address);
++
+ int bcm63xx_nvram_get_psi_size(void)
+ {
+   if (nvram.psi_size  0)
+--- a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_nvram.h
 b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_nvram.h
+@@ -33,4 +33,17 @@ int bcm63xx_nvram_get_mac_address(u8 *ma
+
+ int bcm63xx_nvram_get_psi_size(void);
+
++/*
++ * SPROM MAC Addresses
++ */
++#define NVRAM_MAX_SPROMS 2
++
++struct pci_sprom {
++  int bus;
++  int slot;
++  u8 macaddr[ETH_ALEN];
++};
++
++int bcm63xx_nvram_get_sprom_mac_address(int bus, int slot, u8 *mac);
++
+ #endif /* BCM63XX_NVRAM_H */

___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH][BCM63XX] Add endian check for ath9k

2012-08-17 Thread Álvaro Fernández Rojas

Add endian check for ath9k.

Signed-off-by: Álvaro Fernández Rojas nolt...@gmail.com

Index: 
target/linux/brcm63xx/patches-3.3/443-BCM63XX-add-endian-check-for-ath9k.patch

===
--- 
target/linux/brcm63xx/patches-3.3/443-BCM63XX-add-endian-check-for-ath9k.patch 
 (revisión: 0)
+++ 
target/linux/brcm63xx/patches-3.3/443-BCM63XX-add-endian-check-for-ath9k.patch 
 (revisión: 0)

@@ -0,0 +1,51 @@
+--- a/arch/mips/include/asm/mach-bcm63xx/pci_ath9k_fixup.h
 b/arch/mips/include/asm/mach-bcm63xx/pci_ath9k_fixup.h
+@@ -2,6 +2,7 @@
+ #define _PCI_ATH9K_FIXUP
+
+
+-void pci_enable_ath9k_fixup(unsigned slot, u32 offset) __init;
++void pci_enable_ath9k_fixup(unsigned slot, u32 offset,
++unsigned endian_check) __init;
+
+ #endif /* _PCI_ATH9K_FIXUP */
+--- a/arch/mips/include/asm/mach-bcm63xx/board_bcm963xx.h
 b/arch/mips/include/asm/mach-bcm63xx/board_bcm963xx.h
+@@ -18,6 +18,7 @@
+ struct ath9k_caldata {
+ unsigned intslot;
+ u32caldata_offset;
++unsigned intendian_check:1;
+ };
+
+ /*
+--- a/arch/mips/bcm63xx/pci-ath9k-fixup.c
 b/arch/mips/bcm63xx/pci-ath9k-fixup.c
+@@ -172,12 +172,14 @@ static void ath9k_pci_fixup(struct pci_d
+ }
+ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATHEROS, PCI_ANY_ID, 
ath9k_pci_fixup);

+
+-void __init pci_enable_ath9k_fixup(unsigned slot, u32 offset)
++void __init pci_enable_ath9k_fixup(unsigned slot, u32 offset,
++unsigned endian_check)
+ {
+ if (ath9k_num_fixups = ARRAY_SIZE(ath9k_fixups))
+ return;
+
+ ath9k_fixups[ath9k_num_fixups].slot = slot;
++ath9k_fixups[ath9k_num_fixups].pdata.endian_check = endian_check;
+
+ if 
(!bcm63xx_read_eeprom(ath9k_fixups[ath9k_num_fixups].pdata.eeprom_data, 
offset))

+ return;
+--- a/arch/mips/bcm63xx/boards/board_bcm963xx.c
 b/arch/mips/bcm63xx/boards/board_bcm963xx.c
+@@ -938,7 +938,8 @@ int __init board_register_devices(void)
+
+ /* register any fixups */
+ for (i = 0; i  board.has_caldata; i++)
+-pci_enable_ath9k_fixup(board.caldata[i].slot, 
board.caldata[i].caldata_offset);
++pci_enable_ath9k_fixup(board.caldata[i].slot, 
board.caldata[i].caldata_offset,

++board.caldata[i].endian_check);
+
+ return 0;
+ }
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH] lantiq: dsl: fix status polling loop

2012-08-17 Thread Conor O'Gorman
doesn't need to do it 20 times all the time, missing loop condition check

Signed-off-by: Conor O'Gorman i...@conorogorman.net
---
 .../patches/110-fix_status_polling_loop.patch  |   11 +++
 1 file changed, 11 insertions(+)
 create mode 100644 package/ltq-dsl/patches/110-fix_status_polling_loop.patch

diff --git a/package/ltq-dsl/patches/110-fix_status_polling_loop.patch 
b/package/ltq-dsl/patches/110-fix_status_polling_loop.patch
new file mode 100644
index 000..870943d
--- /dev/null
+++ b/package/ltq-dsl/patches/110-fix_status_polling_loop.patch
@@ -0,0 +1,11 @@
+--- a/src/device/drv_dsl_cpe_device_danube.c
 b/src/device/drv_dsl_cpe_device_danube.c
+@@ -4069,7 +4069,7 @@ static DSL_Error_t DSL_DRV_DANUBE_XTUSys
+ 
+DSL_CTX_WRITE(pContext, nErrCode, xtseCurr, xtseCurr);
+ 
+-   for (nRetry = 0; nRetry  20; nRetry++)
++   for (nRetry = 0; nRetry  20  bStatusUpdated == DSL_FALSE; nRetry++)
+{
+   /* Get STAT1 info*/
+   nErrCode = DSL_DRV_DANUBE_CmvRead(pContext, DSL_CMV_GROUP_STAT,
-- 
1.7.9.5

___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel