Re: Lwip 2.0.3 patches

2018-05-05 Thread Joan Lledó
> > - Not intended to be upstream
> >   autoconf
> >   port

> Why not?

About port, it includes some stack configuration which is only valid for
us. About autoconf, the stack is distributed without any build system and
the user is expected to provide its own solution. They have a repo called
lwip-contrib which has some build systems as an example and for testing
purposes, it includes a library for unix systems.

> > - Won't get to upstream
> >   posix

> Similarly, why not?

We were talking about this a year ago[1] and I wasn't able to find a
satisfactory solution. Do you think it's worth to keep trying? Any ideas?

> If they really don't want it, we definitely should make this patch more
> maitainable by avoiding to move code around, and instead put #ifdef
> #endif around, so that changes to that code will not bring patch
> conflicts.

It's OK for me.

> >   max_sockets

> I guess they didn't want to cripple their source code?  It's arguably
> not very intrusive...

Mmmm, maybe this shouldn't be in that section. I've been reading the
discussion[2] we had past year an they were open to apply the patch but
after solving a problem on fd_set definition. Finally, the discussion went
to a dead end and I forgot it, but the patch could get to upstream if we
solve that problem, any ideas?

--
[1] https://savannah.nongnu.org/patch/?9350
[2] https://lists.nongnu.org/archive/html/lwip-devel/2017-08/msg00029.html
Missatge de Samuel Thibault  del dia dt., 1 de maig
2018 a les 1:52:

> Samuel Thibault, le mar. 01 mai 2018 01:34:42 +0200, a ecrit:
> > > - Won't get to upstream
> > >   posix
> >
> > Similarly, why not?

> If they really don't want it, we definitely should make this patch more
> maitainable by avoiding to move code around, and instead put #ifdef
> #endif around, so that changes to that code will not bring patch
> conflicts.

> Samuel



Re: lwip is in

2018-06-12 Thread Joan Lledó
> Since the lwip package got accepted

Great! :)

I found a bug that prevents using ssh, I hope I have the time to fix it soon...



[PATCH 3/7] AUTOCONF: Adapt the patch to its new position in series

2018-04-30 Thread Joan Lledó
---
 debian/patches/autoconf | 164 ++--
 1 file changed, 90 insertions(+), 74 deletions(-)

diff --git a/debian/patches/autoconf b/debian/patches/autoconf
index aae4ac5..b305e40 100644
--- a/debian/patches/autoconf
+++ b/debian/patches/autoconf
@@ -1,45 +1,31 @@
-Index: lwip/configure.ac
-===
+diff --git a/AUTHORS b/AUTHORS
+new file mode 100644
+index 000..8b13789
 --- /dev/null
-+++ lwip/configure.ac
-@@ -0,0 +1,32 @@
-+#   Copyright (C) 2017 Free Software Foundation, Inc.
-+#
-+#   This file is part of the GNU Hurd.
-+#
-+#   The GNU Hurd is free software; you can redistribute it and/or
-+#   modify it under the terms of the GNU General Public License as
-+#   published by the Free Software Foundation; either version 2, or (at
-+#   your option) any later version.
-+#
-+#   The GNU Hurd is distributed in the hope that it will be useful, but
-+#   WITHOUT ANY WARRANTY; without even the implied warranty of
-+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-+#   General Public License for more details.
-+#
-+#   You should have received a copy of the GNU General Public License
-+#   along with this program; if not, write to the Free Software
-+#   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 b/AUTHORS
+@@ -0,0 +1 @@
 +
-+AC_INIT([liblwip],[2.0.1], [jlle...@member.fsf.org])
-+AM_INIT_AUTOMAKE([1.15 parallel-tests -Wall -Werror subdir-objects])
-+AM_SILENT_RULES
-+AM_PROG_AR
-+LT_INIT
-+AC_PROG_CC
-+AC_CONFIG_MACRO_DIR([m4])
-+AC_CONFIG_HEADERS([config.h])
+diff --git a/ChangeLog b/ChangeLog
+new file mode 100644
+index 000..8b13789
+--- /dev/null
 b/ChangeLog
+@@ -0,0 +1 @@
 +
-+AC_CONFIG_FILES([
-+  Makefile \
-+  lwip.pc
-+  ])
-+AC_OUTPUT
-Index: lwip/Makefile.am
-===
+diff --git a/Filelists.mk b/Filelists.mk
+new file mode 100644
+index 000..75435db
 --- /dev/null
-+++ lwip/Makefile.am
-@@ -0,0 +1,155 @@
 b/Filelists.mk
+@@ -0,0 +1,2 @@
++LWIPDIR=src
++include src/Filelists.mk
+diff --git a/Makefile.am b/Makefile.am
+new file mode 100644
+index 000..08e6308
+--- /dev/null
 b/Makefile.am
+@@ -0,0 +1,164 @@
 +#   Copyright (C) 2017 Free Software Foundation, Inc.
 +#
 +#   This file is part of the GNU Hurd.
@@ -71,10 +57,12 @@ Index: lwip/Makefile.am
 +#ARCHFILES: architecture specific files.
 +ARCHFILES = port/sys_arch.c
 +
-+#ARCHFILES: architecture specific headers.
++#ARCHHEADERS: architecture specific headers.
 +ARCHHEADERS = port/include/arch/cc.h \
 +  port/include/arch/sys_arch.h \
-+  port/include/lwipopts.h
++  port/include/lwipopts.h \
++  port/include/posix/inet.h \
++  port/include/posix/socket.h
 +
 +LWIPFILES = $(LWIPALLFILES) $(ARCHFILES)
 +LWIPHEADERS = $(LWIPALLHEADERS) $(ARCHHEADERS)
@@ -105,7 +93,6 @@ Index: lwip/Makefile.am
 +  $(LWIPDIR)/include/lwip/ethip6.h \
 +  $(LWIPDIR)/include/lwip/icmp.h \
 +  $(LWIPDIR)/include/lwip/icmp6.h \
-+  #$(LWIPDIR)/include/lwip/if_api.h \
 +  $(LWIPDIR)/include/lwip/igmp.h \
 +  $(LWIPDIR)/include/lwip/inet.h \
 +  $(LWIPDIR)/include/lwip/inet_chksum.h \
@@ -117,8 +104,9 @@ Index: lwip/Makefile.am
 +  $(LWIPDIR)/include/lwip/ip6.h \
 +  $(LWIPDIR)/include/lwip/ip6_addr.h \
 +  $(LWIPDIR)/include/lwip/ip6_frag.h \
-+  $(LWIPDIR)/include/lwip/ip6_zone.h \
 +  $(LWIPDIR)/include/lwip/ip_addr.h \
++  $(LWIPDIR)/include/lwip/lwip_inet.h \
++  $(LWIPDIR)/include/lwip/lwip_sockets.h \
 +  $(LWIPDIR)/include/lwip/mem.h \
 +  $(LWIPDIR)/include/lwip/memp.h \
 +  $(LWIPDIR)/include/lwip/mld6.h \
@@ -185,6 +173,13 @@ Index: lwip/Makefile.am
 +  $(PORTDIR)/include/arch/cc.h \
 +  $(PORTDIR)/include/arch/sys_arch.h
 +
++liblwip_la_posix_includedir= \
++  $(includedir)/lwip/posix
++
++liblwip_la_posix_include_HEADERS = \
++  $(PORTDIR)/include/posix/inet.h \
++  $(PORTDIR)/include/posix/socket.h
++
 +liblwip_la_CFLAGS = \
 +  -I$(LWIPDIR)/include \
 +  -I$(PORTDIR)/include \
@@ -195,10 +190,56 @@ Index: lwip/Makefile.am
 +liblwip_la_LIBADD = \
 +  -lpthread
 +
-Index: lwip/lwip.pc.in
-===
+diff --git a/NEWS b/NEWS
+new file mode 100644
+index 000..8b13789
+--- /dev/null
 b/NEWS
+@@ -0,0 +1 @@
++
+diff --git a/configure.ac b/configure.ac
+new file mode 100644
+index 000..b1d5ddf
+--- /dev/null
 b/configure.ac
+@@ -0,0 +1,32 @@
++#   Copyright (C) 2017 Free Software Foundation, Inc.
++#
++#   This file is part of the GNU Hurd.
++#
++#   The GNU Hurd is free software; you can redistribute it and/or
++#   modify it under the terms of the GNU General Public License as
++#   published by the Free Software Foundation; either version 2, or (at
++#   your option) any later version.
++#
++#   The GNU Hurd is 

Lwip 2.0.3 patches

2018-04-30 Thread Joan Lledó

Hello,

I've been working on the lwip package and have some patches for the release 
2.0.3. These patches include:

- Solve some bugs on the PORT patch.
- Create a new macro wich allows the user to choose between POSIX or lwip 
native socket headers.
- Solve the bug 36167 using the same solution upstream does.
- Add an implementation of the poll() function.
- Create a new macro for disabling the limit of simultaneous sockets.

About patches getting to upstream:
- Not intended to be upstream
  autoconf
  port

- Already upstream  
  errno
  bug-36167
  poll

- Won't get to upstream
  posix
  max_sockets

I have to say I haven't added support for DHCP in this series of patches, 
because there're two posible solutions depending on the result of a bug 
report[1] I sent over the isc-dhcp-client package.

Regards.

--
[1] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=875566



[PATCH 2/7] POSIX: Allow enabling/disabling POSIX sockets

2018-04-30 Thread Joan Lledó
---
 debian/patches/posix | 1830 ++
 1 file changed, 1562 insertions(+), 268 deletions(-)

diff --git a/debian/patches/posix b/debian/patches/posix
index ef83cc7..b86452d 100644
--- a/debian/patches/posix
+++ b/debian/patches/posix
@@ -1,29 +1,222 @@
-Manual hack for now, next lwip version will contain needed tweaks.
-
-Index: lwip/src/include/lwip/inet.h
-===
 lwip.orig/src/include/lwip/inet.h
-+++ lwip/src/include/lwip/inet.h
-@@ -49,6 +49,7 @@
- extern "C" {
- #endif
- 
-+#if 0
- /* If your port already typedef's in_addr_t, define IN_ADDR_T_DEFINED
-to prevent this code from redefining it. */
- #if !defined(in_addr_t) && !defined(IN_ADDR_T_DEFINED)
-@@ -129,6 +130,7 @@ extern const struct in6_addr in6addr_any
- #define INET6_ADDRSTRLENIP6ADDR_STRLEN_MAX
- #endif
- #endif
-+#endif
+--- /dev/null
 b/port/include/posix/inet.h
+@@ -0,0 +1,63 @@
++/*
++   Copyright (C) 2018 Free Software Foundation, Inc.
++   Written by Joan Lledó.
++
++   This file is part of the GNU Hurd.
++
++   The GNU Hurd is free software; you can redistribute it and/or
++   modify it under the terms of the GNU General Public License as
++   published by the Free Software Foundation; either version 2, or (at
++   your option) any later version.
++
++   The GNU Hurd is distributed in the hope that it will be useful, but
++   WITHOUT ANY WARRANTY; without even the implied warranty of
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
++   General Public License for more details.
++
++   You should have received a copy of the GNU General Public License
++   along with the GNU Hurd. If not, see <http://www.gnu.org/licenses/>.  */
++
++#ifndef HURD_LWIP_POSIX_INET_H
++#define HURD_LWIP_POSIX_INET_H
++
++#include 
++#include 
++#include 
++#include 
++
++#ifdef __cplusplus
++extern "C" {
++#endif
++
++#define SIN_ZERO_LEN sizeof (struct sockaddr) - \
++   __SOCKADDR_COMMON_SIZE - \
++   sizeof (in_port_t) - \
++   sizeof (struct in_addr)
++
++#if LWIP_IPV4
++
++#define inet_addr_from_ip4addr(target_inaddr, source_ipaddr) 
((target_inaddr)->s_addr = ip4_addr_get_u32(source_ipaddr))
++#define inet_addr_to_ip4addr(target_ipaddr, source_inaddr)   
(ip4_addr_set_u32(target_ipaddr, (source_inaddr)->s_addr))
++/* ATTENTION: the next define only works because both s_addr and ip4_addr_t 
are an u32_t effectively! */
++#define inet_addr_to_ip4addr_p(target_ip4addr_p, source_inaddr)   
((target_ip4addr_p) = (ip4_addr_t*)&((source_inaddr)->s_addr))
++
++#endif /* LWIP_IPV4 */
++
++#if LWIP_IPV6
++#define inet6_addr_from_ip6addr(target_in6addr, source_ip6addr) 
{(target_in6addr)->s6_addr32[0] = (source_ip6addr)->addr[0]; \
++ 
(target_in6addr)->s6_addr32[1] = (source_ip6addr)->addr[1]; \
++ 
(target_in6addr)->s6_addr32[2] = (source_ip6addr)->addr[2]; \
++ 
(target_in6addr)->s6_addr32[3] = (source_ip6addr)->addr[3];}
++#define inet6_addr_to_ip6addr(target_ip6addr, source_in6addr)   
{(target_ip6addr)->addr[0] = (source_in6addr)->s6_addr32[0]; \
++ 
(target_ip6addr)->addr[1] = (source_in6addr)->s6_addr32[1]; \
++ 
(target_ip6addr)->addr[2] = (source_in6addr)->s6_addr32[2]; \
++ 
(target_ip6addr)->addr[3] = (source_in6addr)->s6_addr32[3];}
++/* ATTENTION: the next define only works because both in6_addr and ip6_addr_t 
are an u32_t[4] effectively! */
++#define inet6_addr_to_ip6addr_p(target_ip6addr_p, source_in6addr)   
((target_ip6addr_p) = (ip6_addr_t*)(source_in6addr))
++#endif /* LWIP_IPV6 */
++
++#ifdef __cplusplus
++}
++#endif
++
++#endif /* HURD_LWIP_POSIX_INET_H */
+--- /dev/null
 b/port/include/posix/socket.h
+@@ -0,0 +1,39 @@
++/*
++   Copyright (C) 2018 Free Software Foundation, Inc.
++   Written by Joan Lledó.
++
++   This file is part of the GNU Hurd.
++
++   The GNU Hurd is free software; you can redistribute it and/or
++   modify it under the terms of the GNU General Public License as
++   published by the Free Software Foundation; either version 2, or (at
++   your option) any later version.
++
++   The GNU Hurd is distributed in the hope that it will be useful, but
++   WITHOUT ANY WARRANTY; without even the implied warranty of
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
++   General Public License for more details.
++
++   You should have received a copy of the GNU General Public License
++   along with the GNU Hurd. 

[PATCH 5/7] POLL: New patch implementing poll()

2018-04-30 Thread Joan Lledó
---
 debian/patches/poll | 518 
 1 file changed, 518 insertions(+)
 create mode 100644 debian/patches/poll

diff --git a/debian/patches/poll b/debian/patches/poll
new file mode 100644
index 000..b85ae06
--- /dev/null
+++ b/debian/patches/poll
@@ -0,0 +1,518 @@
+--- a/src/api/sockets.c
 b/src/api/sockets.c
+@@ -238,6 +238,12 @@
+   fd_set *writeset;
+   /** unimplemented: exceptset passed to select */
+   fd_set *exceptset;
++#if LWIP_POLL
++  /** fds passed to poll; NULL if select */
++  struct pollfd *poll_fds;
++  /** nfds passed to poll; 0 if select */
++  nfds_t poll_nfds;
++#endif
+   /** don't signal the same semaphore twice: set to 1 when signalled */
+   int sem_signalled;
+   /** semaphore to wake up a task waiting for select */
+@@ -1288,6 +1294,51 @@
+   return lwip_sendmsg(s, , 0);
+ }
+ 
++/* Add select_cb to select_cb_list. */
++static void
++lwip_link_select_cb(struct lwip_select_cb *select_cb)
++{
++  SYS_ARCH_DECL_PROTECT(lev);
++
++  /* Protect the select_cb_list */
++  SYS_ARCH_PROTECT(lev);
++
++  /* Put this select_cb on top of list */
++  select_cb->next = select_cb_list;
++  if (select_cb_list != NULL) {
++select_cb_list->prev = select_cb;
++  }
++  select_cb_list = select_cb;
++  /* Increasing this counter tells event_callback that the list has changed. 
*/
++  select_cb_ctr++;
++
++  /* Now we can safely unprotect */
++  SYS_ARCH_UNPROTECT(lev);
++}
++
++/* Remove select_cb from select_cb_list. */
++void
++lwip_unlink_select_cb(struct lwip_select_cb *select_cb)
++{
++  SYS_ARCH_DECL_PROTECT(lev);
++
++  /* Take us off the list */
++  SYS_ARCH_PROTECT(lev);
++  if (select_cb->next != NULL) {
++select_cb->next->prev = select_cb->prev;
++  }
++  if (select_cb_list == select_cb) {
++LWIP_ASSERT("select_cb->prev == NULL", select_cb->prev == NULL);
++select_cb_list = select_cb->next;
++  } else {
++LWIP_ASSERT("select_cb->prev != NULL", select_cb->prev != NULL);
++select_cb->prev->next = select_cb->next;
++  }
++  /* Increasing this counter tells event_callback that the list has changed. 
*/
++  select_cb_ctr++;
++  SYS_ARCH_UNPROTECT(lev);
++}
++
+ /**
+  * Go through the readset and writeset lists and see which socket of the 
sockets
+  * set in the sets has events. On return, readset, writeset and exceptset have
+@@ -1411,6 +1462,10 @@
+ select_cb.readset = readset;
+ select_cb.writeset = writeset;
+ select_cb.exceptset = exceptset;
++#if LWIP_POLL
++select_cb.poll_fds = NULL;
++select_cb.poll_nfds = 0;
++#endif
+ select_cb.sem_signalled = 0;
+ #if LWIP_NETCONN_SEM_PER_THREAD
+ select_cb.sem = LWIP_NETCONN_THREAD_SEM_GET();
+@@ -1422,20 +1477,7 @@
+ }
+ #endif /* LWIP_NETCONN_SEM_PER_THREAD */
+ 
+-/* Protect the select_cb_list */
+-SYS_ARCH_PROTECT(lev);
+-
+-/* Put this select_cb on top of list */
+-select_cb.next = select_cb_list;
+-if (select_cb_list != NULL) {
+-  select_cb_list->prev = _cb;
+-}
+-select_cb_list = _cb;
+-/* Increasing this counter tells event_callback that the list has 
changed. */
+-select_cb_ctr++;
+-
+-/* Now we can safely unprotect */
+-SYS_ARCH_UNPROTECT(lev);
++lwip_link_select_cb(_cb);
+ 
+ /* Increase select_waiting for each socket we are interested in */
+ maxfdp2 = maxfdp1;
+@@ -1505,21 +1547,7 @@
+ SYS_ARCH_UNPROTECT(lev);
+   }
+ }
+-/* Take us off the list */
+-SYS_ARCH_PROTECT(lev);
+-if (select_cb.next != NULL) {
+-  select_cb.next->prev = select_cb.prev;
+-}
+-if (select_cb_list == _cb) {
+-  LWIP_ASSERT("select_cb.prev == NULL", select_cb.prev == NULL);
+-  select_cb_list = select_cb.next;
+-} else {
+-  LWIP_ASSERT("select_cb.prev != NULL", select_cb.prev != NULL);
+-  select_cb.prev->next = select_cb.next;
+-}
+-/* Increasing this counter tells event_callback that the list has 
changed. */
+-select_cb_ctr++;
+-SYS_ARCH_UNPROTECT(lev);
++lwip_unlink_select_cb(_cb);
+ 
+ #if LWIP_NETCONN_SEM_PER_THREAD
+ if (select_cb.sem_signalled && (!waited || (waitres == 
SYS_ARCH_TIMEOUT))) {
+@@ -1563,6 +1591,253 @@
+   return nready;
+ }
+ 
++#if LWIP_POLL
++
++/** Options for the lwip_pollscan function. */
++enum lwip_pollscan_opts
++{
++  /** Clear revents in each struct pollfd. */
++  LWIP_POLLSCAN_CLEAR = 1,
++
++  /** Increment select_waiting in each struct lwip_sock. */
++  LWIP_POLLSCAN_INC_WAIT = 2,
++
++  /** Decrement select_waiting in each struct lwip_sock. */
++  LWIP_POLLSCAN_DEC_WAIT = 4
++};
++
++/**
++ * Update revents in each struct pollfd.
++ * Optionally update select_waiting in struct lwip_sock.
++ *
++ * @param fds  array of structures to update
++ * @param nfds number of structures in fds
++ * @param opts what to update and how
++ * @return number of structures that have revents != 0
++ */
++static int
++lwip_pollscan(struct pollfd *fds, nfds_t nfds, enum 

[PATCH 6/7] MAX_SOCKETS: New patch implementing unlimited number of sockets

2018-04-30 Thread Joan Lledó
---
 debian/patches/max_sockets | 247 +
 1 file changed, 247 insertions(+)
 create mode 100644 debian/patches/max_sockets

diff --git a/debian/patches/max_sockets b/debian/patches/max_sockets
new file mode 100644
index 000..bdc7293
--- /dev/null
+++ b/debian/patches/max_sockets
@@ -0,0 +1,247 @@
+--- a/src/core/init.c
 b/src/core/init.c
+@@ -173,6 +173,9 @@
+ #if ((LWIP_SOCKET || LWIP_NETCONN) && (NO_SYS==1))
+   #error "If you want to use Sequential API, you have to define NO_SYS=0 in 
your lwipopts.h"
+ #endif
++#if (LWIP_SOCKET_OPEN_COUNT && !MEMP_MEM_MALLOC)
++  #error "LWIP_SOCKET_OPEN_COUNT requires MEMP_MEM_MALLOC=1 in your 
lwipopts.h"
++#endif
+ #if (LWIP_PPP_API && (NO_SYS==1))
+   #error "If you want to use PPP API, you have to define NO_SYS=0 in your 
lwipopts.h"
+ #endif
+--- a/src/include/lwip/opt.h
 b/src/include/lwip/opt.h
+@@ -1791,6 +1791,16 @@
+ #endif
+ 
+ /**
++ * LWIP_SOCKET_OPEN_COUNT==1: Number of sockets is not limited to 
MEMP_NUM_NETCONN.
++ * When enabled, sockets are allocated in the heap and the amount of sockets 
is
++ * only limited by the heap size. Handle with care regarding execution speed.
++ * To use this, MEMP_MEM_MALLOC also has to be enabled.
++ */
++#if !defined LWIP_SOCKET_OPEN_COUNT || defined __DOXYGEN__
++#define LWIP_SOCKET_OPEN_COUNT  0
++#endif
++
++/**
+  * LWIP_TCP_KEEPALIVE==1: Enable TCP_KEEPIDLE, TCP_KEEPINTVL and TCP_KEEPCNT
+  * options processing. Note that TCP_KEEPIDLE and TCP_KEEPINTVL have to be set
+  * in seconds. (does not require sockets.c, and will affect tcp.c)
+--- a/src/api/sockets.c
 b/src/api/sockets.c
+@@ -198,6 +198,12 @@
+ 
+ /** Contains all internal pointers and states used for a socket */
+ struct lwip_sock {
++#if LWIP_SOCKET_OPEN_COUNT
++  /** Next element in the linked list */
++  struct lwip_sock *next;
++  /** Socket number*/
++  int count;
++#endif /* LWIP_SOCKET_OPEN_COUNT */
+   /** sockets currently are built on netconns, each socket has one netconn */
+   struct netconn *conn;
+   /** data that was left from the previous read */
+@@ -287,8 +293,13 @@
+ static void lwip_socket_drop_registered_memberships(int s);
+ #endif /* LWIP_IGMP */
+ 
++#if LWIP_SOCKET_OPEN_COUNT
++/** The global linked list of available sockets */
++static struct lwip_sock *sockets = NULL;
++#else /* LWIP_SOCKET_OPEN_COUNT */
+ /** The global array of available sockets */
+ static struct lwip_sock sockets[NUM_SOCKETS];
++#endif /* LWIP_SOCKET_OPEN_COUNT */
+ /** The global list of tasks waiting for select */
+ static struct lwip_select_cb *select_cb_list;
+ /** This counter is increased from lwip_select when the list is changed
+@@ -359,15 +370,26 @@
+ 
+   s -= LWIP_SOCKET_OFFSET;
+ 
+-  if ((s < 0) || (s >= NUM_SOCKETS)) {
++  if ((s < 0)
++#if !LWIP_SOCKET_OPEN_COUNT
++  || (s >= NUM_SOCKETS)
++#endif /* !LWIP_SOCKET_OPEN_COUNT */
++  ) {
+ LWIP_DEBUGF(SOCKETS_DEBUG, ("get_socket(%d): invalid\n", s + 
LWIP_SOCKET_OFFSET));
+ set_errno(EBADF);
+ return NULL;
+   }
+ 
++#if LWIP_SOCKET_OPEN_COUNT
++  for(sock = sockets; sock != NULL; sock = sock->next) {
++if(sock->count == s)
++  break;
++  }
++#else /* LWIP_SOCKET_OPEN_COUNT */
+   sock = [s];
++#endif /* LWIP_SOCKET_OPEN_COUNT */
+ 
+-  if (!sock->conn) {
++  if (!sock || !sock->conn) {
+ LWIP_DEBUGF(SOCKETS_DEBUG, ("get_socket(%d): not active\n", s + 
LWIP_SOCKET_OFFSET));
+ set_errno(EBADF);
+ return NULL;
+@@ -386,13 +408,26 @@
+ tryget_socket(int s)
+ {
+   s -= LWIP_SOCKET_OFFSET;
+-  if ((s < 0) || (s >= NUM_SOCKETS)) {
++  if ((s < 0)
++#if !LWIP_SOCKET_OPEN_COUNT
++  || (s >= NUM_SOCKETS)
++#endif /* !LWIP_SOCKET_OPEN_COUNT */
++  ) {
+ return NULL;
+   }
++#if LWIP_SOCKET_OPEN_COUNT
++  struct lwip_sock *sock;
++  for(sock = sockets; sock != NULL; sock = sock->next) {
++if(sock->count == s)
++  break;
++  }
++  return sock;
++#else /* LWIP_SOCKET_OPEN_COUNT */
+   if (!sockets[s].conn) {
+ return NULL;
+   }
+   return [s];
++#endif /* LWIP_SOCKET_OPEN_COUNT */
+ }
+ 
+ /**
+@@ -407,30 +442,70 @@
+ alloc_socket(struct netconn *newconn, int accepted)
+ {
+   int i;
++  struct lwip_sock *newsock = NULL;
++#if LWIP_SOCKET_OPEN_COUNT
++  struct lwip_sock **it;
++#endif /* LWIP_SOCKET_OPEN_COUNT */
++
+   SYS_ARCH_DECL_PROTECT(lev);
+ 
++#if LWIP_SOCKET_OPEN_COUNT
++  newsock = (struct lwip_sock*)mem_malloc(sizeof(struct lwip_sock));
++  if(!newsock) {
++return -1;
++  }
++  /* Protect socket list */
++  SYS_ARCH_PROTECT(lev);
++  it = 
++  i = LWIP_SOCKET_OFFSET;
++  while(*it) {
++if((*it)->count != i) {
++  /* There's a gap in the list, fill it */
++  break;
++}
++i++;
++it = &(*it)->next;
++  }
++  /* Add the new socket in the first gap found or in the end */
++  newsock->count = i;
++  newsock->next = (*it);
++  (*it) = newsock;
++  newsock->conn = newconn;
++  SYS_ARCH_UNPROTECT(lev);
++#else /* LWIP_SOCKET_OPEN_COUNT */
+   

[PATCH 1/7] PORT: Solved some bugs on timed waits

2018-04-30 Thread Joan Lledó
---
 debian/patches/port | 60 -
 1 file changed, 23 insertions(+), 37 deletions(-)

diff --git a/debian/patches/port b/debian/patches/port
index 1a3a71f..92fffb3 100644
--- a/debian/patches/port
+++ b/debian/patches/port
@@ -1,8 +1,6 @@
-Index: lwip/port/include/arch/cc.h
-===
 --- /dev/null
-+++ lwip/port/include/arch/cc.h
-@@ -0,0 +1,77 @@
 b/port/include/arch/cc.h
+@@ -0,0 +1,68 @@
 +/*
 +   Copyright (C) 2017 Free Software Foundation, Inc.
 +   Written by Joan Lledó.
@@ -20,7 +18,7 @@ Index: lwip/port/include/arch/cc.h
 +   General Public License for more details.
 +
 +   You should have received a copy of the GNU General Public License
-+   along with the GNU Hurd.  If not, see <http://www.gnu.org/licenses/>.  */
++   along with the GNU Hurd. If not, see <http://www.gnu.org/licenses/>.  */
 +
 +#ifndef LWIP_ARCH_CC_H
 +#define LWIP_ARCH_CC_H
@@ -39,18 +37,9 @@ Index: lwip/port/include/arch/cc.h
 +#define LWIP_TIMEVAL_PRIVATE  0
 +#include 
 +
-+/* Use our own  */
-+#include 
-+#include 
-+#include 
-+#include 
-+
 +/* We need INT_MAX */
 +#include 
 +
-+/* We use poll() instead of select()*/
-+#include 
-+
 +/* Use our own ioctls */
 +#include 
 +
@@ -80,11 +69,9 @@ Index: lwip/port/include/arch/cc.h
 +  } while(0)
 +
 +#endif /* LWIP_ARCH_CC_H */
-Index: lwip/port/include/arch/sys_arch.h
-===
 --- /dev/null
-+++ lwip/port/include/arch/sys_arch.h
-@@ -0,0 +1,61 @@
 b/port/include/arch/sys_arch.h
+@@ -0,0 +1,64 @@
 +/*
 + * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
 + * All rights reserved. 
@@ -122,6 +109,9 @@ Index: lwip/port/include/arch/sys_arch.h
 +#define SYS_MBOX_NULL NULL
 +#define SYS_SEM_NULL  NULL
 +
++/* Return code for an interrupted timed wait */
++#define SYS_ARCH_INTR 0xfffeUL
++
 +typedef u32_t sys_prot_t;
 +
 +struct sys_sem;
@@ -146,11 +136,9 @@ Index: lwip/port/include/arch/sys_arch.h
 +
 +#endif /* LWIP_ARCH_SYS_ARCH_H */
 +
-Index: lwip/port/include/lwipopts.h
-===
 --- /dev/null
-+++ lwip/port/include/lwipopts.h
-@@ -0,0 +1,137 @@
 b/port/include/lwipopts.h
+@@ -0,0 +1,131 @@
 +/*
 +   Copyright (C) 2017 Free Software Foundation, Inc.
 +   Written by Joan Lledó.
@@ -168,7 +156,7 @@ Index: lwip/port/include/lwipopts.h
 +   General Public License for more details.
 +
 +   You should have received a copy of the GNU General Public License
-+   along with the GNU Hurd.  If not, see <http://www.gnu.org/licenses/>.  */
++   along with the GNU Hurd. If not, see <http://www.gnu.org/licenses/>.  */
 +
 +#ifndef HURD_LWIP_LWIPOPTS_H
 +#define HURD_LWIP_LWIPOPTS_H
@@ -179,12 +167,6 @@ Index: lwip/port/include/lwipopts.h
 +/* Don't rename Sockets API functions */
 +#define LWIP_COMPAT_SOCKETS   0
 +
-+/* Don't limit the number of sockets */
-+#define LWIP_SOCKET_OPEN_COUNT  1
-+
-+/* We're using lwip_poll() */
-+#define LWIP_SOCKET_POLL   1
-+
 +/* Use Glibc malloc()/free() */
 +#define MEM_LIBC_MALLOC   1
 +#define MEMP_MEM_MALLOC   1
@@ -288,11 +270,9 @@ Index: lwip/port/include/lwipopts.h
 +#endif
 +
 +#endif
-Index: lwip/port/sys_arch.c
-===
 --- /dev/null
-+++ lwip/port/sys_arch.c
-@@ -0,0 +1,741 @@
 b/port/sys_arch.c
+@@ -0,0 +1,747 @@
 +/*
 + * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
 + * All rights reserved. 
@@ -812,6 +792,8 @@ Index: lwip/port/sys_arch.c
 +#endif
 +  if (ret == ETIMEDOUT) {
 +return SYS_ARCH_TIMEOUT;
++  } else if (ret == EINTR) {
++return SYS_ARCH_INTR;
 +  }
 +
 +  /* Calculate for how long we waited for the cond. */
@@ -844,12 +826,16 @@ Index: lwip/port/sys_arch.c
 +  if (time_needed == SYS_ARCH_TIMEOUT) {
 +pthread_mutex_unlock(&(sem->mutex));
 +return SYS_ARCH_TIMEOUT;
++  } else if(time_needed == SYS_ARCH_INTR) {
++ /* This means we were interrupted, so don't wait again */
++sem->c++;
++
++if (sem->c > 1) {
++  sem->c = 1;
++}
 +  }
-+  /*  pthread_mutex_unlock(&(sem->mutex));
-+  return time_needed; */
 +} else {
-+  if(cond_wait_intr(&(sem->cond), &(sem->mutex), 0))
-+  {
++  if(cond_wait_intr(&(sem->cond), &(sem->mutex), 0)) {
 +/* This means we were interrupted, so don't wait again */
 +sem->c++;
 +
-- 
2.14.0



[PATCH 7/7] Update series file

2018-04-30 Thread Joan Lledó
---
 debian/patches/series | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/debian/patches/series b/debian/patches/series
index 215fefd..7d92024 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,5 +1,7 @@
-bug-36167 --binary
 port
-autoconf
-errno
 posix
+errno
+autoconf
+bug-36167
+poll
+max_sockets
-- 
2.14.0



[PATCH 4/7] BUG-36167: Implement the upstream solution

2018-04-30 Thread Joan Lledó
---
 debian/patches/bug-36167 | 35 ---
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/debian/patches/bug-36167 b/debian/patches/bug-36167
index 4a7cd42..6d12e93 100644
--- a/debian/patches/bug-36167
+++ b/debian/patches/bug-36167
@@ -1,22 +1,27 @@
-commit 4d624d8c4f47d06a6fdc82cb6737c06f4e69804c
-Author: Joan Lledó <jlle...@member.fsf.org>
-Date:   Sat Nov 11 08:37:28 2017 +0100
-
-Fix bug #36167 in lwip
-
-https://savannah.nongnu.org/bugs/?36167
-
-diff --git a/src/core/tcp.c b/src/core/tcp.c
-index 75be86b..17a51a8 100644
 a/src/core/tcp.c
-+++ b/src/core/tcp.c
-@@ -782,7 +782,8 @@ tcp_recved(struct tcp_pcb *pcb, u16_t len)
+diff --git a/src/core/tcp.c b/src/core/tcp.c
+index 7103a52..ccfa3c1 100644
+--- a/src/core/tcp.c
 b/src/core/tcp.c
+@@ -804,7 +804,7 @@ tcp_recved(struct tcp_pcb *pcb, u16_t len)
  pcb->rcv_wnd = TCP_WND_MAX(pcb);
} else if (pcb->rcv_wnd == 0) {
  /* rcv_wnd overflowed */
 -if ((pcb->state == CLOSE_WAIT) || (pcb->state == LAST_ACK)) {
-+if ((pcb->state == CLOSE_WAIT) || (pcb->state == LAST_ACK)
-+|| (pcb->state == TIME_WAIT)) {
++if (TCP_STATE_IS_CLOSING(pcb->state)) {
/* In passive close, we allow this, since the FIN bit is added to 
rcv_wnd
   by the stack itself, since it is not mandatory for an application
   to call tcp_recved() for the FIN bit, but e.g. the netconn API does 
so. */
+diff --git a/src/include/lwip/tcp.h b/src/include/lwip/tcp.h
+index 3845b9f..fb7fa17 100644
+--- a/src/include/lwip/tcp.h
 b/src/include/lwip/tcp.h
+@@ -424,6 +424,9 @@ const char* tcp_debug_state_str(enum tcp_state s);
+ /* for compatibility with older implementation */
+ #define tcp_new_ip6() tcp_new_ip_type(IPADDR_TYPE_V6)
+ 
++/* ATTENTION: this depends on state number ordering! */
++#define TCP_STATE_IS_CLOSING(state) ((state) >= FIN_WAIT_1)
++
+ #ifdef __cplusplus
+ }
+ #endif
-- 
2.14.0



Re: Debian GNU/Hurd 2019 released!

2019-07-14 Thread Joan Lledó
> This is what was installed from the Debian GNU/Hurd 2019 release. I
> simply downloaded the first CD and then fetched the rest over the net.

Yeah, I've tried and have the same error too. I don't know the problem but I 
fixed it by downloading the Hurd from sources and compiling the lwip translator 
myself. There must have been some problem while compiling the translator in the 
release.


Try this:

apt-get install liblwip-dev build-essential fakeroot git
apt-get build-dep hurd
git clone git://git.sv.gnu.org/hurd/hurd.git
cd hurd
autoreconf -i
cd ..
mkdir hurd-build
cd hurd-build
../hurd/configure --disable-profile
make lwip
cd lwip
settrans -fgap /servers/socket/2 ./lwip and your parameters

Good luck, this is a "bit" more complicated :)



Re: Debian GNU/Hurd 2019 released!

2019-07-09 Thread Joan Lledó
> Is that this stack? https://en.wikipedia.org/wiki/LwIP
>
> How is it possible to switch to it?
>

You must install the liblwip0 package, and then just use the same parameters 
you use with pfinet, for instance:

# settrans -fgap /hurd/lwip /servers/socket/2 -6 /servers/socket/26 -i 
/dev/eth0 -a 192.168.122.178 -m 255.255.255.0 -g 192.168.122.1

Being configured through DHCP is not supported yet.



Re: Xorg news

2022-08-23 Thread Joan Lledó

Hi,

El 23/8/22 a les 19:30, Samuel Thibault ha escrit:

And also, I have just uploaded version 0.16-3+hurd.of libpciaccess. The
issue was that the map_legacy method was completely broken.


What was the problem with it?

Ideally it'd be able to use the map_region method, 


Do you mean device_map_region() from the arbiter? If what you want is to 
map the ROM, Why not calling the new device_map_rom() method?


What's the context of this?



Re: dhcpcd: FTBFS on Hurd

2023-11-25 Thread Joan Lledó

Hi Martin-Éric,

you can write me for help when you need it.

Regards

On 24/11/23 6:50, Martin-Éric Racine wrote:

Greetings,

As dhcpcd is slated to replace dhclient as the default DHCP client in
Debian, I've been trying to fix the build on Hurd, which is the only
architecture that has repeatedly FTBFS. Most of this has merely
required fixing missing includes so far.

Help is welcome, especially from people who have access to a live Hurd
host and who would be able to test the binaries, and also to help me
finalize the port.

Cheers!
Martin-Éric