Re: [OpenWrt-Devel] [Patch v2] [dnsmasq] backport --tftp-no-fail to ignore missing tftp root

2015-04-01 Thread John Crispin
Hi,

please don't use [dnsmasq]. use dnsmasq: instead. otherwise git am does
not pick it up. i fixed this manually now so you dont need to send a v3

John

On 01/04/2015 01:11, Stefan Tomanek wrote:
> This patch backports the option --tftp-no-fail to dnsmasq and prevents the
> service from aborting if the specified TFTP root directory is not available;
> this might be the case if TFTP files are located on external media that might
> occasionally not be present at startup.
> 
> Signed-off-by: Stefan Tomanek 
> ---
>  .../network/services/dnsmasq/files/dnsmasq.init|1 +
>  ...-tftp-no-fail-to-ignore-missing-tftp-root.patch |  193 
> 
>  2 files changed, 194 insertions(+), 0 deletions(-)
>  create mode 100644 
> package/network/services/dnsmasq/patches/120-add-tftp-no-fail-to-ignore-missing-tftp-root.patch
> 
> diff --git a/package/network/services/dnsmasq/files/dnsmasq.init 
> b/package/network/services/dnsmasq/files/dnsmasq.init
> index 2e7fb7b..9795d1a 100644
> --- a/package/network/services/dnsmasq/files/dnsmasq.init
> +++ b/package/network/services/dnsmasq/files/dnsmasq.init
> @@ -128,6 +128,7 @@ dnsmasq() {
>   append_bool "$cfg" boguspriv "--bogus-priv"
>   append_bool "$cfg" expandhosts "--expand-hosts"
>   append_bool "$cfg" enable_tftp "--enable-tftp"
> + append_bool "$cfg" tftp_no_fail "--tftp-no-fail"
>   append_bool "$cfg" nonwildcard "--bind-interfaces"
>   append_bool "$cfg" fqdn "--dhcp-fqdn"
>   append_bool "$cfg" proxydnssec "--proxy-dnssec"
> diff --git 
> a/package/network/services/dnsmasq/patches/120-add-tftp-no-fail-to-ignore-missing-tftp-root.patch
>  
> b/package/network/services/dnsmasq/patches/120-add-tftp-no-fail-to-ignore-missing-tftp-root.patch
> new file mode 100644
> index 000..c85e4e6
> --- /dev/null
> +++ 
> b/package/network/services/dnsmasq/patches/120-add-tftp-no-fail-to-ignore-missing-tftp-root.patch
> @@ -0,0 +1,193 @@
> +From 56920681eaf2c5eb08fc75baee4939d15d03b0ea Mon Sep 17 00:00:00 2001
> +From: Stefan Tomanek 
> +Date: Tue, 31 Mar 2015 22:32:11 +0100
> +Subject: [PATCH] add --tftp-no-fail to ignore missing tftp root
> +
> +(cherry picked from commit 30d0879ed55cb67b1b735beab3d93f3bb3ef1dd2)
> +
> +Conflicts:
> + CHANGELOG
> + src/dnsmasq.c
> + src/dnsmasq.h
> + src/option.c
> +---
> + dnsmasq.conf.example |  3 +++
> + man/dnsmasq.8|  3 +++
> + src/dnsmasq.c| 42 +++---
> + src/dnsmasq.h|  4 +++-
> + src/option.c |  3 +++
> + 5 files changed, 43 insertions(+), 12 deletions(-)
> +
> +diff --git a/dnsmasq.conf.example b/dnsmasq.conf.example
> +index 1bd305d..67be99a 100644
> +--- a/dnsmasq.conf.example
>  b/dnsmasq.conf.example
> +@@ -486,6 +486,9 @@
> + # Set the root directory for files available via FTP.
> + #tftp-root=/var/ftpd
> + 
> ++# Do not abort if the tftp-root is unavailable
> ++#tftp-no-fail
> ++
> + # Make the TFTP server more secure: with this set, only files owned by
> + # the user dnsmasq is running as will be send over the net.
> + #tftp-secure
> +diff --git a/man/dnsmasq.8 b/man/dnsmasq.8
> +index 0b8e04f..2ff4b96 100644
> +--- a/man/dnsmasq.8
>  b/man/dnsmasq.8
> +@@ -1670,6 +1670,9 @@ Absolute paths (starting with /) are allowed, but they 
> must be within
> + the tftp-root. If the optional interface argument is given, the
> + directory is only used for TFTP requests via that interface.
> + .TP
> ++.B --tftp-no-fail
> ++Do not abort startup if specified tftp root directories are inaccessible.
> ++.TP
> + .B --tftp-unique-root
> + Add the IP address of the TFTP client as a path component on the end
> + of the TFTP-root (in standard dotted-quad format). Only valid if a
> +diff --git a/src/dnsmasq.c b/src/dnsmasq.c
> +index 5c7750d..b6fa285 100644
> +--- a/src/dnsmasq.c
>  b/src/dnsmasq.c
> +@@ -58,6 +58,9 @@ int main (int argc, char **argv)
> +   struct dhcp_context *context;
> +   struct dhcp_relay *relay;
> + #endif
> ++#ifdef HAVE_TFTP
> ++  int tftp_prefix_missing = 0;
> ++#endif
> + 
> + #ifdef LOCALEDIR
> +   setlocale(LC_ALL, "");
> +@@ -623,7 +626,7 @@ int main (int argc, char **argv)
> + #endif
> + 
> + #ifdef HAVE_TFTP
> +-  if (option_bool(OPT_TFTP))
> ++  if (option_bool(OPT_TFTP))
> + {
> +   DIR *dir;
> +   struct tftp_prefix *p;
> +@@ -632,24 +635,33 @@ int main (int argc, char **argv)
> + {
> +   if (!((dir = opendir(daemon->tftp_prefix
> + {
> +-  send_event(err_pipe[1], EVENT_TFTP_ERR, errno, 
> daemon->tftp_prefix);
> +-  _exit(0);
> ++  tftp_prefix_missing = 1;
> ++  if (!option_bool(OPT_TFTP_NO_FAIL))
> ++{
> ++  send_event(err_pipe[1], EVENT_TFTP_ERR, errno, 
> daemon->tftp_prefix);
> ++  _exit(0);
> ++}
> + }
> +   closedir(dir);
> + }
> +-
> ++  
> +   for (p = daemon->if_prefix; p; p = p->next)
> + {
> ++  p->missing = 0;

Re: [OpenWrt-Devel] [PATCH] spi-ks8995: switch to upstream

2015-04-01 Thread John Crispin
Hi,

did you runtime test this ?

John

On 01/04/2015 01:50, Sergey Ryazanov wrote:
> This driver is upstream since 2012 (commit: a8e510f682f), so switch to
> it and remove own sources. Also place it under "Network Devices" menu
> together with other phy drivers.
> 
> Signed-off-by: Sergey Ryazanov 
> ---
>  package/kernel/linux/modules/netdevices.mk |  17 ++
>  package/kernel/spi-ks8995/Makefile |  54 
>  package/kernel/spi-ks8995/src/Kconfig  |   3 -
>  package/kernel/spi-ks8995/src/Makefile |   1 -
>  package/kernel/spi-ks8995/src/spi_ks8995.c | 419 
> -
>  5 files changed, 17 insertions(+), 477 deletions(-)
>  delete mode 100644 package/kernel/spi-ks8995/Makefile
>  delete mode 100644 package/kernel/spi-ks8995/src/Kconfig
>  delete mode 100644 package/kernel/spi-ks8995/src/Makefile
>  delete mode 100644 package/kernel/spi-ks8995/src/spi_ks8995.c
> 
> diff --git a/package/kernel/linux/modules/netdevices.mk 
> b/package/kernel/linux/modules/netdevices.mk
> index dd8692a..4508998 100644
> --- a/package/kernel/linux/modules/netdevices.mk
> +++ b/package/kernel/linux/modules/netdevices.mk
> @@ -810,3 +810,20 @@ define KernelPackage/vmxnet3/description
>  endef
>  
>  $(eval $(call KernelPackage,vmxnet3))
> +
> +
> +define KernelPackage/spi-ks8995
> +  SUBMENU:=$(NETWORK_DEVICES_MENU)
> +  TITLE:=Micrel/Kendin KS8995 Ethernet switch control
> +  FILES:=$(LINUX_DIR)/drivers/net/phy/spi_ks8995.ko
> +  KCONFIG:=CONFIG_MICREL_KS8995MA \
> + CONFIG_SPI=y \
> + CONFIG_SPI_MASTER=y
> +  AUTOLOAD:=$(call AutoLoad,50,spi_ks8995)
> +endef
> +
> +define KernelPackage/spi-ks8995/description
> +  Kernel module for Micrel/Kendin KS8995 ethernet switch
> +endef
> +
> +$(eval $(call KernelPackage,spi-ks8995))
> diff --git a/package/kernel/spi-ks8995/Makefile 
> b/package/kernel/spi-ks8995/Makefile
> deleted file mode 100644
> index 0be9fe3..000
> --- a/package/kernel/spi-ks8995/Makefile
> +++ /dev/null
> @@ -1,54 +0,0 @@
> -#
> -# Copyright (C) 2008 OpenWrt.org
> -#
> -# This is free software, licensed under the GNU General Public License v2.
> -# See /LICENSE for more information.
> -#
> -
> -include $(TOPDIR)/rules.mk
> -include $(INCLUDE_DIR)/kernel.mk
> -
> -PKG_NAME:=spi-ks8995
> -PKG_RELEASE:=1
> -
> -include $(INCLUDE_DIR)/package.mk
> -
> -define KernelPackage/spi-ks8995
> -  SUBMENU:=SPI Support
> -  TITLE:=Micrel/Kendin KS8995 Ethernet switch control
> -  FILES:=$(PKG_BUILD_DIR)/spi_ks8995.ko
> -  KCONFIG:=CONFIG_SPI=y \
> - CONFIG_SPI_MASTER=y
> -  AUTOLOAD:=$(call AutoLoad,50,spi_ks8995)
> -endef
> -
> -define KernelPackage/spi-ks8995/description
> -  Kernel module for Micrel/Kendin KS8995 ethernet switch
> -endef
> -
> -EXTRA_KCONFIG:= \
> - CONFIG_SPI_KS8995=m
> -
> -EXTRA_CFLAGS:= \
> - $(patsubst CONFIG_%, -DCONFIG_%=1, $(patsubst %=m,%,$(filter 
> %=m,$(EXTRA_KCONFIG \
> - $(patsubst CONFIG_%, -DCONFIG_%=1, $(patsubst %=y,%,$(filter 
> %=y,$(EXTRA_KCONFIG \
> -
> -MAKE_OPTS:= \
> - ARCH="$(LINUX_KARCH)" \
> - CROSS_COMPILE="$(TARGET_CROSS)" \
> - SUBDIRS="$(PKG_BUILD_DIR)" \
> - EXTRA_CFLAGS="$(EXTRA_CFLAGS)" \
> - $(EXTRA_KCONFIG)
> -
> -define Build/Prepare
> - mkdir -p $(PKG_BUILD_DIR)
> - $(CP) ./src/* $(PKG_BUILD_DIR)/
> -endef
> -
> -define Build/Compile
> - $(MAKE) -C "$(LINUX_DIR)" \
> - $(MAKE_OPTS) \
> - modules
> -endef
> -
> -$(eval $(call KernelPackage,spi-ks8995))
> diff --git a/package/kernel/spi-ks8995/src/Kconfig 
> b/package/kernel/spi-ks8995/src/Kconfig
> deleted file mode 100644
> index 7859be1..000
> --- a/package/kernel/spi-ks8995/src/Kconfig
> +++ /dev/null
> @@ -1,3 +0,0 @@
> -config SPI_KS8995
> - tristate "Micrel/Kendin KS8995 Ethernet switch"
> - depends on SPI
> diff --git a/package/kernel/spi-ks8995/src/Makefile 
> b/package/kernel/spi-ks8995/src/Makefile
> deleted file mode 100644
> index 810c3bd..000
> --- a/package/kernel/spi-ks8995/src/Makefile
> +++ /dev/null
> @@ -1 +0,0 @@
> -obj-${CONFIG_SPI_KS8995} += spi_ks8995.o
> \ No newline at end of file
> diff --git a/package/kernel/spi-ks8995/src/spi_ks8995.c 
> b/package/kernel/spi-ks8995/src/spi_ks8995.c
> deleted file mode 100644
> index dc42b5d..000
> --- a/package/kernel/spi-ks8995/src/spi_ks8995.c
> +++ /dev/null
> @@ -1,419 +0,0 @@
> -/*
> - * SPI driver for Micrel/Kendin KS8995M ethernet switch
> - *
> - * Copyright (C) 2008 Gabor Juhos 
> - *
> - * This file was based on: drivers/spi/at25.c
> - *   Copyright (C) 2006 David Brownell
> - *
> - * This program is free software; you can redistribute it and/or modify it
> - * under the terms of the GNU General Public License version 2 as published
> - * by the Free Software Foundation.
> - */
> -
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -
> -#include 
> -
> -#define DRV_VERSION  "0.1.1"
> -#define DRV_DESC "Micrel/Kendin KS8995 Ethernet switch SPI driver"
> -
> -/*

Re: [OpenWrt-Devel] [PATCH] spi-ks8995: switch to upstream

2015-04-01 Thread Sergey Ryazanov
2015-04-01 12:02 GMT+03:00 John Crispin :
> Hi,
>
> did you runtime test this ?
>
No I did not. I do not have hw with this switch. Only compile tested.

spi_ks8995.c from 3.18.9 kernel differ from sources in spi-ks8995
package in several lines: register size made dynamic in upstream. All
other code are the same.

> John
>
> On 01/04/2015 01:50, Sergey Ryazanov wrote:
>> This driver is upstream since 2012 (commit: a8e510f682f), so switch to
>> it and remove own sources. Also place it under "Network Devices" menu
>> together with other phy drivers.
>>
>> Signed-off-by: Sergey Ryazanov 
>> ---
>>  package/kernel/linux/modules/netdevices.mk |  17 ++
>>  package/kernel/spi-ks8995/Makefile |  54 
>>  package/kernel/spi-ks8995/src/Kconfig  |   3 -
>>  package/kernel/spi-ks8995/src/Makefile |   1 -
>>  package/kernel/spi-ks8995/src/spi_ks8995.c | 419 
>> -
>>  5 files changed, 17 insertions(+), 477 deletions(-)
>>  delete mode 100644 package/kernel/spi-ks8995/Makefile
>>  delete mode 100644 package/kernel/spi-ks8995/src/Kconfig
>>  delete mode 100644 package/kernel/spi-ks8995/src/Makefile
>>  delete mode 100644 package/kernel/spi-ks8995/src/spi_ks8995.c
>>
>> diff --git a/package/kernel/linux/modules/netdevices.mk 
>> b/package/kernel/linux/modules/netdevices.mk
>> index dd8692a..4508998 100644
>> --- a/package/kernel/linux/modules/netdevices.mk
>> +++ b/package/kernel/linux/modules/netdevices.mk
>> @@ -810,3 +810,20 @@ define KernelPackage/vmxnet3/description
>>  endef
>>
>>  $(eval $(call KernelPackage,vmxnet3))
>> +
>> +
>> +define KernelPackage/spi-ks8995
>> +  SUBMENU:=$(NETWORK_DEVICES_MENU)
>> +  TITLE:=Micrel/Kendin KS8995 Ethernet switch control
>> +  FILES:=$(LINUX_DIR)/drivers/net/phy/spi_ks8995.ko
>> +  KCONFIG:=CONFIG_MICREL_KS8995MA \
>> + CONFIG_SPI=y \
>> + CONFIG_SPI_MASTER=y
>> +  AUTOLOAD:=$(call AutoLoad,50,spi_ks8995)
>> +endef
>> +
>> +define KernelPackage/spi-ks8995/description
>> +  Kernel module for Micrel/Kendin KS8995 ethernet switch
>> +endef
>> +
>> +$(eval $(call KernelPackage,spi-ks8995))
>> diff --git a/package/kernel/spi-ks8995/Makefile 
>> b/package/kernel/spi-ks8995/Makefile
>> deleted file mode 100644
>> index 0be9fe3..000
>> --- a/package/kernel/spi-ks8995/Makefile
>> +++ /dev/null
>> @@ -1,54 +0,0 @@
>> -#
>> -# Copyright (C) 2008 OpenWrt.org
>> -#
>> -# This is free software, licensed under the GNU General Public License v2.
>> -# See /LICENSE for more information.
>> -#
>> -
>> -include $(TOPDIR)/rules.mk
>> -include $(INCLUDE_DIR)/kernel.mk
>> -
>> -PKG_NAME:=spi-ks8995
>> -PKG_RELEASE:=1
>> -
>> -include $(INCLUDE_DIR)/package.mk
>> -
>> -define KernelPackage/spi-ks8995
>> -  SUBMENU:=SPI Support
>> -  TITLE:=Micrel/Kendin KS8995 Ethernet switch control
>> -  FILES:=$(PKG_BUILD_DIR)/spi_ks8995.ko
>> -  KCONFIG:=CONFIG_SPI=y \
>> - CONFIG_SPI_MASTER=y
>> -  AUTOLOAD:=$(call AutoLoad,50,spi_ks8995)
>> -endef
>> -
>> -define KernelPackage/spi-ks8995/description
>> -  Kernel module for Micrel/Kendin KS8995 ethernet switch
>> -endef
>> -
>> -EXTRA_KCONFIG:= \
>> - CONFIG_SPI_KS8995=m
>> -
>> -EXTRA_CFLAGS:= \
>> - $(patsubst CONFIG_%, -DCONFIG_%=1, $(patsubst %=m,%,$(filter 
>> %=m,$(EXTRA_KCONFIG \
>> - $(patsubst CONFIG_%, -DCONFIG_%=1, $(patsubst %=y,%,$(filter 
>> %=y,$(EXTRA_KCONFIG \
>> -
>> -MAKE_OPTS:= \
>> - ARCH="$(LINUX_KARCH)" \
>> - CROSS_COMPILE="$(TARGET_CROSS)" \
>> - SUBDIRS="$(PKG_BUILD_DIR)" \
>> - EXTRA_CFLAGS="$(EXTRA_CFLAGS)" \
>> - $(EXTRA_KCONFIG)
>> -
>> -define Build/Prepare
>> - mkdir -p $(PKG_BUILD_DIR)
>> - $(CP) ./src/* $(PKG_BUILD_DIR)/
>> -endef
>> -
>> -define Build/Compile
>> - $(MAKE) -C "$(LINUX_DIR)" \
>> - $(MAKE_OPTS) \
>> - modules
>> -endef
>> -
>> -$(eval $(call KernelPackage,spi-ks8995))
>> diff --git a/package/kernel/spi-ks8995/src/Kconfig 
>> b/package/kernel/spi-ks8995/src/Kconfig
>> deleted file mode 100644
>> index 7859be1..000
>> --- a/package/kernel/spi-ks8995/src/Kconfig
>> +++ /dev/null
>> @@ -1,3 +0,0 @@
>> -config SPI_KS8995
>> - tristate "Micrel/Kendin KS8995 Ethernet switch"
>> - depends on SPI
>> diff --git a/package/kernel/spi-ks8995/src/Makefile 
>> b/package/kernel/spi-ks8995/src/Makefile
>> deleted file mode 100644
>> index 810c3bd..000
>> --- a/package/kernel/spi-ks8995/src/Makefile
>> +++ /dev/null
>> @@ -1 +0,0 @@
>> -obj-${CONFIG_SPI_KS8995} += spi_ks8995.o
>> \ No newline at end of file
>> diff --git a/package/kernel/spi-ks8995/src/spi_ks8995.c 
>> b/package/kernel/spi-ks8995/src/spi_ks8995.c
>> deleted file mode 100644
>> index dc42b5d..000
>> --- a/package/kernel/spi-ks8995/src/spi_ks8995.c
>> +++ /dev/null
>> @@ -1,419 +0,0 @@
>> -/*
>> - * SPI driver for Micrel/Kendin KS8995M ethernet switch
>> - *
>> - * Copyright (C) 2008 Gabor Juhos 
>> - *
>> - * This file was based on: drivers/spi/at25.c
>> - *   Copyright (C) 2006 David Brownell
>> - 

[OpenWrt-Devel] netifd loosing control over monitor interface?

2015-04-01 Thread Bruno Randolf
Hello All,

As I roughly outlined before in another thread ("synchronous network
reload/restart"), I am trying to re-configure several dependent network
interfaces thru ubus/netifd on BB.

I have one physical wireless device and 3 virtual interfaces:
 - moni (moni0)
 - mesh (mesh0)
 - ap (ap0)

On top of mesh0 there is batman-adv with its bat0 interface and
depending on wether a internet connection is available or not (I use
"watchping") it is either configured as bat_cl (GW client, DHCP) or
bat_gw (GW, static IP).

Now, when I want to change the channel of the radio, all these
interfaces need to be re-configured.

Since I started to use the ubus C API I am able to control the "async"
network reload most of the time - I listen to ubus network "ifup" events
and issue a "ubus call network reload" both thru the C API. When my
monitor interface is up again I can continue, and the next step in the
program is to get it's HW address thru ioctl SIOCGIFHWADDR.

Now, after a lot of fine-tuning (add force_link to moni and assign it a
static IP 0.0.0.0 - yes, it makes a difference), that works most of the
time, say 98%, but sometimes it happens that the monitor interface is
"lost", and no ifup event for it ever comes... I believe the problem
actually happens at "ifdown":

Here is the output of the ubus events in this case:

Reloading network and waiting for moni...
{ "network.interface": {"action":"ifdown","interface":"mesh"} }
{ "network.interface": {"action":"ifdown","interface":"bat_gw"} }
{ "network.interface": {"action":"ifdown","interface":"moni"} }
{ "network.interface": {"action":"ifup","interface":"bat_gw"} }
{ "network.interface": {"action":"ifup","interface":"mesh"} }

Normally "moni" comes up before "mesh" and "bat_gw".

ifconfig still shows the moni0 interface, which is why I believe the
ifdown did not succeed:

moni0 Link encap:UNSPEC  HWaddr
AC-86-74-07-71-62-00-44-00-00-00-00-00-00-00-00
  UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
  RX packets:22 errors:0 dropped:0 overruns:0 frame:0
  TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
  collisions:0 txqueuelen:1000
  RX bytes:2925 (2.8 KiB)  TX bytes:0 (0.0 B)

But it's not know ("available": false) to netifd any more:

root@OpenWrt:~# ubus call network.interface.moni status
{
"up": false,
"pending": false,
"available": false,
"autostart": true,
"proto": "static",
"device": "moni0",
"data": {

}
}

It also does not show up in "ubus call network.device status" and any
attempt to re-configure it fails, e.g.:

root@OpenWrt:~# ubus call network.interface.moni up
root@OpenWrt:~# ubus call network.interface.moni status
{
"up": false,
"pending": false,
"available": false,
"autostart": true,
"proto": "static",
"device": "moni0",
"data": {

},
"errors": [
{
"subsystem": "interface",
"code": "NO_DEVICE"
}
]
}

And even a "ubus call network restart" does not fix the problem. I have
to resort to reboot the system :(

Attached you there is more syslog (with comments) of this case, and my
network and wireless config files.

Thanks for any comments or ideas. Is there anything I could do to get
more debugging output of netifd?

bruno


config wifi-device 'radio0'
option type 'mac80211'
option hwmode '11g'
option path 'platform/ar933x_wmac'
option htmode 'HT20'
option disabled '0'
option channel '9'

config wifi-iface 'mesh'
option device 'radio0'
option ifname 'mesh0'
option network 'mesh'
option mode 'adhoc'
option ssid 'mesh'
option bssid '02:CA:FE:CA:CA:40'
option mcast_rate '18000'
option encryption 'none'
option disabled '0'

config wifi-iface 'monitor'
option device 'radio0'
option ifname 'moni0'
option mode 'monitor'

config wifi-iface 'ap'
option device 'radio0'
option ifname 'ap0'
option mode 'ap'
option ssid 'XXX'
option encryption 'psk2'
option key 'XXX'
option macfilter 'allow'


config interface 'loopback'
option ifname 'lo'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'

config interface 'lan'
option ifname 'eth0'
option force_link '1'
option proto 'static'
option ipaddr '192.168.1.1'
option netmask '255.255.255.0'

config interface 'wan'
option ifname 'eth1'
option proto 'dhcp'
option metric '2'

config interface 'mesh'
option mtu '1532'
option proto 'batadv'
option mesh 'bat0'

config interface 'bat_cl'
option ifname 'bat0'
option proto 'dhcp'
option metric '1'
option auto '0'

config interface 'bat_gw'
 

[OpenWrt-Devel] [PATCH 1/2] tests: add test coverage for uci export with -P option.

2015-04-01 Thread Yousong Zhou
 - With "uci -P xxx/ export", changes in "xxx/" should be applied last.
 - With "uci -p xxx/ commit", changes in "xxx/" should be applied before
   ctx->savedir.

Signed-off-by: Yousong Zhou 
---
 test/references/cli.options.delta.commit.result |5 +
 test/references/cli.options.delta.export.result |5 +
 test/references/options.delta.result|5 -
 test/tests.d/090_cli_options|   16 
 4 files changed, 22 insertions(+), 9 deletions(-)
 create mode 100644 test/references/cli.options.delta.commit.result
 create mode 100644 test/references/cli.options.delta.export.result
 delete mode 100644 test/references/options.delta.result

diff --git a/test/references/cli.options.delta.commit.result 
b/test/references/cli.options.delta.commit.result
new file mode 100644
index 000..3119b6f
--- /dev/null
+++ b/test/references/cli.options.delta.commit.result
@@ -0,0 +1,5 @@
+
+config sectype 'sec0'
+   list li0 '1'
+   list li0 '0'
+
diff --git a/test/references/cli.options.delta.export.result 
b/test/references/cli.options.delta.export.result
new file mode 100644
index 000..5aa71ce
--- /dev/null
+++ b/test/references/cli.options.delta.export.result
@@ -0,0 +1,5 @@
+package delta
+
+config sectype 'sec0'
+   list li0 '0'
+   list li0 '1'
diff --git a/test/references/options.delta.result 
b/test/references/options.delta.result
deleted file mode 100644
index 3119b6f..000
--- a/test/references/options.delta.result
+++ /dev/null
@@ -1,5 +0,0 @@
-
-config sectype 'sec0'
-   list li0 '1'
-   list li0 '0'
-
diff --git a/test/tests.d/090_cli_options b/test/tests.d/090_cli_options
index 52052a3..55920a2 100644
--- a/test/tests.d/090_cli_options
+++ b/test/tests.d/090_cli_options
@@ -1,6 +1,7 @@
 test_add_delta() {
local new_savedir="$TMP_DIR/new_savedir"
local config_delta="$CONFIG_DIR/delta"
+   local cmdoutput
 
# add normal changes
touch "$config_delta"
@@ -16,11 +17,18 @@ test_add_delta() {
assertEquals "delta.sec0='sectype'
 delta.sec0.li0+='0'" "$($UCI changes)"
 
-   # check combined changes.  order matters here.
+   # check combined changes.  Order matters here.
+   cmdoutput="$($UCI -P "$new_savedir" changes)"
+   assertTrue "$?"
assertEquals "delta.sec0='sectype'
-delta.sec0.li0+='1'
+delta.sec0.li0+='0'
 delta.sec0='sectype'
-delta.sec0.li0+='0'" "$($UCI -P "$new_savedir" changes)"
+delta.sec0.li0+='1'" "$cmdoutput"
+
+   # check combined export.  Order matters here.
+   cmdoutput="$($UCI -P "$new_savedir" export)"
+   assertTrue "$?"
+   assertEquals "$(cat $REF_DIR/cli.options.delta.export.result)" 
"$cmdoutput"
 
# check CLI_FLAG_NOCOMMIT with -P option.
$UCI -P "$new_savedir" commit
@@ -30,7 +38,7 @@ delta.sec0.li0+='0'" "$($UCI -P "$new_savedir" changes)"
# check normal commit.
$UCI -p "$new_savedir" commit
assertTrue "$?"
-   assertSameFile "$REF_DIR/options.delta.result" "$config_delta"
+   assertSameFile "$REF_DIR/cli.options.delta.commit.result" 
"$config_delta"
 
rm -rf "$new_savedir"
rm -f "$config_delta"
-- 
1.7.10.4
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 2/2] delta: fix adding new savedir.

2015-04-01 Thread Yousong Zhou
Newly added savedir should be at the last position while
uci_add_delta_path() will add it to the position second to the last.

Signed-off-by: Yousong Zhou 
---
 delta.c |5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/delta.c b/delta.c
index 357f5c7..459d2c7 100644
--- a/delta.c
+++ b/delta.c
@@ -114,9 +114,8 @@ int uci_set_savedir(struct uci_context *ctx, const char 
*dir)
}
}
if (!exists)
-   UCI_INTERNAL(uci_add_delta_path, ctx, dir);
-   else
-   uci_list_add(&ctx->delta_path, &e->list);
+   e = uci_alloc_generic(ctx, UCI_TYPE_PATH, dir, sizeof(struct 
uci_element));
+   uci_list_add(&ctx->delta_path, &e->list);
 
sdir = uci_strdup(ctx, dir);
if (ctx->savedir != uci_savedir)
-- 
1.7.10.4
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] mbim / Sierra Wireless AirCard 340U

2015-04-01 Thread John Crispin
Hi,

it seems that umbim has problems talking to this device. without
hardware to test on it will be hard to figure out what is wrong.

does anyone have a spare/unlocked Sierra Wireless AirCard 340U ?

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


[OpenWrt-Devel] Errors? on ar71xx tl-wdr3500 in trunk

2015-04-01 Thread Виталий Процко

Hi!

I found strange things happening with building result on ar71xx for 
tl-wdr3500:


- factory is less in size, than sysupgrade
- sysupgrade sized as flash - 8G
- flashed system (both - factory and sysupgrade) boots (asterisk led 
stops blinking), but does not answer on any IP


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


Re: [OpenWrt-Devel] mbim / Sierra Wireless AirCard 340U

2015-04-01 Thread David Hutchison
Hello John,

One of our customers use the 340U, and the latest firmware revision
that fixes Windows 8 support.. broke linux support (
http://mtekk.us/archives/guides/netgear-aircard-340u-linux/ ) We had
to downgrade the firmware on the 340u itself.

I don't think they have released a firmware fix with both windows 8
support + linux support. ( This has been a couple months, but when we
asked they told us to downgrade the firmware ).

Our 340u's running the *working* linux support firmware are running
great in OpenWRT.

I would start there, insure the firmware on the 340u is running a
version that has linux support working. Downgrade if necessary.

-- Davey

On Wed, Apr 1, 2015 at 8:19 AM, John Crispin  wrote:
> Hi,
>
> it seems that umbim has problems talking to this device. without
> hardware to test on it will be hard to figure out what is wrong.
>
> does anyone have a spare/unlocked Sierra Wireless AirCard 340U ?
>
> John
> ___
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] mbim / Sierra Wireless AirCard 340U

2015-04-01 Thread John Crispin
Hi David,

thanks for the reply, i was looking at this ticket ->
https://dev.openwrt.org/ticket/19121

so i will just reply, that they should downgrade to the linux version
of the firmware.

John

On 01/04/2015 17:51, David Hutchison wrote:
> Hello John,
> 
> One of our customers use the 340U, and the latest firmware
> revision that fixes Windows 8 support.. broke linux support ( 
> http://mtekk.us/archives/guides/netgear-aircard-340u-linux/ ) We
> had to downgrade the firmware on the 340u itself.
> 
> I don't think they have released a firmware fix with both windows
> 8 support + linux support. ( This has been a couple months, but
> when we asked they told us to downgrade the firmware ).
> 
> Our 340u's running the *working* linux support firmware are
> running great in OpenWRT.
> 
> I would start there, insure the firmware on the 340u is running a 
> version that has linux support working. Downgrade if necessary.
> 
> -- Davey
> 
> On Wed, Apr 1, 2015 at 8:19 AM, John Crispin 
> wrote:
>> Hi,
>> 
>> it seems that umbim has problems talking to this device. without 
>> hardware to test on it will be hard to figure out what is wrong.
>> 
>> does anyone have a spare/unlocked Sierra Wireless AirCard 340U ?
>> 
>> John ___ 
>> openwrt-devel mailing list openwrt-devel@lists.openwrt.org 
>> https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
> ___ openwrt-devel
> mailing list openwrt-devel@lists.openwrt.org 
> https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
> 
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH] logread: add support for non-transparent-framing for Syslog over TCP

2015-04-01 Thread Etienne CHAMPETIER
https://tools.ietf.org/html/rfc6587#section-3.4.2
the idea is to add \n or \0 as message trailer so it's easier
to find message end

Signed-off-by: Etienne CHAMPETIER 
---
 log/logread.c | 38 +++---
 1 file changed, 31 insertions(+), 7 deletions(-)

diff --git a/log/logread.c b/log/logread.c
index 06dda62..c791a85 100644
--- a/log/logread.c
+++ b/log/logread.c
@@ -59,7 +59,7 @@ static struct uloop_timeout retry;
 static struct uloop_fd sender;
 static const char *log_file, *log_ip, *log_port, *log_prefix, *pid_file, 
*hostname;
 static int log_type = LOG_STDOUT;
-static int log_size, log_udp, log_follow = 0;
+static int log_size, log_udp, log_follow, log_trailer_null, log_trailer_lf = 0;
 
 static const char* getcodetext(int value, CODE *codetable) {
CODE *i;
@@ -149,10 +149,26 @@ static int log_notify(struct blob_attr *msg)
if (blobmsg_get_u32(tb[LOG_SOURCE]) == SOURCE_KLOG)
strncat(buf, "kernel: ", sizeof(buf) - strlen(buf) - 1);
strncat(buf, m, sizeof(buf) - strlen(buf) - 1);
-   if (log_udp)
+   if (log_udp) {
err = write(sender.fd, buf, strlen(buf));
-   else
-   err = send(sender.fd, buf, strlen(buf), 0);
+   } else {
+   size_t buflen = strlen(buf);
+   if (log_trailer_lf) {
+   if (buflen == sizeof(buf)-1) {
+   //buf is full, overwrite last char
+   buf[buflen-1] = '\n';
+   } else {
+   buf[buflen] = '\n';
+   buf[buflen+1] = '\0';
+   buflen++;
+   }
+   }
+   //buf is already null terminated
+   if (log_trailer_null)
+   buflen++;
+
+   err = send(sender.fd, buf, buflen, 0);
+   }
 
if (err < 0) {
syslog(LOG_INFO, "failed to send log data to %s:%s via 
%s\n",
@@ -182,14 +198,16 @@ static int usage(const char *prog)
"Options:\n"
"-s   Path to ubus socket\n"
"-l  Got only the last 'count' messages\n"
-   "-r   Stream message to a server\n"
"-F   Log file\n"
"-S  Log size\n"
"-p   PID file\n"
+   "-f Follow log messages\n"
+   "-r   Stream message to a server\n"
"-h   Add hostname to the message\n"
"-P Prefix custom text to streamed 
messages\n"
-   "-f Follow log messages\n"
"-u Use UDP as the protocol\n"
+   "-t Add null byte at the end of message 
when using TCP protocol\n"
+   "-T Add LF at the end of message when using 
TCP protocol\n"
"\n", prog);
return 1;
 }
@@ -234,11 +252,17 @@ int main(int argc, char **argv)
 
signal(SIGPIPE, SIG_IGN);
 
-   while ((ch = getopt(argc, argv, "ufcs:l:r:F:p:S:P:h:")) != -1) {
+   while ((ch = getopt(argc, argv, "utTfcs:l:r:F:p:S:P:h:")) != -1) {
switch (ch) {
case 'u':
log_udp = 1;
break;
+   case 't':
+   log_trailer_null = 1;
+   break;
+   case 'T':
+   log_trailer_lf = 1;
+   break;
case 's':
ubus_socket = optarg;
break;
-- 
2.1.0
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH] logread: add support for non-transparent-framing for Syslog over TCP

2015-04-01 Thread John Crispin
Hi,

i have just cooked up an alternative patch to do this. i think we should
make \0 or \n a default and then add an option to switch to the other.
which one would make more sense as a default ?


John

On 01/04/2015 18:33, Etienne CHAMPETIER wrote:
> https://tools.ietf.org/html/rfc6587#section-3.4.2
> the idea is to add \n or \0 as message trailer so it's easier
> to find message end
> 
> Signed-off-by: Etienne CHAMPETIER 
> ---
>  log/logread.c | 38 +++---
>  1 file changed, 31 insertions(+), 7 deletions(-)
> 
> diff --git a/log/logread.c b/log/logread.c
> index 06dda62..c791a85 100644
> --- a/log/logread.c
> +++ b/log/logread.c
> @@ -59,7 +59,7 @@ static struct uloop_timeout retry;
>  static struct uloop_fd sender;
>  static const char *log_file, *log_ip, *log_port, *log_prefix, *pid_file, 
> *hostname;
>  static int log_type = LOG_STDOUT;
> -static int log_size, log_udp, log_follow = 0;
> +static int log_size, log_udp, log_follow, log_trailer_null, log_trailer_lf = 
> 0;
>  
>  static const char* getcodetext(int value, CODE *codetable) {
>   CODE *i;
> @@ -149,10 +149,26 @@ static int log_notify(struct blob_attr *msg)
>   if (blobmsg_get_u32(tb[LOG_SOURCE]) == SOURCE_KLOG)
>   strncat(buf, "kernel: ", sizeof(buf) - strlen(buf) - 1);
>   strncat(buf, m, sizeof(buf) - strlen(buf) - 1);
> - if (log_udp)
> + if (log_udp) {
>   err = write(sender.fd, buf, strlen(buf));
> - else
> - err = send(sender.fd, buf, strlen(buf), 0);
> + } else {
> + size_t buflen = strlen(buf);
> + if (log_trailer_lf) {
> + if (buflen == sizeof(buf)-1) {
> + //buf is full, overwrite last char
> + buf[buflen-1] = '\n';
> + } else {
> + buf[buflen] = '\n';
> + buf[buflen+1] = '\0';
> + buflen++;
> + }
> + }
> + //buf is already null terminated
> + if (log_trailer_null)
> + buflen++;
> +
> + err = send(sender.fd, buf, buflen, 0);
> + }
>  
>   if (err < 0) {
>   syslog(LOG_INFO, "failed to send log data to %s:%s via 
> %s\n",
> @@ -182,14 +198,16 @@ static int usage(const char *prog)
>   "Options:\n"
>   "-s   Path to ubus socket\n"
>   "-l  Got only the last 'count' messages\n"
> - "-r   Stream message to a server\n"
>   "-F   Log file\n"
>   "-S  Log size\n"
>   "-p   PID file\n"
> + "-f Follow log messages\n"
> + "-r   Stream message to a server\n"
>   "-h   Add hostname to the message\n"
>   "-P Prefix custom text to streamed 
> messages\n"
> - "-f Follow log messages\n"
>   "-u Use UDP as the protocol\n"
> + "-t Add null byte at the end of message 
> when using TCP protocol\n"
> + "-T Add LF at the end of message when using 
> TCP protocol\n"
>   "\n", prog);
>   return 1;
>  }
> @@ -234,11 +252,17 @@ int main(int argc, char **argv)
>  
>   signal(SIGPIPE, SIG_IGN);
>  
> - while ((ch = getopt(argc, argv, "ufcs:l:r:F:p:S:P:h:")) != -1) {
> + while ((ch = getopt(argc, argv, "utTfcs:l:r:F:p:S:P:h:")) != -1) {
>   switch (ch) {
>   case 'u':
>   log_udp = 1;
>   break;
> + case 't':
> + log_trailer_null = 1;
> + break;
> + case 'T':
> + log_trailer_lf = 1;
> + break;
>   case 's':
>   ubus_socket = optarg;
>   break;
> 
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH] logread: add support for non-transparent-framing for Syslog over TCP

2015-04-01 Thread Etienne Champetier
Hi,

Le 1 avr. 2015 19:25, "John Crispin"  a écrit :
>
> Hi,
>
> i have just cooked up an alternative patch to do this. i think we should
> make \0 or \n a default and then add an option to switch to the other.
> which one would make more sense as a default ?
>

Thanks for your quick answer!
I think \n is more common and understoud by every syslog/TCP receiver (1
line = 1 log), so you should put this as default.
I prefer \0 because it's very unlikely to find it in original log.

Etienne
>
> John
>
> On 01/04/2015 18:33, Etienne CHAMPETIER wrote:
> > https://tools.ietf.org/html/rfc6587#section-3.4.2
> > the idea is to add \n or \0 as message trailer so it's easier
> > to find message end
> >
> > Signed-off-by: Etienne CHAMPETIER 
> > ---
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH 1/2] [packages] add support for Huawei NCM modems (openwrt-devel Digest, Vol 111, Issue 138)

2015-04-01 Thread Matti Laakso
> On 28-03-2015 17:43, Cezary Jackiewicz wrote:
> > Why you do that? ncm from gcom-ncm is enough, you do not have to do 
> > specifically the new protocol. Just set /dev/cdc-wdm0 as device. Tested
> > with E3131 in huawei/ncm mode.
>
> Well, i saw that code, but found it to be quite slow and unreliable with
> my modems. It blocked regularly, and the connection was not
> reinitialized when it dropped. I should probably test it again with the
> 3.18 kernel and add code specific to the modems i own.
>
>
> Maarten Deprez

Did you try it with the changes from r44628...r44631?

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


Re: [OpenWrt-Devel] [PATCH] ubox: make remote logging send \0 or \n on tcp connections as a trailer

2015-04-01 Thread Etienne Champetier
Hi

I've just tested the patch and it need some fixing,
see my comments/fixes inline.

I will not be able to tests other patches until ~1 week,
but you can test simply using netcat (nc -l 5140) and watching with tcpdump
-i any port 5140 -vvvX

Your code is cleaner but it's 2 syscalls instead of 1 each time

Thanks for your work,
Etienne

2015-03-30 6:48 GMT+02:00 John Crispin :

> Signed-off-by: John Crispin 
> ---
>  log/logread.c |   22 +++---
>  1 file changed, 19 insertions(+), 3 deletions(-)
>
> diff --git a/log/logread.c b/log/logread.c
> index 06dda62..cb601be 100644
> --- a/log/logread.c
> +++ b/log/logread.c
> @@ -59,7 +59,7 @@ static struct uloop_timeout retry;
>  static struct uloop_fd sender;
>  static const char *log_file, *log_ip, *log_port, *log_prefix, *pid_file,
> *hostname;
>  static int log_type = LOG_STDOUT;
> -static int log_size, log_udp, log_follow = 0;
> +static int log_size, log_udp, log_follow, log_newline;
>
>  static const char* getcodetext(int value, CODE *codetable) {
> CODE *i;
> @@ -93,6 +93,18 @@ static void log_handle_fd(struct uloop_fd *u, unsigned
> int events)
> }
>  }
>
> +static int send_tcp(int sock, char *buf)
> +{
>

you are not using "sock"


> +   int err = send(sender.fd, buf, strlen(buf), MSG_MORE);
> +   if (err)
>
should be "if (err < 0)"


> +   return err;
> +
> +   if (log_newline)
> +   return send(sender.fd, "\n", 1, 0);
> +
> +   return send(sender.fd, "\0", 1, 0);
>

\n should be the default, many receiver do not support \0 i think


> +}
> +
>  static int log_notify(struct blob_attr *msg)
>  {
> struct blob_attr *tb[__LOG_MAX];
> @@ -152,7 +164,7 @@ static int log_notify(struct blob_attr *msg)
> if (log_udp)
> err = write(sender.fd, buf, strlen(buf));
> else
> -   err = send(sender.fd, buf, strlen(buf), 0);
> +   err = send_tcp(sender.fd, buf);
>
> if (err < 0) {
> syslog(LOG_INFO, "failed to send log data to %s:%s
> via %s\n",
> @@ -190,6 +202,7 @@ static int usage(const char *prog)
> "-P Prefix custom text to streamed
> messages\n"
> "-f Follow log messages\n"
> "-u Use UDP as the protocol\n"
> +   "-n Use newline when remote logging\n"
>

-0 Use null byte instead of newline when remote logging ?


> "\n", prog);
> return 1;
>  }
> @@ -234,7 +247,7 @@ int main(int argc, char **argv)
>
> signal(SIGPIPE, SIG_IGN);
>
> -   while ((ch = getopt(argc, argv, "ufcs:l:r:F:p:S:P:h:")) != -1) {
> +   while ((ch = getopt(argc, argv, "ufcs:l:r:F:p:S:P:h:n")) != -1) {
> switch (ch) {
> case 'u':
> log_udp = 1;
> @@ -270,6 +283,9 @@ int main(int argc, char **argv)
> case 'h':
> hostname = optarg;
> break;
> +   case 'n':
> +   log_newline = 1;
> +   break;
> default:
> return usage(*argv);
> }
> --
> 1.7.10.4
>
>
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH] ubox: make remote logging send \0 or \n on tcp connections as a trailer

2015-04-01 Thread John Crispin
i'll test it on device myself tomorrow :) not near hw just now

On 02/04/2015 00:23, Etienne Champetier wrote:
> Hi
> 
> I've just tested the patch and it need some fixing,
> see my comments/fixes inline.
> 
> I will not be able to tests other patches until ~1 week,
> but you can test simply using netcat (nc -l 5140) and watching with
> tcpdump -i any port 5140 -vvvX
> 
> Your code is cleaner but it's 2 syscalls instead of 1 each time
> 
> Thanks for your work,
> Etienne
> 
> 2015-03-30 6:48 GMT+02:00 John Crispin  >:
> 
> Signed-off-by: John Crispin  >
> ---
>  log/logread.c |   22 +++---
>  1 file changed, 19 insertions(+), 3 deletions(-)
> 
> diff --git a/log/logread.c b/log/logread.c
> index 06dda62..cb601be 100644
> --- a/log/logread.c
> +++ b/log/logread.c
> @@ -59,7 +59,7 @@ static struct uloop_timeout retry;
>  static struct uloop_fd sender;
>  static const char *log_file, *log_ip, *log_port, *log_prefix,
> *pid_file, *hostname;
>  static int log_type = LOG_STDOUT;
> -static int log_size, log_udp, log_follow = 0;
> +static int log_size, log_udp, log_follow, log_newline;
> 
>  static const char* getcodetext(int value, CODE *codetable) {
> CODE *i;
> @@ -93,6 +93,18 @@ static void log_handle_fd(struct uloop_fd *u,
> unsigned int events)
> }
>  }
> 
> +static int send_tcp(int sock, char *buf)
> +{
> 
> 
> you are not using "sock"
>  
> 
> +   int err = send(sender.fd, buf, strlen(buf), MSG_MORE);
> +   if (err)
> 
> should be "if (err < 0)"
>  
> 
> +   return err;
> +
> +   if (log_newline)
> +   return send(sender.fd, "\n", 1, 0);
> +
> +   return send(sender.fd, "\0", 1, 0);
> 
> 
> \n should be the default, many receiver do not support \0 i think
>  
> 
> +}
> +
>  static int log_notify(struct blob_attr *msg)
>  {
> struct blob_attr *tb[__LOG_MAX];
> @@ -152,7 +164,7 @@ static int log_notify(struct blob_attr *msg)
> if (log_udp)
> err = write(sender.fd, buf, strlen(buf));
> else
> -   err = send(sender.fd, buf, strlen(buf), 0);
> +   err = send_tcp(sender.fd, buf);
> 
> if (err < 0) {
> syslog(LOG_INFO, "failed to send log data to
> %s:%s via %s\n",
> @@ -190,6 +202,7 @@ static int usage(const char *prog)
> "-P Prefix custom text to
> streamed messages\n"
> "-f Follow log messages\n"
> "-u Use UDP as the protocol\n"
> +   "-n Use newline when remote
> logging\n"
> 
> 
> -0 Use null byte instead of newline when remote logging ?
>  
> 
> "\n", prog);
> return 1;
>  }
> @@ -234,7 +247,7 @@ int main(int argc, char **argv)
> 
> signal(SIGPIPE, SIG_IGN);
> 
> -   while ((ch = getopt(argc, argv, "ufcs:l:r:F:p:S:P:h:")) != -1) {
> +   while ((ch = getopt(argc, argv, "ufcs:l:r:F:p:S:P:h:n")) !=
> -1) {
> switch (ch) {
> case 'u':
> log_udp = 1;
> @@ -270,6 +283,9 @@ int main(int argc, char **argv)
> case 'h':
> hostname = optarg;
> break;
> +   case 'n':
> +   log_newline = 1;
> +   break;
> default:
> return usage(*argv);
> }
> --
> 1.7.10.4
> 
> 
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH v2] logread: add support for non-transparent-framing for Syslog over TCP

2015-04-01 Thread Etienne CHAMPETIER
https://tools.ietf.org/html/rfc6587#section-3.4.2
the idea is to add \n or \0 as message trailer so it's easier
to find message end

v2: simplify, use \n by default, with optional \0

Signed-off-by: Etienne CHAMPETIER 
---
 log/logread.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/log/logread.c b/log/logread.c
index 06dda62..94b96db 100644
--- a/log/logread.c
+++ b/log/logread.c
@@ -59,7 +59,7 @@ static struct uloop_timeout retry;
 static struct uloop_fd sender;
 static const char *log_file, *log_ip, *log_port, *log_prefix, *pid_file, 
*hostname;
 static int log_type = LOG_STDOUT;
-static int log_size, log_udp, log_follow = 0;
+static int log_size, log_udp, log_follow, log_trailer_null = 0;
 
 static const char* getcodetext(int value, CODE *codetable) {
CODE *i;
@@ -151,8 +151,12 @@ static int log_notify(struct blob_attr *msg)
strncat(buf, m, sizeof(buf) - strlen(buf) - 1);
if (log_udp)
err = write(sender.fd, buf, strlen(buf));
-   else
-   err = send(sender.fd, buf, strlen(buf), 0);
+   else {
+   size_t buflen = strlen(buf);
+   if (!log_trailer_null)
+   buf[buflen] = '\n';
+   err = send(sender.fd, buf, buflen + 1, 0);
+   }
 
if (err < 0) {
syslog(LOG_INFO, "failed to send log data to %s:%s via 
%s\n",
@@ -190,6 +194,7 @@ static int usage(const char *prog)
"-P Prefix custom text to streamed 
messages\n"
"-f Follow log messages\n"
"-u Use UDP as the protocol\n"
+   "-0 Use \\0 instead of \\n as trailer when 
using TCP\n"
"\n", prog);
return 1;
 }
@@ -234,11 +239,14 @@ int main(int argc, char **argv)
 
signal(SIGPIPE, SIG_IGN);
 
-   while ((ch = getopt(argc, argv, "ufcs:l:r:F:p:S:P:h:")) != -1) {
+   while ((ch = getopt(argc, argv, "u0fcs:l:r:F:p:S:P:h:")) != -1) {
switch (ch) {
case 'u':
log_udp = 1;
break;
+   case '0':
+   log_trailer_null = 1;
+   break;
case 's':
ubus_socket = optarg;
break;
-- 
2.1.0
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel