13
13
#include "aprx.h"
14
14
15
15
16
+ // Verify the sanity of a TNC2 formatted call,
17
+ // and return a pointer to after the callsign
16
18
const char * tnc2_verify_callsign_format (const char * t , int starok , int strictax25 , const char * e )
17
19
{
18
20
const char * s = t ;
@@ -157,8 +159,15 @@ void verblog(const char *portname, int istx, const char *tnc2buf, int tnc2len) {
157
159
* It does presume that the record is in a buffer that can be written on!
158
160
*/
159
161
160
- void igate_to_aprsis (const char * portname , const int tncid , const char * tnc2buf , int tnc2addrlen , int tnc2len , const int discard0 , const int strictax25_ )
161
- {
162
+ void igate_to_aprsis (
163
+ const char * portname ,
164
+ const int tncid ,
165
+ const char * tnc2buf ,
166
+ int tnc2addrlen ,
167
+ int tnc2len ,
168
+ const int discard0 ,
169
+ const int strictax25_ ) {
170
+
162
171
const char * tp , * t , * t0 ;
163
172
const char * s ;
164
173
const char * ae ;
@@ -170,26 +179,20 @@ void igate_to_aprsis(const char *portname, const int tncid, const char *tnc2buf,
170
179
ae = tp + tnc2addrlen ; // 3rd-party recursion moves ae
171
180
e = tp + tnc2len ; // stays the same all the time
172
181
173
- redo_frame_filter :;
182
+ redo_frame_filter :;
174
183
175
184
t = tp ;
176
185
t0 = NULL ;
177
186
178
187
/* t == beginning of the TNC2 format packet */
179
188
180
- /*
181
- * If any of following matches, discard the packet!
182
- * next if ($axpath =~ m/^WIDE/io); # Begins with = is sourced by..
183
- * next if ($axpath =~ m/^RELAY/io);
184
- * next if ($axpath =~ m/^TRACE/io);
185
- */
189
+ // Check the source callsign to see if it's an invalid source
186
190
s = tnc2_forbidden_source_stationid (t , strictax25 , e );
187
191
if (s )
188
192
t = (char * ) s ;
189
193
else {
190
194
/* Forbidden in source fields.. */
191
- if (debug )
192
- printf ("TNC2 forbidden source stationid: '%.20s'\n" , t );
195
+ if (debug ) printf ("TNC2 forbidden source stationid: '%.20s'\n" , t );
193
196
goto discard ;
194
197
}
195
198
@@ -198,81 +201,67 @@ void igate_to_aprsis(const char *portname, const int tncid, const char *tnc2buf,
198
201
if (* t == '>' ) {
199
202
++ t ;
200
203
} else {
201
- if (debug )
202
- printf ("TNC2 bad address format, expected '>', got: '%.20s'\n" , t );
204
+ if (debug ) printf ("TNC2 bad address format, expected '>', got: '%.20s'\n" , t );
203
205
goto discard ;
204
206
}
205
207
206
208
s = tnc2_forbidden_destination_stationid (t , strictax25 , e );
207
209
if (s )
208
210
t = (char * ) s ;
209
211
else {
210
- if (debug )
211
- printf ("TNC2 forbidden (by REGEX) destination stationid: '%.20s'\n" , t );
212
+ if (debug ) printf ("TNC2 forbidden (by REGEX) destination stationid: '%.20s'\n" , t );
212
213
goto discard ;
213
214
}
214
215
215
216
while (* t && t < ae ) {
216
217
if (* t == ',' ) {
217
218
++ t ;
218
219
} else {
219
- if (debug )
220
- printf ("TNC2 via address syntax bug, wanted ',' or ':', got: '%.20s'\n" , t );
220
+ if (debug ) printf ("TNC2 via address syntax bug, wanted ',' or ':', got: '%.20s'\n" , t );
221
221
goto discard ;
222
222
}
223
223
224
- /*
225
- * next if ($axpath =~ m/RFONLY/io); # Has any of these in via fields..
226
- * next if ($axpath =~ m/TCPIP/io);
227
- * next if ($axpath =~ m/TCPXX/io);
228
- * next if ($axpath =~ m/NOGATE/io); # .. drop it.
229
- */
224
+ // Sanity check the via hops to make sure we don't have a TCP/IP via
225
+ // or a NOGATE via so we shouldn't gateway this to the Internet
230
226
231
227
s = tnc2_forbidden_via_stationid (t , strictax25 , e );
232
228
if (!s ) {
233
229
/* Forbidden in via fields.. */
234
- if (debug )
235
- printf ("TNC2 forbidden VIA stationid, got: '%.20s'\n" , t );
230
+ if (debug ) printf ("TNC2 forbidden VIA stationid, got: '%.20s'\n" , t );
236
231
goto discard ;
237
232
} else
238
233
t = (char * ) s ;
239
234
240
-
241
235
}
242
- /* Now we have processed the address, this should be ABORT time if
243
- the current character is not ':' ! */
236
+
237
+ // We've now parsed the whole header. The next character REALLY needs to be
238
+ // a colon, or something is terribly wrong.
244
239
if (* t == ':' ) {
245
- /* Don't zero! */
246
- ++ t ;
240
+ /* Don't zero! */
241
+ ++ t ;
247
242
} else {
248
- if (debug )
249
- printf ("TNC2 address parsing did not find ':': '%.20s'\n" ,t );
243
+ if (debug ) printf ("TNC2 address parsing did not find ':': '%.20s'\n" ,t );
250
244
goto discard ;
251
245
}
252
246
t0 = t ; // Start of payload
253
247
254
248
/* Now 't' points to data.. */
255
249
256
250
257
- /*
258
- if (tnc2_forbidden_data(t)) {
259
- if (debug)
260
- printf("Forbidden data in TNC2 packet - REGEX match");
261
- goto discard;
262
- }
263
- */
264
-
265
- /* Will not relay messages that begin with '?' char: */
251
+ // DON'T I-gate ? APRS query packets, since that can cause bad things
266
252
if (* t == '?' ) {
267
- if (debug )
268
- printf ("Will not relay packets where payload begins with '?'\n" );
253
+ if (debug ) printf ("Will not I-gate packets where payload begins with '?'\n" );
269
254
goto discard ;
270
255
}
271
256
272
257
/* Messages begining with '}' char are 3rd-party frames.. */
273
258
if (* t == '}' ) {
274
259
/* DEBUG OUTPUT TO STDOUT ! */
275
260
verblog (portname , 0 , tp , tnc2len );
261
+ // Let's log the whole packet which we received
262
+ // But we're definitely discarding the outer packet because it's
263
+ // Third party
264
+ rflog (portname , 'd' , discard , tp , tnc2len );
276
265
277
266
strictax25 = 0 ;
278
267
/* Copy the 3rd-party message content into begining of the buffer... */
@@ -283,8 +272,8 @@ void igate_to_aprsis(const char *portname, const int tncid, const char *tnc2buf,
283
272
// Address end must be searched again
284
273
ae = memchr (tp , ':' , tnc2len );
285
274
if (ae == NULL ) {
286
- // Bad 3rd-party frame
287
- goto discard ;
275
+ // Bad 3rd-party frame
276
+ goto discard ;
288
277
}
289
278
tnc2addrlen = (int )(ae - tp );
290
279
@@ -303,24 +292,23 @@ void igate_to_aprsis(const char *portname, const int tncid, const char *tnc2buf,
303
292
* future packet formats, experiments and improvements. The
304
293
* packet's sender and recipient should agree on the format only.
305
294
*/
306
-
295
+
307
296
/* _NO_ ending CRLF, the APRSIS subsystem adds it. */
308
297
309
298
discard = aprsis_queue (tp , tnc2addrlen , qTYPE_IGATED , portname , t0 , e - t0 ); /* Send it.. */
310
299
/* DEBUG OUTPUT TO STDOUT ! */
311
300
verblog (portname , 0 , tp , tnc2len );
312
301
313
302
if (0 ) {
314
- discard :;
315
-
303
+ discard :;
316
304
discard = -1 ;
317
305
}
318
306
319
307
if (discard ) {
320
308
erlang_add (portname , ERLANG_DROP , tnc2len , 1 );
321
- rflog (portname , 'd' , discard , tp , tnc2len );
309
+ rflog (portname , 'd' , discard , tp , tnc2len );
322
310
} else {
323
- rflog (portname , 'R' , discard , tp , tnc2len );
311
+ rflog (portname , 'R' , discard , tp , tnc2len );
324
312
}
325
313
}
326
314
0 commit comments