Index: CHANGELOG
===================================================================
RCS file: /sources/lwip/lwip/CHANGELOG,v
retrieving revision 1.109
diff -u -3 -p -r1.109 CHANGELOG
--- CHANGELOG	30 Mar 2007 13:30:42 -0000	1.109
+++ CHANGELOG	30 Mar 2007 15:42:09 -0000
@@ -23,6 +23,10 @@ HISTORY
 
   ++ New features:
 
+  2007-03-30 Frédéric Bernon
+  * opt.h, tcpip.h, tcpip.c: New configuration option LWIP_NETIF_API allow to use thread-safe
+    functions to add/remove netif in list, and to start/stop dhcp clients.
+
   2007-03-28 Frédéric Bernon
   * opt.h, netif.h, dhcp.h, dhcp.c: New configuration option LWIP_NETIF_HOSTNAME allow to
     define a hostname in netif struct (this is just a pointer, so, you can use a hardcoded


Index: src/api/tcpip.c
===================================================================
RCS file: /sources/lwip/lwip/src/api/tcpip.c,v
retrieving revision 1.32
diff -u -3 -p -r1.32 tcpip.c
--- src/api/tcpip.c	26 Mar 2007 18:57:30 -0000	1.32
+++ src/api/tcpip.c	30 Mar 2007 15:36:40 -0000
@@ -163,6 +163,41 @@ ethernet_input(struct pbuf *p, struct ne
 }
 #endif /* ETHARP_TCPIP_ETHINPUT */
 
+#if LWIP_NETIF_API
+void
+netifapi_msg_input(struct netifapi_msg *netifapimsg)
+{ netifapimsg->err = ERR_OK;
+  switch (netifapimsg->type) {
+    case NETIFAPI_MSG_NETIF_ADD: {
+      struct ip_addr ipaddr;
+      struct ip_addr netmask;
+      struct ip_addr gw;
+      
+      ipaddr  = netifapimsg->netif->ip_addr;
+      netmask = netifapimsg->netif->netmask;
+      gw      = netifapimsg->netif->gw;
+                 
+      netif_add( netifapimsg->netif, ipaddr, netmask, gw,
+                 netifapimsg->netif->state,
+                 /*netifapimsg->netif->init*/NULL, /*need change in netif struct*/
+                 netifapimsg->netif->input);
+      break;
+    }
+    case NETIFAPI_MSG_NETIF_REMOVE:
+      netif_remove(netifapimsg->netif);
+      break;
+#if LWIP_DHCP    
+    case NETIFAPI_MSG_DHCP_START:
+      netifapimsg->err = dhcp_start(netifapimsg->netif);
+      break;
+    case NETIFAPI_MSG_DHCP_STOP:
+      dhcp_stop(netifapimsg->netif);
+      break;
+#endif /* LWIP_DHCP */
+  }
+}
+#endif /* LWIP_NETIF_API */
+
 static void
 tcpip_thread(void *arg)
 {
@@ -198,6 +233,7 @@ tcpip_thread(void *arg)
     case TCPIP_MSG_INPUT:
       LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: IP packet %p\n", (void *)msg));
       ip_input(msg->msg.inp.p, msg->msg.inp.netif);
+      memp_free(MEMP_TCPIP_MSG, msg);
       break;
 #endif /* ETHARP_TCPIP_INPUT */
 
@@ -205,20 +241,25 @@ tcpip_thread(void *arg)
     case TCPIP_MSG_ETHINPUT:
       LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: Ethernet packet %p\n", (void *)msg));
       ethernet_input(msg->msg.inp.p, msg->msg.inp.netif);
+      memp_free(MEMP_TCPIP_MSG, msg);
       break;
 #endif /* ETHARP_TCPIP_ETHINPUT */
 
+#if LWIP_NETIF_API
+    case TCPIP_MSG_NETIFAPI:
+      LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: Netif API message %p\n", (void *)msg));
+      netifapi_msg_input(msg->msg.netifapimsg);
+      break;
+#endif /* LWIP_NETIF_API */
+
     case TCPIP_MSG_CALLBACK:
       LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: CALLBACK %p\n", (void *)msg));
       msg->msg.cb.f(msg->msg.cb.ctx);
+      memp_free(MEMP_TCPIP_MSG, msg);
       break;
     default:
       break;
     }
-    
-    if (msg->type!=TCPIP_MSG_API) {
-      memp_free(MEMP_TCPIP_MSG, msg);
-    }
   }
 }
 
@@ -303,6 +344,22 @@ tcpip_apimsg(struct api_msg *apimsg)
   return ERR_VAL;
 }
 
+#if LWIP_NETIF_API
+err_t tcpip_netifapi(struct netifapi_msg* netifapimsg)
+{
+  struct tcpip_msg msg;
+  
+  if (mbox != SYS_MBOX_NULL) {
+    msg.type = TCPIP_MSG_NETIFAPI;
+    msg.msg.netifapimsg = netifapimsg;
+    sys_mbox_post(mbox, &msg);
+    sys_mbox_fetch(apimsg->msg.conn->mbox, NULL);
+    return ERR_OK;
+  }
+  return ERR_VAL;
+}
+#endif /* LWIP_NETIF_API */
+
 void
 tcpip_init(void (* initfunc)(void *), void *arg)
 {


Index: src/include/lwip/opt.h
===================================================================
RCS file: /sources/lwip/lwip/src/include/lwip/opt.h,v
retrieving revision 1.51
diff -u -3 -p -r1.51 opt.h
--- src/include/lwip/opt.h	30 Mar 2007 08:47:05 -0000	1.51
+++ src/include/lwip/opt.h	30 Mar 2007 15:33:52 -0000
@@ -393,6 +393,11 @@ a lot of data that needs to be copied, t
 #define LWIP_NETIF_HOSTNAME             0
 #endif
 
+/* Support network interface API */
+#ifndef LWIP_NETIF_API
+#define LWIP_NETIF_API                  0
+#endif
+
 /* Support network interface callbacks */
 #ifndef LWIP_NETIF_CALLBACK
 #define LWIP_NETIF_CALLBACK             0
Index: src/include/lwip/tcpip.h
===================================================================
RCS file: /sources/lwip/lwip/src/include/lwip/tcpip.h,v
retrieving revision 1.7
diff -u -3 -p -r1.7 tcpip.h
--- src/include/lwip/tcpip.h	19 Mar 2007 20:35:33 -0000	1.7
+++ src/include/lwip/tcpip.h	30 Mar 2007 15:35:21 -0000
@@ -35,18 +35,6 @@
 #include "lwip/api_msg.h"
 #include "lwip/pbuf.h"
 
-void tcpip_init(void (* tcpip_init_done)(void *), void *arg);
-err_t tcpip_apimsg(struct api_msg *apimsg);
-#if ETHARP_TCPIP_INPUT
-err_t tcpip_input(struct pbuf *p, struct netif *inp);
-#endif /* ETHARP_TCPIP_INPUT */
-#if ETHARP_TCPIP_ETHINPUT
-err_t tcpip_ethinput(struct pbuf *p, struct netif *inp);
-#endif /* ETHARP_TCPIP_ETHINPUT */
-err_t tcpip_callback(void (*f)(void *ctx), void *ctx);
-
-void tcpip_tcp_timer_needed(void);
-
 enum tcpip_msg_type {
   TCPIP_MSG_API,
 #if ETHARP_TCPIP_INPUT  
@@ -55,14 +43,37 @@ enum tcpip_msg_type {
 #if ETHARP_TCPIP_ETHINPUT
   TCPIP_MSG_ETHINPUT,
 #endif /* ETHARP_TCPIP_ETHINPUT */
+#if LWIP_NETIF_API
+  TCPIP_MSG_NETIFAPI,
+#endif /* LWIP_NETIF_API */
   TCPIP_MSG_CALLBACK
 };
 
+#if LWIP_NETIF_API
+enum netifapi_msg_type {
+  NETIFAPI_MSG_NETIF_ADD,
+  NETIFAPI_MSG_NETIF_REMOVE,
+#if LWIP_DHCP  
+  NETIFAPI_MSG_DHCP_START,
+  NETIFAPI_MSG_DHCP_STOP
+#endif /* LWIP_DHCP */
+};
+
+struct netifapi_msg {
+  enum netifapi_msg_type type;
+  struct netif *netif;
+  err_t err;
+};
+#endif /* LWIP_NETIF_API */
+
 struct tcpip_msg {
   enum tcpip_msg_type type;
   sys_sem_t *sem;
   union {
     struct api_msg *apimsg;
+#if LWIP_NETIF_API
+    struct netifapi_msg *netifapimsg;
+#endif /* LWIP_NETIF_API */
     struct {
       struct pbuf *p;
       struct netif *netif;
@@ -74,5 +85,24 @@ struct tcpip_msg {
   } msg;
 };
 
+void tcpip_init(void (* tcpip_init_done)(void *), void *arg);
+
+err_t tcpip_apimsg(struct api_msg *apimsg);
+
+#if ETHARP_TCPIP_INPUT
+err_t tcpip_input(struct pbuf *p, struct netif *inp);
+#endif /* ETHARP_TCPIP_INPUT */
+
+#if ETHARP_TCPIP_ETHINPUT
+err_t tcpip_ethinput(struct pbuf *p, struct netif *inp);
+#endif /* ETHARP_TCPIP_ETHINPUT */
+
+#if LWIP_NETIF_API
+err_t tcpip_netifapi(struct netifapi_msg* netifapimsg);
+#endif /* LWIP_NETIF_API */
+
+err_t tcpip_callback(void (*f)(void *ctx), void *ctx);
+
+void tcpip_tcp_timer_needed(void);
 
 #endif /* __LWIP_TCPIP_H__ */
