Integrate 0.9.8 NDS read-only lab, repair upstream hook and simplify setup guidance
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
static int ctl,server,reply_fd;
|
||||
static int ipc_socket(unsigned port){int fd=mars_socket(AF_IPX,SOCK_DGRAM,AF_IPX);assert(fd>=0);struct sockaddr_ipx a={.sipx_family=AF_IPX,.sipx_port=htons(port)};assert(!mars_bind(fd,(void*)&a,sizeof a));return fd;}
|
||||
static void setup(void){ctl=mars_socket(AF_IPX,SOCK_DGRAM,AF_IPX);assert(ctl>=0);struct ifreq r={0};struct sockaddr_ipx v={.sipx_family=AF_IPX,.sipx_network=htonl(0x12345678),.sipx_special=IPX_INTERNAL,.sipx_action=IPX_CRTITF,.sipx_node={0,0,0,0,0,1}};memcpy(&r.ifr_addr,&v,sizeof v);assert(!mars_ioctl(ctl,SIOCSIFADDR,&r));server=ipc_socket(0x451);reply_fd=ipc_socket(0);}
|
||||
@@ -28,7 +29,7 @@ static size_t slp_query(int fd,int func,const char*type,uint8_t*out,size_t cap){
|
||||
static int slp_fd(void){int fd=socket(AF_INET,SOCK_DGRAM,0);assert(fd>=0);struct timeval tv={0,200000};assert(!setsockopt(fd,SOL_SOCKET,SO_RCVTIMEO,&tv,sizeof tv));struct sockaddr_in a={.sin_family=AF_INET,.sin_port=htons(15427),.sin_addr.s_addr=htonl(INADDR_LOOPBACK)};assert(!connect(fd,(void*)&a,sizeof a));return fd;}
|
||||
static void advertise(int fd,int hops){uint8_t p[66]={0};put16(p,2);put16(p+2,4);memcpy(p+4,"MARS_TEST",9);put32(p+52,0x12345678);p[61]=1;put16(p+62,0x451);put16(p+64,hops);struct sockaddr_ipx dst={.sipx_family=AF_IPX,.sipx_network=htonl(0x12345678),.sipx_port=htons(0x452),.sipx_node={0,0,0,0,0,1}};assert(mars_sendto(fd,p,sizeof p,0,(void*)&dst,sizeof dst)==sizeof p);}
|
||||
static void test_slp(void){int fd=slp_fd(),sap=ipc_socket(0x452);uint8_t out[512];assert(!slp_query(fd,1,"service:bindery.novell",out,sizeof out));advertise(sap,1);size_t r=0;for(int i=0;i<30&&!r;i++){r=slp_query(fd,1,"service:bindery.novell",out,sizeof out);if(!r)usleep(50000);}assert(r>20&&out[1]==2&&get16(out+10)==0x7263&&get16(out+18)==1&&memmem(out,r,"MARS_TEST",9));int multi=socket(AF_INET,SOCK_DGRAM,0);assert(multi>=0);struct timeval tv={1,0};struct in_addr lo={htonl(INADDR_LOOPBACK)};assert(!setsockopt(multi,SOL_SOCKET,SO_RCVTIMEO,&tv,sizeof tv));assert(!setsockopt(multi,IPPROTO_IP,IP_MULTICAST_IF,&lo,sizeof lo));struct sockaddr_in group={.sin_family=AF_INET,.sin_port=htons(15427)};assert(inet_pton(AF_INET,"239.255.255.253",&group.sin_addr)==1);uint8_t mq[128]={2,1};mq[5]=0x20;put16(mq+10,0x7264);put16(mq+12,2);memcpy(mq+14,"en",2);size_t qn=16;const char*fields[]={"","service:bindery.novell","DEFAULT","",""};for(int i=0;i<5;i++){size_t k=strlen(fields[i]);put16(mq+qn,k);memcpy(mq+qn+2,fields[i],k);qn+=2+k;}put16(mq+3,qn);assert(sendto(multi,mq,qn,0,(void*)&group,sizeof group)==(ssize_t)qn);ssize_t mr=recv(multi,out,sizeof out,0);assert(mr>20&&get16(out+10)==0x7264&&get16(out+18)==1);close(multi);
|
||||
r=slp_query(fd,6,"service:bindery.novell:///MARS_TEST",out,sizeof out);assert(r>20&&out[1]==7&&memmem(out,r,"7F000001020C",12));r=slp_query(fd,1,"service:ndap.novell",out,sizeof out);assert(r==20&&get16(out+18)==0);advertise(sap,16);usleep(100000);assert(!slp_query(fd,1,"service:bindery.novell",out,sizeof out));close(fd);close(sap);puts("PASS real broker SLP UDP unicast/multicast, attributes, no NDS advertisement, SAP withdrawal");}
|
||||
r=slp_query(fd,6,"service:bindery.novell:///MARS_TEST",out,sizeof out);assert(r>20&&out[1]==7&&memmem(out,r,"7F000001020C",12));r=slp_query(fd,1,"service:ndap.novell",out,sizeof out);if(getenv("MARS_TEST_NDS_DISCOVERY")){assert(r>20&&get16(out+18)==1&&memmem(out,r,"service:ndap.novell:///MARS_TREE.",sizeof("service:ndap.novell:///MARS_TREE.")-1));r=slp_query(fd,6,"service:ndap.novell:///MARS_TREE.",out,sizeof out);assert(r>20&&memmem(out,r,"(svcname-ws=MARS_TREE.)",sizeof("(svcname-ws=MARS_TREE.)")-1));}else assert(r==20&&get16(out+18)==0);advertise(sap,16);usleep(100000);assert(!slp_query(fd,1,"service:bindery.novell",out,sizeof out));close(fd);close(sap);puts("PASS real broker SLP UDP unicast/multicast, attributes, NDS opt-in state, SAP withdrawal");}
|
||||
int main(void){setup();test_slp();int a=connect_tcp(),b=connect_tcp();tx(a,0x1111,0,65535,-1);struct sockaddr_ipx x=rx(0x1111,0,65535);answer(&x,0,7);response(a,0,7);tx(b,0x1111,1,65535,-1);struct sockaddr_ipx y=rx(0x1111,0,65535);assert(memcmp(x.sipx_node,y.sipx_node,6));answer(&y,0,9);response(b,1,9);
|
||||
tx(a,0x2222,1,7,23);x=rx(0x2222,1,7);/* incorrect connection reply must be ignored */answer(&x,1,9);answer(&x,1,7);response(a,1,7);
|
||||
/* Watchdog: upstream asks on source port+1; reply on local IPC. */struct sockaddr_ipx wd=x;wd.sipx_port=htons(ntohs(x.sipx_port)+1);uint8_t ping[2]={7,'?'};assert(mars_sendto(reply_fd,ping,2,0,(void*)&wd,sizeof wd)==2);struct pollfd pfd={reply_fd,POLLIN,0};assert(poll(&pfd,1,3000)==1);socklen_t sz=sizeof wd;assert(mars_recvfrom(reply_fd,ping,2,0,(void*)&wd,&sz)==2&&ping[0]==7&&ping[1]=='Y');
|
||||
@@ -40,4 +41,6 @@ int main(void){setup();test_slp();int a=connect_tcp(),b=connect_tcp();tx(a,0x111
|
||||
uint8_t ping104[24]={0};put32(ping104,0x446d6454);put32(ping104+4,sizeof ping104);put32(ping104+8,1);put32(ping104+12,4096);put16(ping104+16,0x2222);ping104[18]=1;ping104[19]=11;ping104[20]=1;ping104[22]=104;ping104[23]=1;fullwrite(nd,ping104,sizeof ping104);x=rx(0x2222,1,11);answer(&x,1,11);response(nd,1,11);
|
||||
/* An upstream shutdown must invalidate all TCP sessions immediately. */
|
||||
close(server);eof(nd);close(nd);sleep(2);FILE*status=fopen("/run/mars-pcap/ncp-ip-status","r");assert(status);char diag[1024]={0};assert(fread(diag,1,sizeof diag-1,status)>0);fclose(status);assert(strstr(diag,"NDS-Requests-TCP=1")&&strstr(diag,"NDS-Ping=1")&&strstr(diag,"waiting for local NCP server"));
|
||||
if(getenv("MARS_TEST_NDS_DISCOVERY"))assert(strstr(diag,"NDS-Discovery-Tree=MARS_TREE"));
|
||||
if(getenv("MARS_TEST_INVALID_NDS"))assert(strstr(diag,"NDS-Discovery=invalid or missing NDS lab snapshot")&&strstr(diag,"NDS-Discovery-Tree=-"));
|
||||
close(ctl);close(reply_fd);puts("PASS NDS request metadata and upstream shutdown invalidates TCP sessions");puts("PASS real TCP framing, fragmented input, separate session nodes, spoof rejection, watchdog, disconnect, malformed signed frame");return 0;}
|
||||
|
||||
Reference in New Issue
Block a user