Build legacy drivers and publish per-OS packages with web activation and DEB

This commit is contained in:
2026-11-27 20:55:31 +00:00
96 changed files with 3204 additions and 25 deletions

11
tests/test_gateway.c Normal file
View File

@@ -0,0 +1,11 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
#include "gateway.h"
#include "ipxpkt.h"
#include <assert.h>
#include <arpa/inet.h>
#include <stdio.h>
struct packets {size_t len[3];uint8_t data[3][546];int count;};
static int store(void*ctx,const uint8_t*p,size_t n){struct packets*a=ctx;assert(a->count<3&&n<=546);a->len[a->count]=n;memcpy(a->data[a->count++],p,n);return 0;}
static void protocol(void){uint8_t frame[1514],out[1514],node[6]={2,1,2,3,4,5};for(size_t i=0;i<sizeof frame;i++)frame[i]=(uint8_t)(i*17);for(unsigned port=PKT_PLAIN;port<=PKT_TRAIL;port++){struct packets a={0};struct pkt_rx r={0};assert(!pkt_send(port,0x1234,frame,sizeof frame,store,&a)&&a.count==3);int off=port==PKT_TRAIL?32:0;assert(a.data[0][off]==1&&a.data[0][off+1]==3&&a.data[0][off+2]==0x34&&a.data[0][off+3]==0x12);assert(a.len[0]==546);assert(pkt_receive(&r,1,node,port,a.data[2],a.len[2],1,out)==0);assert(pkt_receive(&r,1,node,port,a.data[2],a.len[2],1,out)==0);assert(pkt_receive(&r,1,node,port,a.data[0],a.len[0],1,out)==0);assert(pkt_receive(&r,1,node,port,a.data[1],a.len[1],1,out)==1514);assert(!memcmp(frame,out,sizeof frame));/* Timeouts and distinct source keys */assert(!pkt_receive(&r,1,node,port,a.data[0],a.len[0],10,out));assert(!pkt_receive(&r,2,node,port,a.data[1],a.len[1],10,out));assert(!pkt_receive(&r,1,node,port,a.data[1],a.len[1],14,out));assert(!pkt_receive(&r,1,node,port,a.data[2],a.len[2],14,out));assert(pkt_receive(&r,1,node,port,a.data[0],a.len[0],14,out)==1514);a.data[0][off]=0;assert(pkt_receive(&r,1,node,port,a.data[0],a.len[0],15,out)<0);a.data[0][off]=1;a.data[0][off+1]=4;assert(pkt_receive(&r,1,node,port,a.data[0],a.len[0],15,out)<0);assert(pkt_receive(&r,1,node,port,a.data[0],3,15,out)<0);assert(pkt_receive(&r,1,node,port,a.data[0],547,15,out)<0);for(unsigned j=0;j<500;j++){struct packets b={0};assert(!pkt_send(port,j,frame,60,store,&b));assert(pkt_receive(&r,1,node,port,b.data[0],b.len[0],20,out)==60);assert(!memcmp(frame,out,60));}}}
static void policy(void){char e[256];struct gw_config c;json_object*o=gw_default();assert(!gw_parse(o,&c,e,sizeof e)&&!c.enabled);json_object_put(o);o=json_tokener_parse("{\"enabled\":true,\"network\":\"0x101\",\"gateway\":\"10.250.0.1\",\"dns\":\"1.1.1.1\",\"uplink\":\"eth0\",\"web\":true,\"ping\":true,\"clients\":[{\"mac\":\"020102030405\",\"ip\":\"10.250.0.10\"}]}");assert(!gw_parse(o,&c,e,sizeof e)&&c.count==1&&ntohl(c.net)==0x101);uint8_t mac[]={2,9,8,7,6,5},f[60]={0};memcpy(f,mac,6);memcpy(f+6,c.peers[0].mac,6);put16(f+12,0x0800);f[14]=0x45;put16(f+16,20);memcpy(f+26,&c.peers[0].ip,4);assert(gw_frame_allowed(&c,&c.peers[0],mac,f,sizeof f));f[26]^=1;assert(!gw_frame_allowed(&c,&c.peers[0],mac,f,sizeof f));f[26]^=1;f[6]^=1;assert(!gw_frame_allowed(&c,&c.peers[0],mac,f,sizeof f));f[6]^=1;put16(f+12,0x86dd);assert(!gw_frame_allowed(&c,&c.peers[0],mac,f,sizeof f));memset(f,255,6);put16(f+12,0x0806);put16(f+14,1);put16(f+16,0x0800);f[18]=6;f[19]=4;put16(f+20,1);memcpy(f+22,c.peers[0].mac,6);memcpy(f+28,&c.peers[0].ip,4);memcpy(f+38,&c.ip,4);assert(gw_frame_allowed(&c,&c.peers[0],mac,f,sizeof f));f[41]^=1;assert(!gw_frame_allowed(&c,&c.peers[0],mac,f,sizeof f));json_object_object_add(o,"uplink",json_object_new_string("eth0;evil"));assert(gw_parse(o,&c,e,sizeof e));json_object_object_add(o,"uplink",json_object_new_string("eth0"));json_object_object_add(o,"dns",json_object_new_string("192.168.1.1"));assert(gw_parse(o,&c,e,sizeof e));json_object_object_add(o,"dns",json_object_new_string("1.1.1.1"));json_object *a=NULL;json_object_object_get_ex(o,"clients",&a);json_object_array_add(a,json_object_get(json_object_array_get_idx(a,0)));assert(gw_parse(o,&c,e,sizeof e));json_object_put(o);}
int main(void){protocol();policy();puts("PASS: IPXPKT both sockets, little-endian IDs, fragmentation, out-of-order, duplicates, expiry, throughput, malformed data, config validation, static MAC/IP and ARP policy");}