[Nstx-ng-devel] r15 - in /trunk: ChangeLog nstx_pstack.c nstx_pstack.h nstx_queue.c nstxcd.c nstxd.c nstxfun.h
qsr-guest at users.alioth.debian.org
qsr-guest at users.alioth.debian.org
Wed May 6 21:02:52 UTC 2009
Author: qsr-guest
Date: Wed May 6 21:02:52 2009
New Revision: 15
URL: http://svn.debian.org/wsvn/nstx-ng/?sc=1&rev=15
Log:
* Add a -c option to the client to choose the channel.
Have 16 queues on the server to separate packets depending on
their incoming channel
Modified:
trunk/ChangeLog
trunk/nstx_pstack.c
trunk/nstx_pstack.h
trunk/nstx_queue.c
trunk/nstxcd.c
trunk/nstxd.c
trunk/nstxfun.h
Modified: trunk/ChangeLog
URL: http://svn.debian.org/wsvn/nstx-ng/trunk/ChangeLog?rev=15&op=diff
==============================================================================
--- trunk/ChangeLog (original)
+++ trunk/ChangeLog Wed May 6 21:02:52 2009
@@ -1,3 +1,8 @@
+2009-05-06 Benjamin Lerman <nstx at ambre.net>
+ * Add a -c option to the client to choose the channel.
+ Have 16 queues on the server to separate packets depending on
+ their incoming channel
+
2009-05-06 Nicolas Boullis <nboullis at debian.org>
* Convert between struct nstxhdr and a char buffer in a
platform-independant way.
@@ -39,7 +44,7 @@
* Fix multiple leaks and cleanups.
Patch from Debian by Matthew William Solloway Bell
- <m.w.s.bell at durham.ac.uk>.
+ <m.w.s.bell at durham.ac.uk>.
2009-04-30 Josselin Mouette <joss at debian.org>
Modified: trunk/nstx_pstack.c
URL: http://svn.debian.org/wsvn/nstx-ng/trunk/nstx_pstack.c?rev=15&op=diff
==============================================================================
--- trunk/nstx_pstack.c (original)
+++ trunk/nstx_pstack.c Wed May 6 21:02:52 2009
@@ -40,7 +40,12 @@
static struct nstx_item *nstx_list = NULL;
-void nstx_handlepacket(const char *ptr, size_t len,
+/**
+ * This method will parse the given packet of the given length, and if it does correspond to a nstx packet, will decode it and add the content to the block of the right id.
+ * If the block is full, it will use the given method to send the data.
+ * This method returns the channel used.
+ */
+int nstx_handlepacket(const char *ptr, size_t len,
void (*nstx_usepacket)(const char*, size_t)) {
struct nstxhdr nh;
struct nstx_item *nstxitem;
@@ -48,12 +53,12 @@
int netpacketlen;
if ((!ptr) || (signed int) len < (signed int) nstxhdr_size)
- return;
+ return -1;
buf2nstxhdr(ptr, &nh);
if (!nh.id)
- return;
+ return nh.chan;
nstxitem = get_item_by_id(nh.id);
@@ -65,6 +70,7 @@
nstx_usepacket(netpacket, netpacketlen);
}
check_timeouts();
+ return nh.chan;
}
static struct nstx_item * get_item_by_id(unsigned int id) {
Modified: trunk/nstx_pstack.h
URL: http://svn.debian.org/wsvn/nstx-ng/trunk/nstx_pstack.h?rev=15&op=diff
==============================================================================
--- trunk/nstx_pstack.h (original)
+++ trunk/nstx_pstack.h Wed May 6 21:02:52 2009
@@ -55,7 +55,7 @@
int seq;
};
-void nstx_handlepacket(const char *, size_t,
+int nstx_handlepacket(const char *, size_t,
void(*)(const char*, size_t));
void init_pstack(int len);
Modified: trunk/nstx_queue.c
URL: http://svn.debian.org/wsvn/nstx-ng/trunk/nstx_queue.c?rev=15&op=diff
==============================================================================
--- trunk/nstx_queue.c (original)
+++ trunk/nstx_queue.c Wed May 6 21:02:52 2009
@@ -7,33 +7,33 @@
#include "nstxfun.h"
-static struct nstxqueue *qhead = NULL;
-static int qlen = 0;
+static struct nstxqueue *qhead[16] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
+static int qlen[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
static int qtimeout = QUEUETIMEOUT;
-struct nstxqueue *finditem (unsigned short id) {
+struct nstxqueue *finditem (int channel, unsigned short id) {
struct nstxqueue *ptr;
- for (ptr = qhead; ptr; ptr = ptr->next)
+ for (ptr = qhead[channel]; ptr; ptr = ptr->next)
if (ptr->id == id)
break;
return ptr;
}
-void queueitem(unsigned short id, const char *name, const struct sockaddr_in *peer) {
+void queueitem(int channel, unsigned short id, const char *name, const struct sockaddr_in *peer) {
struct nstxqueue *ptr, *tmp;
- if (finditem(id))
+ if (finditem(channel, id))
return;
- qlen++;
+ qlen[channel]++;
ptr = malloc(sizeof(struct nstxqueue));
memset(ptr, 0, sizeof(struct nstxqueue));
- if (!qhead)
- qhead = ptr;
+ if (!qhead[channel])
+ qhead[channel] = ptr;
else {
- for (tmp = qhead; tmp->next; tmp = tmp->next)
+ for (tmp = qhead[channel]; tmp->next; tmp = tmp->next)
;
tmp->next = ptr;
}
@@ -45,26 +45,26 @@
ptr->timeout = time(NULL) + qtimeout;
}
-void queueid (unsigned short id) {
- queueitem(id, NULL, NULL);
+void queueid (int channel, unsigned short id) {
+ queueitem(channel, id, NULL, NULL);
}
-struct nstxqueue *dequeueitem (int id) {
+struct nstxqueue *dequeueitem (int channel, int id) {
static struct nstxqueue *tmp = NULL, *ptr;
- if (!qhead)
+ if (!qhead[channel])
return NULL;
- if ((id < 0) || (qhead->id == id)) {
- tmp = qhead;
- qhead = qhead->next;
- qlen--;
+ if ((id < 0) || (qhead[channel]->id == id)) {
+ tmp = qhead[channel];
+ qhead[channel] = qhead[channel]->next;
+ qlen[channel]--;
} else {
- ptr = qhead;
- for (tmp = qhead->next; tmp; tmp = tmp->next) {
+ ptr = qhead[channel];
+ for (tmp = qhead[channel]->next; tmp; tmp = tmp->next) {
if (tmp->id == id) {
ptr->next = tmp->next;
- qlen--;
+ qlen[channel]--;
break;
}
ptr = tmp;
@@ -74,24 +74,24 @@
return tmp;
}
-void timeoutqueue (void (*timeoutfn)(struct nstxqueue *)) {
+void timeoutqueue (int channel, void (*timeoutfn)(struct nstxqueue *)) {
struct nstxqueue *ptr;
time_t now;
now = time(NULL);
- while (qhead && (qhead->timeout <= now)) {
+ while (qhead[channel] && (qhead[channel]->timeout <= now)) {
if (timeoutfn)
- timeoutfn(qhead);
- ptr = qhead;
- qhead = qhead->next;
- qlen--;
+ timeoutfn(qhead[channel]);
+ ptr = qhead[channel];
+ qhead[channel] = qhead[channel]->next;
+ qlen[channel]--;
free(ptr);
}
}
-int queuelen (void) {
- return qlen;
+int queuelen (int channel) {
+ return qlen[channel];
}
void qsettimeout (int timeout) {
Modified: trunk/nstxcd.c
URL: http://svn.debian.org/wsvn/nstx-ng/trunk/nstxcd.c?rev=15&op=diff
==============================================================================
--- trunk/nstxcd.c (original)
+++ trunk/nstxcd.c Wed May 6 21:02:52 2009
@@ -47,13 +47,13 @@
#define DRQLEN 10
static void nstxc_handle_reply(char *, int);
-static int nstxc_send_packet(char *, int);
+static int nstxc_send_packet(int, char *, int);
static int nsid;
int gotpacket = 0;
static void usage(const char *prog, int code) {
- fprintf(stderr, "Usage: %s [-d tun-device] <domainname> <dns-server>\n"
+ fprintf(stderr, "Usage: %s [-d tun-device] [ -c channel ] <domainname> <dns-server>\n"
"Example: %s tun.yomama.com 125.23.53.12\n", prog, prog);
exit(code);
}
@@ -62,22 +62,31 @@
struct nstxmsg *msg;
const char *device = NULL;
int ch;
+ int channel = 0;
nsid = time(NULL);
if (argc < 3)
usage(argv[0], EX_USAGE);
- while ((ch = getopt(argc, argv, "hd:")) != -1) {
+ while ((ch = getopt(argc, argv, "hdc:")) != -1) {
switch (ch) {
case 'd':
device = optarg;
break;
case 'h':
usage(argv[0], 0);
+ case 'c':
+ channel = atoi(optarg);
+ break;
default:
usage(argv[0], EX_USAGE);
}
+ }
+
+ if(channel < 0 || channel > 15) {
+ fprintf(stderr, "Channel %d is incorrect. Channel must be beetween 0 and 15.\n", channel);
+ exit(1);
}
dns_setsuffix(argv[optind]);
@@ -92,12 +101,12 @@
if (msg->src == FROMNS) {
nstxc_handle_reply (msg->data, msg->len);
} else if (msg->src == FROMTUN) {
- nstxc_send_packet (msg->data, msg->len);
+ nstxc_send_packet (channel, msg->data, msg->len);
}
}
- timeoutqueue(NULL);
- while (queuelen() < DRQLEN)
- nstxc_send_packet (NULL, 0);
+ timeoutqueue(0, NULL);
+ while (queuelen(0) < DRQLEN)
+ nstxc_send_packet (channel, NULL, 0);
}
return 0;
@@ -116,14 +125,14 @@
data = (char*)txt2data((unsigned char*)data, &datalen);
nstx_handlepacket (data, datalen, &sendtun);
}
- qitem = dequeueitem(pkt->id);
+ qitem = dequeueitem(0, pkt->id);
if (qitem) {
free(qitem);
}
dns_free(pkt);
}
-static int nstxc_send_packet (char *data, int datalen) {
+static int nstxc_send_packet (int channel, char *data, int datalen) {
static int id = -1;
char *p;
@@ -136,7 +145,7 @@
nh.magic = NSTX_MAGIC;
nh.seq = 0;
- nh.chan = 0; /* Not use yet. Initialized to a default value. */
+ nh.chan = channel;
nh.id = id++;
nh.flags = 0;
@@ -168,7 +177,7 @@
sendns(p, l, NULL);
free(p);
- queueid(nsid);
+ queueid(0, nsid);
nsid++;
nh.seq++;
} while (datalen);
Modified: trunk/nstxd.c
URL: http://svn.debian.org/wsvn/nstx-ng/trunk/nstxd.c?rev=15&op=diff
==============================================================================
--- trunk/nstxd.c (original)
+++ trunk/nstxd.c Wed May 6 21:02:52 2009
@@ -183,7 +183,7 @@
}
void nstx_getpacket (void) {
- int len, link;
+ int len, link, channel;
const char *name, *inbuf, *data;
char *outbuf = NULL;
struct nstxmsg *msg;
@@ -200,10 +200,12 @@
if (name) {
syslog(LOG_DEBUG, "getpacket: asked for name `%s'",
name);
- queueitem(pkt->id, name, &msg->peer);
if ((data = dns_fqdn2data(name)) &&
(inbuf = nstx_decode((unsigned char*)data, &len))) {
- nstx_handlepacket(inbuf, len, &sendtun);
+ int channel = nstx_handlepacket(inbuf, len, &sendtun);
+ if(channel >= 0) {
+ queueitem(channel, pkt->id, name, &msg->peer);
+ }
}
}
dns_free(pkt);
@@ -212,23 +214,25 @@
queue_senditem(msg->data, msg->len);
}
- while (queuelen()) {
- if (!nstx_sendlist)
- break;
- qitem = dequeueitem(-1);
- pkt = dns_alloc();
- dns_setid(pkt, qitem->id);
- dns_settype(pkt, DNS_RESPONSE);
- link = dns_addquery(pkt, qitem->name);
- len = dns_getfreespace(pkt, DNS_RESPONSE);
- outbuf = dequeue_senditem(&len);
- dns_addanswer(pkt, outbuf, len, link);
- outbuf = (char*)dns_constructpacket(pkt, &len);
- sendns(outbuf, len, &qitem->peer);
- free(outbuf);
- free(qitem);
- }
- timeoutqueue(do_timeout);
+ for(channel = 0; channel < 16; channel++) {
+ while (queuelen(channel)) {
+ if (!nstx_sendlist)
+ break;
+ qitem = dequeueitem(channel, -1);
+ pkt = dns_alloc();
+ dns_setid(pkt, qitem->id);
+ dns_settype(pkt, DNS_RESPONSE);
+ link = dns_addquery(pkt, qitem->name);
+ len = dns_getfreespace(pkt, DNS_RESPONSE);
+ outbuf = dequeue_senditem(&len);
+ dns_addanswer(pkt, outbuf, len, link);
+ outbuf = (char*)dns_constructpacket(pkt, &len);
+ sendns(outbuf, len, &qitem->peer);
+ free(outbuf);
+ free(qitem);
+ }
+ timeoutqueue(channel, do_timeout);
+ }
}
Modified: trunk/nstxfun.h
URL: http://svn.debian.org/wsvn/nstx-ng/trunk/nstxfun.h?rev=15&op=diff
==============================================================================
--- trunk/nstxfun.h (original)
+++ trunk/nstxfun.h Wed May 6 21:02:52 2009
@@ -40,18 +40,20 @@
};
static const size_t nstxhdr_size = 4;
+
static inline void nstxhdr2buf(const struct nstxhdr *nh, char *buf) {
- buf[0] = nh->magic;
- buf[1] = nh->seq | (nh->chan << 4);
- buf[2] = nh->id & 0xff;
- buf[3] = (nh->id >> 8) | (nh->flags << 4);
+ buf[0] = nh->magic;
+ buf[1] = nh->seq | (nh->chan << 4);
+ buf[2] = nh->id & 0xff;
+ buf[3] = (nh->id >> 8) | (nh->flags << 4);
}
+
static inline void buf2nstxhdr(const char *buf, struct nstxhdr *nh) {
- nh->magic = buf[0];
- nh->seq = buf[1] & 0x0f;
- nh->chan = buf[1] >> 4;
- nh->id = ((unsigned short)buf[2]) | ((buf[3] & 0x0f) << 8);
- nh->flags = buf[3] >> 4;
+ nh->magic = buf[0];
+ nh->seq = buf[1] & 0x0f;
+ nh->chan = buf[1] >> 4;
+ nh->id = ((unsigned short)buf[2]) | ((buf[3] & 0x0f) << 8);
+ nh->flags = buf[3] >> 4;
}
/* flags... more to come ?! */
@@ -103,13 +105,13 @@
struct nstxqueue *next;
};
-struct nstxqueue *finditem (unsigned short);
-void queueitem (unsigned short, const char *, const struct sockaddr_in *);
-void queueid (unsigned short);
-int queuelen (void);
+struct nstxqueue *finditem (int, unsigned short);
+void queueitem (int, unsigned short, const char *, const struct sockaddr_in *);
+void queueid (int, unsigned short);
+int queuelen (int);
void qsettimeout (int);
-struct nstxqueue *dequeueitem (int);
-void timeoutqueue (void (*)(struct nstxqueue *));
+struct nstxqueue *dequeueitem (int, int);
+void timeoutqueue (int, void (*)(struct nstxqueue *));
#ifdef WITH_PKTDUMP
void pktdump (const char *, unsigned short, const char *, size_t, int);
More information about the Nstx-ng-devel
mailing list