Explitely flag INPORT functionality on a port, alike UPLINK

git-svn-id: http://repo.ham.fi/svn/aprsc/trunk@225 3ce903b1-3385-4e86-93cd-f9a4a239f7ac
This commit is contained in:
Matti Aarnio 2008-03-22 17:27:53 +00:00
parent 01f5b9d3f7
commit 8e0053539e
5 changed files with 33 additions and 29 deletions

View File

@ -415,7 +415,7 @@ int do_listen(struct listen_config_t **lq, int argc, char **argv)
int i, port;
struct listen_config_t *l;
struct addrinfo req, *ai;
int clflags = 0;
int clflags = CLFLAGS_INPORT;
memset(&req, 0, sizeof(req));
req.ai_family = 0;
@ -428,15 +428,15 @@ int do_listen(struct listen_config_t **lq, int argc, char **argv)
return -1;
if (strcasecmp(argv[2], "userfilter") == 0) {
clflags = CLFLAGS_USERFILTEROK;
clflags |= CLFLAGS_USERFILTEROK;
} else if (strcasecmp(argv[2], "fullfeed") == 0) {
clflags = CLFLAGS_FULLFEED;
clflags |= CLFLAGS_FULLFEED;
} else if (strcasecmp(argv[2], "dupefeed") == 0) {
clflags = CLFLAGS_DUPEFEED;
clflags |= CLFLAGS_DUPEFEED;
} else if (strcasecmp(argv[2], "messageonly") == 0) {
clflags = CLFLAGS_MESSAGEONLY;
clflags |= CLFLAGS_MESSAGEONLY;
} else if (strcasecmp(argv[2], "uplinksim") == 0) {
clflags = CLFLAGS_UPLINKSIM;
clflags = CLFLAGS_UPLINKSIM; /* _removes_ INPORT flag! */
} else {
hlog(LOG_ERR, "Listen: unknown quality token: %s", argv[2]);
}

View File

@ -49,9 +49,9 @@ int is_verified_client_login(char *s, int len)
#define MAX_Q_CALLS 64
int q_dropcheck(struct client_t *c, char *new_q, int new_q_size,
int new_q_len, char q_proto, char q_type, char *q_start,
char *path_end)
static int q_dropcheck( struct client_t *c, char *new_q, int new_q_size,
int new_q_len, char q_proto, char q_type, char *q_start,
char *path_end )
{
char *qcallv[MAX_Q_CALLS+1];
int qcallc;
@ -148,7 +148,9 @@ int q_dropcheck(struct client_t *c, char *new_q, int new_q_size,
/* 2) */
if (l == username_len && strncasecmp(qcallv[i], c->username, username_len) == 0) {
/* ok, login is client's login, handle step 3) */
if (c->state == CSTATE_CONNECTED && i != qcallc - 1) {
if (c->state == CSTATE_CONNECTED &&
(c->flags & CLFLAGS_INPORT) &&
(i != qcallc - 1)) {
/* 3) hits: from an inbound connection, client login found in path,
* but is not the last viacall
* TODO: should dump...
@ -256,7 +258,8 @@ int q_process(struct client_t *c, char *new_q, int new_q_size, char *via_start,
* All packets from an inbound connection that would normally be passed per current validation algorithm:
*/
if (c->state == CSTATE_CONNECTED) {
if (c->state == CSTATE_CONNECTED &&
(c->flags & CLFLAGS_INPORT)) {
/*
* If the packet entered the server from an UDP port:
* {
@ -378,7 +381,7 @@ int q_process(struct client_t *c, char *new_q, int new_q_size, char *via_start,
} else {
/* Replace ,VIACALL,I with qAr,VIACALL */
*path_end = p;
new_q_len = snprintf(new_q, new_q_size, ",qAr,%.*s", prevcall_end - prevcall, prevcall);
new_q_len = snprintf(new_q, new_q_size, ",qAr,%.*s", (int)(prevcall_end - prevcall), prevcall);
q_proto = 'A';
q_type = 'r';
}
@ -451,7 +454,7 @@ int q_process(struct client_t *c, char *new_q, int new_q_size, char *via_start,
} else {
/* Replace ,VIACALL,I with qAr,VIACALL */
*path_end = p;
new_q_len = snprintf(new_q, new_q_size, ",qAr,%.*s", prevcall_end - prevcall, prevcall);
new_q_len = snprintf(new_q, new_q_size, ",qAr,%.*s", (int)(prevcall_end - prevcall), prevcall);
q_proto = 'A';
q_type = 'r';
}
@ -486,7 +489,7 @@ int q_process(struct client_t *c, char *new_q, int new_q_size, char *via_start,
* Untested at the time of implementation (no uplink support yet)
*/
if (!q_proto && (c->state == CSTATE_UPLINK || c->state == CSTATE_UPLINKSIM)) {
if (!q_proto && (c->flags & (CLFLAGS_UPLINKPORT|CLFLAGS_UPLINKSIM))) {
if (pathlen > 2 && *(*path_end -1) == 'I' && *(*path_end -2) == ',') {
// fprintf(stderr, "\tpath has ,I in the end\n");
/* the path is terminated with ,I - lookup previous callsign in path */
@ -499,7 +502,7 @@ int q_process(struct client_t *c, char *new_q, int new_q_size, char *via_start,
// fprintf(stderr, "\tprevious callsign is %.*s\n", prevcall_end - prevcall, prevcall);
/* Replace ,VIACALL,I with qAr,VIACALL */
*path_end = p;
new_q_len = snprintf(new_q, new_q_size, ",qAr,%.*s", prevcall_end - prevcall, prevcall);
new_q_len = snprintf(new_q, new_q_size, ",qAr,%.*s", (int)(prevcall_end - prevcall), prevcall);
q_proto = 'A';
q_type = 'r';
} else {

View File

@ -253,7 +253,7 @@ int make_uplink(struct uplink_config_t *l)
c = client_alloc();
c->fd = fd;
c->addr = sa;
c->state = CSTATE_UPLINK;
c->state = CSTATE_CONNECTED;
c->addr_s = hstrdup(eb);
c->keepalive = now;
/* use the default login handler */

View File

@ -125,7 +125,8 @@ int worker_sighandler(int signum)
void close_client(struct worker_t *self, struct client_t *c)
{
hlog( LOG_DEBUG, "Worker %d disconnecting %s fd %d: %s",
self->id, c->state == CSTATE_CONNECTED ? "client":"uplink", c->fd, c->addr_s);
self->id, ( (c->flags & (CLFLAGS_UPLINKPORT|CLFLAGS_UPLINKSIM))
? "client":"uplink" ), c->fd, c->addr_s);
/* close */
if (c->fd >= 0) {
@ -147,7 +148,7 @@ void close_client(struct worker_t *self, struct client_t *c)
/* if this happens to be the uplink, tell the uplink module that the
* connection has gone away
*/
if (c->state == CSTATE_UPLINK)
if (c->flags & CLFLAGS_UPLINKPORT)
uplink_close(c);
/* free it up */
@ -530,9 +531,8 @@ void send_keepalives(struct worker_t *self)
// the c may get destroyed from underneath of ourselves!
cnext = c->next;
if (// c->state == CSTATE_UPLINK ||
c->state == CSTATE_UPLINKSIM ||
c->state == CSTATE_COREPEER)
if ( c->flags & (CLFLAGS_UPLINKSIM|CLFLAGS_UPLINKPORT) ||
c->state == CSTATE_COREPEER )
continue;
/* No keepalives on UPLINK or PEER links.. */

View File

@ -128,11 +128,11 @@ extern struct pbuf_t *pbuf_global_dupe_last;
extern struct pbuf_t **pbuf_global_dupe_prevp;
/* a network client */
#define CSTATE_LOGIN 0
#define CSTATE_CONNECTED 1
#define CSTATE_COREPEER 2
#define CSTATE_UPLINK 3
#define CSTATE_UPLINKSIM 4
typedef enum {
CSTATE_LOGIN,
CSTATE_CONNECTED,
CSTATE_COREPEER
} CStateEnum;
struct worker_t; /* used in client_t, but introduced later */
struct filter_t; /* used in client_t, but introduced later */
@ -178,15 +178,16 @@ struct client_t {
#endif
int32_t flags; /* bit flags on what kind of client this is */
#define CLFLAGS_USERFILTEROK 0x001 /* Permits entry of user defined filters */
#define CLFLAGS_INPORT 0x001
#define CLFLAGS_UPLINKPORT 0x002
#define CLFLAGS_UPLINKSIM 0x004
#define CLFLAGS_PORT_RO 0x010
#define CLFLAGS_PORT_RO 0x008
#define CLFLAGS_USERFILTEROK 0x010 /* Permits entry of user defined filters */
#define CLFLAGS_FULLFEED 0x100 /* Together with filter t/c* -- which really implements it */
#define CLFLAGS_DUPEFEED 0x200 /* Duplicates are also sent to client */
#define CLFLAGS_MESSAGEONLY 0x400 /* Together with filter t/m -- which really implements it */
char state; /* state of the client... one of CSTATE_* */
CStateEnum state; /* state of the client... one of CSTATE_* */
char warned; /* the client has been warned that it has bad filter definition */
char *username; /* The callsign */
char *app_name; /* application name, from 'user' command */