-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAXHEARD.C
287 lines (261 loc) · 7.06 KB
/
AXHEARD.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/* AX25 link callsign monitoring. Also contains beginnings of
* an automatic link quality monitoring scheme (incomplete)
*
* Copyright 1991 Phil Karn, KA9Q
*/
#include <ctype.h>
#include "global.h"
#ifdef AX25
#include "mbuf.h"
#include "iface.h"
#include "ax25.h"
#include "ip.h"
#include "timer.h"
#define iscallsign(c) ((isupper(c)) || (isdigit(c)) || (c ==' '))
int axheard_filter_flag = AXHEARD_PASS;
static struct lq *al_create __ARGS((struct iface *ifp,char *addr));
static struct ld *ad_lookup __ARGS((struct iface *ifp,char *addr,int sort));
static struct ld *ad_create __ARGS((struct iface *ifp,char *addr));
struct lq *Lq;
struct ld *Ld;
#ifdef notdef
/* Send link quality reports to interface */
void
genrpt(ifp)
struct iface *ifp;
{
struct mbuf *bp;
register char *cp;
int i;
struct lq *lp;
int maxentries,nentries;
maxentries = (Paclen - LQHDR) / LQENTRY;
if((bp = alloc_mbuf(Paclen)) == NULLBUF)
return;
cp = bp->data;
nentries = 0;
/* Build and emit header */
cp = putlqhdr(cp,LINKVERS,Ip_addr);
/* First entry is for ourselves. Since we're examining the Axsent
* variable before we've sent this frame, add one to it so it'll
* match the receiver's count after he gets this frame.
*/
cp = putlqentry(cp,ifp->hwaddr,Axsent+1);
nentries++;
/* Now add entries from table */
for(lp = lq;lp != NULLLQ;lp = lp->next){
cp = putlqentry(cp,&lp->addr,lp->currxcnt);
if(++nentries >= MAXENTRIES){
/* Flush */
bp->cnt = nentries*LQENTRY + LQHDR;
ax_output(ifp,Ax25multi[0],ifp->hwaddr,PID_LQ,bp);
if((bp = alloc_mbuf(Paclen)) == NULLBUF)
return;
cp = bp->data;
}
}
if(nentries > 0){
bp->cnt = nentries*LQENTRY + LQHDR;
ax_output(ifp,Ax25multi[0],ifp->hwaddr,LQPID,bp);
} else {
free_p(bp);
}
}
/* Pull the header off a link quality packet */
void
getlqhdr(hp,bpp)
struct lqhdr *hp;
struct mbuf **bpp;
{
hp->version = pull16(bpp);
hp->ip_addr = pull32(bpp);
}
/* Put a header on a link quality packet.
* Return pointer to buffer immediately following header
*/
char *
putlqhdr(cp,version,ip_addr)
register char *cp;
int16 version;
int32 ip_addr;
{
cp = put16(cp,version);
return put32(cp,ip_addr);
}
/* Pull an entry off a link quality packet */
void
getlqentry(ep,bpp)
struct lqentry *ep;
struct mbuf **bpp;
{
pullup(bpp,ep->addr,AXALEN);
ep->count = pull32(bpp);
}
/* Put an entry on a link quality packet
* Return pointer to buffer immediately following header
*/
char *
putlqentry(cp,addr,count)
char *cp;
char *addr;
int32 count;
{
memcpy(cp,addr,AXALEN);
cp += AXALEN;
return put32(cp,count);
}
#endif
/* Log the source address of an incoming packet */
void
logsrc(ifp,addr)
struct iface *ifp;
char *addr;
{
register struct lq *lp;
if(axheard_filter_flag & AXHEARD_NOSRC || !(ifp->flags & LOG_AXHEARD))
return;
{
register unsigned char c;
register int i = 0;
while(i < AXALEN-1){
c = *(addr+i);
c >>= 1;
if(!iscallsign(c))
return;
i++;
}
}
if((lp = al_lookup(ifp,addr,1)) == NULLLQ)
if((lp = al_create(ifp,addr)) == NULLLQ)
return;
lp->currxcnt++;
lp->time = secclock();
}
/* Log the destination address of an incoming packet */
void
logdest(ifp,addr)
struct iface *ifp;
char *addr;
{
register struct ld *lp;
if(axheard_filter_flag & AXHEARD_NODST || !(ifp->flags & LOG_AXHEARD))
return;
{
register unsigned char c;
register int i = 0;
while(i < AXALEN-1){
c = *(addr+i);
c >>= 1;
if(!iscallsign(c))
return;
i++;
}
}
if((lp = ad_lookup(ifp,addr,1)) == NULLLD)
if((lp = ad_create(ifp,addr)) == NULLLD)
return;
lp->currxcnt++;
lp->time = secclock();
}
/* Look up an entry in the source data base */
struct lq *
al_lookup(ifp,addr,sort)
struct iface *ifp;
char *addr;
int sort;
{
register struct lq *lp;
struct lq *lplast = NULLLQ;
for(lp = Lq;lp != NULLLQ;lplast = lp,lp = lp->next){
if((lp->iface == ifp) && addreq(lp->addr,addr)){
if(sort && lplast != NULLLQ){
/* Move entry to top of list */
lplast->next = lp->next;
lp->next = Lq;
Lq = lp;
}
return lp;
}
}
return NULLLQ;
}
extern int Maxax25heard;
/* Create a new entry in the source database */
/* If there are too many entries, override the oldest one - WG7J */
static struct lq *
al_create(ifp,addr)
struct iface *ifp;
char *addr;
{
extern int numal; /* in ax25cmd.c - K5JB */
register struct lq *lp;
struct lq *lplast = NULLLQ;
if(Maxax25heard && numal == Maxax25heard) {
/* find and use last one in list */
for(lp = Lq;lp->next != NULLLQ;lplast = lp,lp = lp->next);
/* delete entry from end */
if(lplast)
lplast->next = NULLLQ;
else /* Only one entry, and maxax25heard = 1 ! */
Lq = NULLLQ;
lp->currxcnt = 0;
} else { /* create a new entry */
numal++;
lp = (struct lq *)callocw(1,sizeof(struct lq));
}
memcpy(lp->addr,addr,AXALEN);
lp->iface = ifp;
lp->next = Lq;
Lq = lp;
return lp;
}
/* Look up an entry in the destination database */
static struct ld *
ad_lookup(ifp,addr,sort)
struct iface *ifp;
char *addr;
int sort;
{
register struct ld *lp;
struct ld *lplast = NULLLD;
for(lp = Ld;lp != NULLLD;lplast = lp,lp = lp->next){
if((lp->iface == ifp) && addreq(lp->addr,addr)){
if(sort && lplast != NULLLD){
/* Move entry to top of list */
lplast->next = lp->next;
lp->next = Ld;
Ld = lp;
}
return lp;
}
}
return NULLLD;
}
/* Create a new entry in the destination database */
static struct ld *
ad_create(ifp,addr)
struct iface *ifp;
char *addr;
{
extern int numad; /* In ax25cmd.c - K5JB */
register struct ld *lp;
struct ld *lplast = NULLLD;
if(Maxax25heard && numad == Maxax25heard) { /* find and use last one in list */
for(lp = Ld;lp->next != NULLLD;lplast = lp,lp = lp->next);
/* delete entry from end */
if(lplast)
lplast->next = NULLLD;
else
Ld = NULLLD;
lp->currxcnt = 0;
} else { /* create a new entry */
numad++;
lp = (struct ld *)callocw(1,sizeof(struct ld));
}
memcpy(lp->addr,addr,AXALEN);
lp->iface = ifp;
lp->next = Ld;
Ld = lp;
return lp;
}
#endif /* AX25 */