From: Alan Cox Date: Fri, 30 Mar 2018 23:29:29 +0000 (+0100) Subject: netd: Update for new protocol X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=12518484802bf2aa862d6ec0c09c164b464d96d4;p=FUZIX.git netd: Update for new protocol Align the headers Honour a request for an unhook as soon as we can (immediately if the uIP link is already dead) --- diff --git a/Applications/netd/netd.c b/Applications/netd/netd.c index bd5e4812..f6af4761 100644 --- a/Applications/netd/netd.c +++ b/Applications/netd/netd.c @@ -111,15 +111,25 @@ void rel_map( int n ) freelist[ freeptr++ ] = n; } +/* release a linkage and if appropriate tell the kernel */ +void unhook_and_rel_map(int n) +{ + struct link *s = & map[n]; + if (s->flags & LINK_UNBIND) { + ksend(NE_UNHOOK); + s->flags &= ~LINK_UNBIND; + } + rel_map(n); +} + /* initialize the free map of links */ void init_map( void ) { int n; for ( n = 0; nflags &= ~LINK_CLOSED; s->flags |= LINK_SHUTW | LINK_DEAD; ne.socket = s->socketn; - rel_map( uip_conn->appstate ); + unhook_and_rel_map( uip_conn->appstate ); ne.data = SS_CLOSED; ksend(NE_NEWSTATE); } @@ -340,12 +350,12 @@ void netd_appcall(void) ne.ret = ECONNREFUSED; ksende(NE_RESET); s->flags |= LINK_DEAD; - rel_map( uip_conn->appstate ); + unhook_and_rel_map( uip_conn->appstate ); } else if (uip_timedout()) { ne.ret = ETIMEDOUT; ksende(NE_RESET); s->flags |= LINK_DEAD; - rel_map( uip_conn->appstate ); + unhook_and_rel_map( uip_conn->appstate ); } else if ( uip_closed()) { int e; switch ( s->flags & (LINK_SHUTR | LINK_SHUTW) ){ @@ -362,7 +372,7 @@ void netd_appcall(void) break; case LINK_SHUTR | LINK_SHUTW: s->flags |= LINK_DEAD; - rel_map( uip_conn->appstate ); + unhook_and_rel_map( uip_conn->appstate ); return; } } @@ -470,7 +480,7 @@ void netd_raw_appcall(void) ne.data = SS_CLOSED; ksend( NE_NEWSTATE ); /* release private link resource */ - rel_map( uip_raw_conn->appstate ); + unhook_and_rel_map( uip_raw_conn->appstate ); s->flags |= LINK_DEAD; uip_raw_remove( uip_raw_conn ); return; @@ -516,7 +526,8 @@ int dokernel( void ) int i = read( knet, &sm, sizeof(sm) ); int c; - if ( i < 0 ){ + if ( i < 0 && errno != EAGAIN) { + perror("knet read"); return 0; } else if ( i == sizeof( sm ) && (sm.sd.event & 127)){ @@ -603,18 +614,28 @@ int dokernel( void ) conptr->appstate = sm.sd.lcn; /* refactor: same as tcp action from connect event */ ne.data = SS_CONNECTED; - ksend( NE_NEWSTATE ); + ksend(NE_NEWSTATE); break; } break; /* FIXME: handle unknown/unhandled sock types here */ + case SS_DEAD: case SS_CLOSED: if ( sm.s.s_type == SOCKTYPE_UDP ){ uip_udp_remove(m->conn); rel_map(m->lcn); ne.data = SS_CLOSED; - ksend( NE_NEWSTATE ); + ksend(NE_UNHOOK); + break; + } + /* If the tcp session died before we ask, then + we respond with an immeidate unhook */ + if ( m->flags & LINK_DEAD) { + ksend(NE_UNHOOK); break; } + /* If not then we ask for a notification and + kick the process off */ + m->flags |= LINK_UNBIND; if ( sm.s.s_type == SOCKTYPE_TCP ) activity |= (1 << c); m->flags |= LINK_CLOSED; diff --git a/Applications/netd/netd.h b/Applications/netd/netd.h index 2502b5a9..39bcc3e1 100644 --- a/Applications/netd/netd.h +++ b/Applications/netd/netd.h @@ -14,6 +14,8 @@ struct link{ #define LINK_OPEN 8 /* TCP connected onward */ #define LINK_DEAD 16 /* No longer exists to the kernel (may be live internally to uIP still */ +#define LINK_UNBIND 32 /* The kernel wants netd to confirm this link is + dead and will receive no more messages */ uint8_t socketn; /* Kernel's socket no */ uint8_t lcn; /* Kernel's idea of lcn ???*/ struct uip_conn *conn; /* uIP's idea of lcn */ diff --git a/Library/include/sys/net_native.h b/Library/include/sys/net_native.h index bd76804b..ec5f938d 100644 --- a/Library/include/sys/net_native.h +++ b/Library/include/sys/net_native.h @@ -52,6 +52,7 @@ struct sockmsg { #define NE_DATA 6 #define NE_SHUTR 7 #define NE_RESET 8 +#define NE_UNHOOK 9 struct netevent { uint8_t socket; diff --git a/Library/include/sys/netdev.h b/Library/include/sys/netdev.h index ba95dd9f..f52a3b84 100644 --- a/Library/include/sys/netdev.h +++ b/Library/include/sys/netdev.h @@ -55,6 +55,7 @@ struct socket #define SS_CLOSEWAIT 9 /* Remote has closed */ #define SS_CLOSING 10 /* Protocol close in progress */ #define SS_CLOSED 11 /* Protocol layers done, not close()d */ +#define SS_DEAD 12 /* FIXME: need state for shutdown handling */ uint8_t s_data; /* Socket we are an accept() for */ uint8_t s_error; @@ -72,6 +73,7 @@ struct socket #define SI_EOF 8 /* At EOF */ #define SI_THROTTLE 16 /* Transmit is throttled */ void *s_priv; /* Private pointer for lower layers */ + void *s_ino; }; #define NSOCKTYPE 3