[OpenWrt-Devel] [PATCH] [iwinfo] nl80211: fix not terminated string in get_countrylist

2015-08-19 Thread Alejandro Enrique
nl80211_get_countrylist function was not appending the terminating
NULL character to the ccodes returned

Signed-off-by: Alejandro Enrique alejandro.enri...@fon.com
---
 iwinfo_nl80211.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c
index 55bfd0f..8672dd8 100644
--- a/iwinfo_nl80211.c
+++ b/iwinfo_nl80211.c
@@ -2478,8 +2478,8 @@ static int nl80211_get_countrylist(const char *ifname, 
char *buf, int *len)
for (l = IWINFO_ISO3166_NAMES, count = 0; l-iso3166; l++, e++, count++)
{
e-iso3166 = l-iso3166;
-   e-ccode[0] = (l-iso3166 / 256);
-   e-ccode[1] = (l-iso3166 % 256);
+   snprintf(e-ccode, sizeof(e-ccode), %c%c,
+(l-iso3166 / 256), (l-iso3166 % 256));
}
 
*len = (count * sizeof(struct iwinfo_country_entry));
-- 
2.1.4
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH relayd] Add command line argument to disable DHCP options parsing

2015-02-17 Thread Alejandro Enrique
Default routes added when parsing DHCP options are problematic on
setups where there are more interfaces than those being managed by
relayd. A default route on the routing table used for locally
generated traffic makes the traffic addressed to not managed local
networks to be sent out using that default route instead of being
properly routed.

Disabling DHCP options parsing prevents the introduction of a default
route, that way the traffic addressed to not managed local networks is
routed using the main routing table.

Signed-off-by: Alejandro Enrique alejandro.enri...@fon.com
---
 dhcp.c   |4 ++--
 main.c   |   10 --
 relayd.h |2 +-
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/dhcp.c b/dhcp.c
index 5f7744a..aefe34f 100644
--- a/dhcp.c
+++ b/dhcp.c
@@ -115,7 +115,7 @@ parse_dhcp_options(struct relayd_host *host, struct 
dhcp_header *dhcp, int len)
}
 }
 
-bool relayd_handle_dhcp_packet(struct relayd_interface *rif, void *data, int 
len, bool forward)
+bool relayd_handle_dhcp_packet(struct relayd_interface *rif, void *data, int 
len, bool forward, bool parse)
 {
struct ip_packet *pkt = data;
struct udphdr *udp;
@@ -151,7 +151,7 @@ bool relayd_handle_dhcp_packet(struct relayd_interface 
*rif, void *data, int len
 
if (dhcp-op == 2) {
host = relayd_refresh_host(rif, pkt-eth.ether_shost, (void *) 
pkt-iph.saddr);
-   if (host)
+   if (host  parse)
parse_dhcp_options(host, dhcp, udplen - sizeof(struct 
udphdr));
}
 
diff --git a/main.c b/main.c
index 24435b4..edd10b8 100644
--- a/main.c
+++ b/main.c
@@ -40,6 +40,7 @@ static int host_ping_tries;
 static int inet_sock;
 static int forward_bcast;
 static int forward_dhcp;
+static int parse_dhcp;
 
 uint8_t local_addr[4];
 int local_route_table;
@@ -507,7 +508,7 @@ static void recv_bcast_packet(struct uloop_fd *fd, unsigned 
int events)
if (!forward_bcast  !forward_dhcp)
continue;
 
-   if (relayd_handle_dhcp_packet(rif, pktbuf, pktlen, 
forward_dhcp))
+   if (relayd_handle_dhcp_packet(rif, pktbuf, pktlen, 
forward_dhcp, parse_dhcp))
continue;
 
if (forward_bcast)
@@ -690,6 +691,7 @@ static int usage(const char *progname)
   -T table  Set routing table number for 
automatically added routes\n
   -B  Enable broadcast forwarding\n
   -D  Enable DHCP forwarding\n
+  -P  Disable DHCP options parsing\n
   -L ipaddr Enable local access using 
ipaddr as source address\n
\n,
progname);
@@ -718,9 +720,10 @@ int main(int argc, char **argv)
host_ping_tries = 5;
forward_bcast = 0;
local_route_table = 0;
+   parse_dhcp = 1;
uloop_init();
 
-   while ((ch = getopt(argc, argv, I:i:t:p:BDdT:G:R:L:)) != -1) {
+   while ((ch = getopt(argc, argv, I:i:t:p:BDPdT:G:R:L:)) != -1) {
switch(ch) {
case 'I':
managed = true;
@@ -752,6 +755,9 @@ int main(int argc, char **argv)
case 'D':
forward_dhcp = 1;
break;
+   case 'P':
+   parse_dhcp = 0;
+   break;
case 'T':
route_table = atoi(optarg);
if (route_table = 0)
diff --git a/relayd.h b/relayd.h
index ff30b67..d7ad212 100644
--- a/relayd.h
+++ b/relayd.h
@@ -127,6 +127,6 @@ void relayd_add_host_route(struct relayd_host *host, const 
uint8_t *ipaddr, uint
 void relayd_add_pending_route(const uint8_t *gateway, const uint8_t *dest, 
uint8_t mask, int timeout);
 
 void relayd_forward_bcast_packet(struct relayd_interface *from_rif, void 
*packet, int len);
-bool relayd_handle_dhcp_packet(struct relayd_interface *rif, void *data, int 
len, bool forward);
+bool relayd_handle_dhcp_packet(struct relayd_interface *rif, void *data, int 
len, bool forward, bool parse);
 
 #endif
-- 
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] improve host detection on interface change

2015-02-11 Thread Alejandro Enrique
This patch improve host detection and refresh when it moves from and
interface to another by pinging for it on all managed interfaces.

Previous to this patch host expiration was done by pinging for it on
the last interface it was known to be. If it does not reply after a
number of retries it will be expired and its entries
deleted. Nevertheless, if the host has moved to another managed
interface it will not be detected until there is some ARP packet sent
by the host.

This detection can be improved by pinging for the host on all managed
interfaces instead of just the one where it is supposed to be
connected, as it will reply to the ARP ping on the new interface it is
connected to and a host refresh will be triggered.

Signed-off-by: Alejandro Enrique alejandro.enri...@fon.com
---
 main.c |5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/main.c b/main.c
index a78076c..318ba1c 100644
--- a/main.c
+++ b/main.c
@@ -252,6 +252,7 @@ static void send_arp_reply(struct relayd_interface *rif, 
const uint8_t spa[4],
 static void host_entry_timeout(struct uloop_timeout *timeout)
 {
struct relayd_host *host = container_of(timeout, struct relayd_host, 
timeout);
+   struct relayd_interface *rif;
 
/*
 * When a host is behind a managed interface, we must not expire its 
host
@@ -261,7 +262,9 @@ static void host_entry_timeout(struct uloop_timeout 
*timeout)
 * giving up on it.
 */
if (host-rif-managed  host-cleanup_pending  host_ping_tries) {
-   send_arp_request(host-rif, host-ipaddr);
+   list_for_each_entry(rif, interfaces, list) {
+   send_arp_request(rif, host-ipaddr);
+   }
host-cleanup_pending++;
uloop_timeout_set(host-timeout, 1000);
return;
-- 
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] fix missing -p command line argument

2015-02-11 Thread Alejandro Enrique
Option -p was not being accepted as it was missing in getopt parameter
list

Signed-off-by: Alejandro Enrique alejandro.enri...@fon.com
---
 main.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/main.c b/main.c
index 2e34954..a78076c 100644
--- a/main.c
+++ b/main.c
@@ -719,7 +719,7 @@ int main(int argc, char **argv)
local_route_table = 0;
uloop_init();
 
-   while ((ch = getopt(argc, argv, I:i:t:BDdT:G:R:L:)) != -1) {
+   while ((ch = getopt(argc, argv, I:i:t:p:BDdT:G:R:L:)) != -1) {
switch(ch) {
case 'I':
managed = true;
-- 
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] add host route on local ip arp request

2015-02-11 Thread Alejandro Enrique
This patch fixes relayd not adding a host on an ARP request for the local
IP address.
When relayd is launched using the -L option, it was not adding the
necessary host routes when it receives an ARP request for the local
IP address.

This issue makes a host not able to connect to the device running
relayd until there is ARP traffic involving a third host.

Signed-off-by: Alejandro Enrique alejandro.enri...@fon.com
---
 main.c |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/main.c b/main.c
index 801d2f2..2e34954 100644
--- a/main.c
+++ b/main.c
@@ -386,15 +386,15 @@ static void recv_arp_request(struct relayd_interface 
*rif, struct arp_packet *pk
if (!memcmp(pkt-arp.arp_spa, \x00\x00\x00\x00, 4))
return;
 
+   host = find_host_by_ipaddr(NULL, pkt-arp.arp_spa);
+   if (!host || host-rif != rif)
+   relayd_refresh_host(rif, pkt-eth.ether_shost, 
pkt-arp.arp_spa);
+
if (local_route_table  !memcmp(pkt-arp.arp_tpa, local_addr, 
sizeof(local_addr))) {
send_arp_reply(rif, local_addr, pkt-arp.arp_sha, 
pkt-arp.arp_spa);
return;
}
 
-   host = find_host_by_ipaddr(NULL, pkt-arp.arp_spa);
-   if (!host || host-rif != rif)
-   relayd_refresh_host(rif, pkt-eth.ether_shost, 
pkt-arp.arp_spa);
-
host = find_host_by_ipaddr(NULL, pkt-arp.arp_tpa);
 
/*
-- 
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] add host route on local ip arp request

2015-02-11 Thread Alejandro Enrique
Great.

Thank you

 [image: Fon] http://www.fon.com/  Alejandro Enrique  Router Development
   All information in this email is confidential
http://corp.fon.com/legal/email-disclaimer

On 11 February 2015 at 11:12, Felix Fietkau n...@openwrt.org wrote:

 On 2015-02-11 21:02, Alejandro Enrique wrote:
  This patch fixes relayd not adding a host on an ARP request for the local
  IP address.
  When relayd is launched using the -L option, it was not adding the
  necessary host routes when it receives an ARP request for the local
  IP address.
 
  This issue makes a host not able to connect to the device running
  relayd until there is ARP traffic involving a third host.
 
  Signed-off-by: Alejandro Enrique alejandro.enri...@fon.com
 Applied all three and committed the update to OpenWrt.

 Thanks,

 - Felix

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


[OpenWrt-Devel] [PATCH] relayd: add host route on local ip arp request

2015-02-10 Thread Alejandro Enrique
This patch fixes relayd not adding a host on an ARP request for the local
IP address.
When relayd is launched using the -L option, it was not adding the
necessary host routes when it receives an ARP request for the local
IP address.

This issue makes a host not able to connect to the device running
relayd until there is ARP traffic involving a third host.

Signed-off-by: Alejandro Enrique alejandro.enri...@fon.com
---
 .../001-add_host_on_local_arp_request.patch|   22 
 1 file changed, 22 insertions(+)
 create mode 100644 
package/network/services/relayd/patches/001-add_host_on_local_arp_request.patch

diff --git 
a/package/network/services/relayd/patches/001-add_host_on_local_arp_request.patch
 
b/package/network/services/relayd/patches/001-add_host_on_local_arp_request.patch
new file mode 100644
index 000..aa7dfc7
--- /dev/null
+++ 
b/package/network/services/relayd/patches/001-add_host_on_local_arp_request.patch
@@ -0,0 +1,22 @@
+--- a/main.c
 b/main.c
+@@ -386,15 +386,15 @@ static void recv_arp_request(struct rela
+   if (!memcmp(pkt-arp.arp_spa, \x00\x00\x00\x00, 4))
+   return;
+ 
++  host = find_host_by_ipaddr(NULL, pkt-arp.arp_spa);
++  if (!host || host-rif != rif)
++  relayd_refresh_host(rif, pkt-eth.ether_shost, 
pkt-arp.arp_spa);
++
+   if (local_route_table  !memcmp(pkt-arp.arp_tpa, local_addr, 
sizeof(local_addr))) {
+   send_arp_reply(rif, local_addr, pkt-arp.arp_sha, 
pkt-arp.arp_spa);
+   return;
+   }
+ 
+-  host = find_host_by_ipaddr(NULL, pkt-arp.arp_spa);
+-  if (!host || host-rif != rif)
+-  relayd_refresh_host(rif, pkt-eth.ether_shost, 
pkt-arp.arp_spa);
+-
+   host = find_host_by_ipaddr(NULL, pkt-arp.arp_tpa);
+ 
+   /*
-- 
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] relayd: improve host detection on interface change

2015-02-10 Thread Alejandro Enrique
This patch improve host detection and refresh when it moves from and
interface to another by pinging for it on all managed interfaces.

Previous to this patch host expiration was done by pinging for it on
the last interface it was known to be. If it does not reply after a
number of retries it will be expired and its entries
deleted. Nevertheless, if the host has moved to another managed
interface it will not be detected until there is some ARP packet sent
by the host.

This detection can be improved by pinging for the host on all managed
interfaces instead of just the one where it is supposed to be
connected, as it will reply to the ARP ping on the new interface it is
connected to and a host refresh will be triggered.

Signed-off-by: Alejandro Enrique alejandro.enri...@fon.com
---
 .../patches/003-arping_on_all_interfaces.patch |   21 
 1 file changed, 21 insertions(+)
 create mode 100644 
package/network/services/relayd/patches/003-arping_on_all_interfaces.patch

diff --git 
a/package/network/services/relayd/patches/003-arping_on_all_interfaces.patch 
b/package/network/services/relayd/patches/003-arping_on_all_interfaces.patch
new file mode 100644
index 000..9321585
--- /dev/null
+++ b/package/network/services/relayd/patches/003-arping_on_all_interfaces.patch
@@ -0,0 +1,21 @@
+--- a/main.c
 b/main.c
+@@ -252,6 +252,7 @@ static void send_arp_reply(struct relayd
+ static void host_entry_timeout(struct uloop_timeout *timeout)
+ {
+   struct relayd_host *host = container_of(timeout, struct relayd_host, 
timeout);
++  struct relayd_interface *rif;
+ 
+   /*
+* When a host is behind a managed interface, we must not expire its 
host
+@@ -261,7 +262,9 @@ static void host_entry_timeout(struct ul
+* giving up on it.
+*/
+   if (host-rif-managed  host-cleanup_pending  host_ping_tries) {
+-  send_arp_request(host-rif, host-ipaddr);
++  list_for_each_entry(rif, interfaces, list) {
++  send_arp_request(rif, host-ipaddr);
++  }
+   host-cleanup_pending++;
+   uloop_timeout_set(host-timeout, 1000);
+   return;
-- 
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] relayd: fix missing -p command line argument

2015-02-10 Thread Alejandro Enrique
Option -p was not being accepted as it was missing in getopt parameter
list

Signed-off-by: Alejandro Enrique alejandro.enri...@fon.com
---
 .../services/relayd/patches/002-fix_expiry_retries.patch|   11 +++
 1 file changed, 11 insertions(+)
 create mode 100644 
package/network/services/relayd/patches/002-fix_expiry_retries.patch

diff --git 
a/package/network/services/relayd/patches/002-fix_expiry_retries.patch 
b/package/network/services/relayd/patches/002-fix_expiry_retries.patch
new file mode 100644
index 000..1f2a0ad
--- /dev/null
+++ b/package/network/services/relayd/patches/002-fix_expiry_retries.patch
@@ -0,0 +1,11 @@
+--- a/main.c
 b/main.c
+@@ -719,7 +719,7 @@ int main(int argc, char **argv)
+   local_route_table = 0;
+   uloop_init();
+ 
+-  while ((ch = getopt(argc, argv, I:i:t:BDdT:G:R:L:)) != -1) {
++  while ((ch = getopt(argc, argv, I:i:t:p:BDdT:G:R:L:)) != -1) {
+   switch(ch) {
+   case 'I':
+   managed = true;
-- 
1.7.10.4
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel