summaryrefslogtreecommitdiffstats
path: root/sys/netinet/ip_fw.c
blob: 3b2f9388320e6e28cdfa8d57b8fc8314c76c9530 (plain)
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
/*
 * Copyright (c) 1993 Daniel Boulet
 * Copyright (c) 1994 Ugen J.S.Antsilevich
 *
 * Redistribution and use in source forms, with and without modification,
 * are permitted provided that this entire comment appears intact.
 *
 * Redistribution in binary form may occur without any restrictions.
 * Obviously, it would be nice if you gave credit where credit is due
 * but requiring it would be too onerous.
 *
 * This software is provided ``AS IS'' without any warranties of any kind.
 */

/*
 * Implement IP packet firewall
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/domain.h>
#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/errno.h>
#include <sys/time.h>
#include <sys/kernel.h>

#include <net/if.h>
#include <net/route.h>

#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/in_pcb.h>
#include <netinet/in_var.h>
#include <netinet/ip_var.h>
#include <netinet/ip_icmp.h>

#include <netinet/ip_fw.h>

struct ip_fw *ip_fw_fwd_chain;
struct ip_fw *ip_fw_blk_chain;
int ip_fw_policy=1;


inline
void
print_ip(xaddr)
struct in_addr xaddr;
{
    u_long addr = ntohl(xaddr.s_addr);
    printf("%d.%d.%d.%d",(addr>>24) & 0xff,
                         (addr>>16)&0xff,
                         (addr>>8)&0xff,
                         addr&0xFF);
}                  


/*
 * Returns 1 if the port is matched by the vector, 0 otherwise
 */

inline
int port_match(portptr,nports,port,range_flag)
u_short *portptr;
int nports;
u_short port;
int range_flag;
{
    if ( range_flag ) {
	if ( portptr[0] <= port && port <= portptr[1] ) {
	    return( 1 );
	}
	nports -= 2;
	portptr += 2;
    }
    while ( nports-- > 0 ) {
	if ( *portptr++ == port ) {
	    return( 1 );
	}
    }
    return(0);
}


/*
 * Returns 0 if packet should be dropped, 1 or more if it should be accepted
 */


int ip_fw_chk(ip,chain)
struct ip *ip;
struct ip_fw *chain;
{
    struct in_addr src, dst;
    char got_proto = 0;
    int frwl_proto, proto = 0;
    register struct ip_fw *fptr;
    u_short src_port = 0, dst_port = 0;
#ifdef IPFIREWALL_VERBOSE
    u_short *portptr = (u_short *)&(((u_int *)ip)[ip->ip_hl]);
#endif

    if ( chain == NULL ) {	/* Is there a frwl chain? */
	return(1);
    }

    src = ip->ip_src;
    dst = ip->ip_dst;

#ifdef DEBUG_IPFIREWALL
    {
	u_short *portptr = (u_short *)&(((u_int *)ip)[ip->ip_hl]);
	printf("packet ");
	switch(ip->ip_p) {
	case IPPROTO_TCP: printf("TCP "); break;
	case IPPROTO_UDP: printf("UDP "); break;
	case IPPROTO_ICMP: printf("ICMP:%d ",((char *)portptr)[0]&0xff); break;
	default: printf("p=%d ",ip->ip_p); break;
	}
	print_ip(ip->ip_src);
	if ( ip->ip_p == IPPROTO_TCP || ip->ip_p == IPPROTO_UDP ) {
	    printf(":%d ",ntohs(portptr[0]));
	}
	print_ip(ip->ip_dst);
	if ( ip->ip_p == IPPROTO_TCP || ip->ip_p == IPPROTO_UDP ) {
	    printf(":%d ",ntohs(portptr[1]));
	}
	printf("\n");
    }
#endif

    for ( fptr = chain; fptr != NULL; fptr = fptr->next ) {

	if ( (src.s_addr & fptr->src_mask.s_addr) == fptr->src.s_addr
	&&   (dst.s_addr & fptr->dst_mask.s_addr) == fptr->dst.s_addr ) {

	    if ( (frwl_proto = fptr->flags & IP_FW_F_KIND)
					== IP_FW_F_ALL ) {

		/* Universal frwl - we've got a match! */

#ifdef DEBUG_IPFIREWALL
		printf("universal frwl match\n");
#endif
#ifdef IPFIREWALL_VERBOSE
		/*
		 * VERY ugly piece of code which actually
		 * makes kernel printf for denyed packets...
		 * This thingy will be added in more places...
		 */
    if (  !(fptr->flags & IP_FW_F_ACCEPT) &&
          (fptr->flags & IP_FW_F_PRN)) {
	printf("ip_fw_chk says no to ");
	switch(ip->ip_p) {
	case IPPROTO_TCP: printf("TCP "); break;
	case IPPROTO_UDP: printf("UDP "); break;
	case IPPROTO_ICMP: printf("ICMP:%d ",((char *)portptr)[0]&0xff); break;
	default: printf("p=%d ",ip->ip_p); break;
	}
	print_ip(ip->ip_src);
	if ( ip->ip_p == IPPROTO_TCP || ip->ip_p == IPPROTO_UDP ) {
	    printf(":%d ",ntohs(portptr[0]));
	} else {
	    printf("\n");
	}
	print_ip(ip->ip_dst);
	if ( ip->ip_p == IPPROTO_TCP || ip->ip_p == IPPROTO_UDP ) {
	    printf(":%d ",ntohs(portptr[1]));
	}
	printf("\n");
	return(0);
    }
#endif
		return( fptr->flags & IP_FW_F_ACCEPT );
	    } else {

	/* Specific frwl - packet's protocol must match frwl's */

	if ( !got_proto ) {
	    u_short *portptr = (u_short *)&(((u_int *)ip)[ip->ip_hl]);
	    switch( ip->ip_p ) {
	    case IPPROTO_TCP:
		proto = IP_FW_F_TCP;
		src_port = ntohs(portptr[0]);	/* first two shorts in TCP */
		dst_port = ntohs(portptr[1]);	/* are src and dst ports */
		break;
	    case IPPROTO_UDP:
		proto = IP_FW_F_UDP;
		src_port = ntohs(portptr[0]);	/* first two shorts in UDP */
		dst_port = ntohs(portptr[1]);	/* are src and dst ports */
		break;
	    case IPPROTO_ICMP:
		proto = IP_FW_F_ICMP;
		break;
	    default: proto = IP_FW_F_ALL;
#ifdef DEBUG_IPFIREWALL
		printf("non TCP/UDP packet\n");
#endif
		    }
		    got_proto = 1;
		}

		if ( proto == frwl_proto ) {

		    if (
			proto == IP_FW_F_ICMP
		    ||
			(
			    (
				fptr->n_src_p == 0
			    ||
				port_match( &fptr->ports[0],
					    fptr->n_src_p,
					    src_port,
					    fptr->flags & IP_FW_F_SRNG
					  )
			    )
			&&
			    (
				fptr->n_dst_p == 0
			    ||
				port_match( &fptr->ports[fptr->n_src_p],
					    fptr->n_dst_p,
					    dst_port,
					    fptr->flags & IP_FW_F_DRNG
					  )
			    )
			)
		    ) {

#ifdef IPFIREWALL_VERBOSE
		/*
		 * VERY ugly piece of code which actually
		 * makes kernel printf for denyed packets...
		 * This thingy will be added in more places...
		 */
    if (  !(fptr->flags & IP_FW_F_ACCEPT) &&
          (fptr->flags & IP_FW_F_PRN)) {
	printf("ip_fw_chk says no to ");
	switch(ip->ip_p) {
	case IPPROTO_TCP: printf("TCP "); break;
	case IPPROTO_UDP: printf("UDP "); break;
	case IPPROTO_ICMP: printf("ICMP:%d ",((char *)portptr)[0]&0xff); break;
	default: printf("p=%d ",ip->ip_p); break;
	}
	print_ip(ip->ip_src);
	if ( ip->ip_p == IPPROTO_TCP || ip->ip_p == IPPROTO_UDP ) {
	    printf(":%d ",ntohs(portptr[0]));
	} else {
	    printf("\n");
	}
	print_ip(ip->ip_dst);
	if ( ip->ip_p == IPPROTO_TCP || ip->ip_p == IPPROTO_UDP ) {
	    printf(":%d ",ntohs(portptr[1]));
	}
	printf("\n");
	return(0);
    }
#endif
			return( fptr->flags & IP_FW_F_ACCEPT);
		    }

		}

	    }

	}

    }

    /*
     * If we get here then none of the frwls matched.
     * So now we relay on policy defined by user-unmatched packet can
     * be ever accepted or rejected...
     */

#ifdef IPFIREWALL_VERBOSE
		/*
		 * VERY ugly piece of code which actually
		 * makes kernel printf for denyed packets...
		 * This thingy will be added in more places...
		 */
    if (  !(ip_fw_policy) &&
          (fptr->flags & IP_FW_F_PRN)) {
	printf("ip_fw_chk says no to ");
	switch(ip->ip_p) {
	case IPPROTO_TCP: printf("TCP "); break;
	case IPPROTO_UDP: printf("UDP "); break;
	case IPPROTO_ICMP: printf("ICMP:%d ",((char *)portptr)[0]&0xff); break;
	default: printf("p=%d ",ip->ip_p); break;
	}
	print_ip(ip->ip_src);
	if ( ip->ip_p == IPPROTO_TCP || ip->ip_p == IPPROTO_UDP ) {
	    printf(":%d ",ntohs(portptr[0]));
	} else {
	    printf("\n");
	}
	print_ip(ip->ip_dst);
	if ( ip->ip_p == IPPROTO_TCP || ip->ip_p == IPPROTO_UDP ) {
	    printf(":%d ",ntohs(portptr[1]));
	}
	printf("\n");
	return(0);
    }
#endif
    return(ip_fw_policy);

}


static
void
free_fw_chain(chainptr)
struct ip_fw **chainptr;
{
int s=splnet();
    while ( *chainptr != NULL ) {
	struct ip_fw *ftmp;
	ftmp = *chainptr;
	*chainptr = ftmp->next;
	free(ftmp,M_SOOPTS);
    }
splx(s);
}

static
int
add_to_chain(chainptr,frwl)
struct ip_fw **chainptr;
struct ip_fw *frwl;
{
    struct ip_fw *ftmp;
    struct ip_fw *chtmp=NULL;
    struct ip_fw *chtmp_prev=NULL;
    int s=splnet();
    u_long m_src_mask,m_dst_mask;
    u_long n_sa,n_da,o_sa,o_da,o_sm,o_dm,n_sm,n_dm;
    u_short n_sr,n_dr,o_sr,o_dr; 
    u_short oldkind,newkind;
    int addb4=0;
    int n_o,n_n;

    ftmp = malloc( sizeof(struct ip_fw), M_SOOPTS, M_DONTWAIT );
    if ( ftmp == NULL ) {
#ifdef DEBUG_IPFIREWALL
	printf("ip_fw_ctl:  malloc said no\n");
#endif
	splx(s);
	return( ENOSPC );
    }

    bcopy( frwl, ftmp, sizeof( struct ip_fw ) );
    ftmp->next = NULL;

    if (*chainptr==NULL)
       {
        *chainptr=ftmp;
       }
    else
       {
	chtmp_prev=NULL;
	for (chtmp=*chainptr;chtmp!=NULL;chtmp=chtmp->next) {

		addb4=0;

		newkind=ftmp->flags & IP_FW_F_KIND;
		oldkind=chtmp->flags & IP_FW_F_KIND;

		if (newkind!=IP_FW_F_ALL 
		&&  oldkind!=IP_FW_F_ALL
		&&  oldkind!=newkind)
			continue;
		/*
		 * Very very *UGLY* code...
		 * Sorry,but i had to do this....
		 */
		n_sa=ntohl(ftmp->src.s_addr);
		n_da=ntohl(ftmp->dst.s_addr);
		n_sm=ntohl(ftmp->src_mask.s_addr);
		n_dm=ntohl(ftmp->dst_mask.s_addr);

		o_sa=ntohl(chtmp->src.s_addr);
		o_da=ntohl(chtmp->dst.s_addr);
		o_sm=ntohl(chtmp->src_mask.s_addr);
		o_dm=ntohl(chtmp->dst_mask.s_addr);

		m_src_mask = o_sm & n_sm;
		m_dst_mask = o_dm & n_dm;

		if ((o_sa & m_src_mask) == (n_sa & m_src_mask)) {
			if (n_sm > o_sm) 
				addb4++;
			if (n_sm < o_sm) 
				addb4--;
		}

		if ((o_da & m_dst_mask) == (n_da & m_dst_mask)) {
			if (n_dm > o_dm)
				addb4++;
			if (n_dm < o_dm)
				addb4--;
		}

		if (((o_da & o_dm) == (n_da & n_dm))
                  &&((o_sa & o_sm) == (n_sa & n_sm)))
		{
			if (newkind!=IP_FW_F_ALL &&
			    oldkind==IP_FW_F_ALL)
				addb4++;
			if (newkind==oldkind && (oldkind==IP_FW_F_TCP
					     ||  oldkind==IP_FW_F_UDP)) {

				/*
				 * Here the main ide is to check the size
				 * of port range which the frwl covers
				 * We actually don't check their values but
				 * just the wideness of range they have
				 * so that less wide ranges or single ports
				 * go first and wide ranges go later. No ports
				 * at all treated as a range of maximum number
				 * of ports.
				 */

				if (ftmp->flags & IP_FW_F_SRNG) 
					n_sr=ftmp->ports[1]-ftmp->ports[0];
				else 
					n_sr=(ftmp->n_src_p)?
						ftmp->n_src_p : USHRT_MAX;
					
				if (chtmp->flags & IP_FW_F_SRNG) 
				     o_sr=chtmp->ports[1]-chtmp->ports[0];
				else 
				     o_sr=(chtmp->n_src_p)?
				 	    chtmp->n_src_p : USHRT_MAX;

				if (n_sr<o_sr)
					addb4++;
				if (n_sr>o_sr)
					addb4--;
					
				n_n=ftmp->n_src_p;
				n_o=chtmp->n_src_p;
		/*
		 * Actually this cannot happen as the frwl control
		 * procedure checks for number of ports in source and
		 * destination range but we will try to be more safe.
		 */
				if ((n_n>(IP_FW_MAX_PORTS-2)) ||
				    (n_o>(IP_FW_MAX_PORTS-2)))
					goto skip_check;

				if (ftmp->flags & IP_FW_F_DRNG) 
				       n_dr=ftmp->ports[n_n+1]-ftmp->ports[n_n];
				else 
				       n_dr=(ftmp->n_dst_p)?
						ftmp->n_dst_p : USHRT_MAX;

				if (chtmp->flags & IP_FW_F_DRNG) 
				       o_dr=chtmp->ports[n_o+1]-chtmp->ports[n_o];
				else 
				       o_dr=(chtmp->n_dst_p)?
						chtmp->n_dst_p : USHRT_MAX;
				if (n_dr<o_dr)
					addb4++;
				if (n_dr>o_dr)
					addb4--;

skip_check:
			}
		}
		if (addb4>0) {
			if (chtmp_prev) {
				chtmp_prev->next=ftmp; 
				ftmp->next=chtmp;
			} else {
				*chainptr=ftmp;
				ftmp->next=chtmp;
			}
			splx(s);
			return 0;
		}
		chtmp_prev=chtmp;
	}
	if (chtmp_prev)
		chtmp_prev->next=ftmp;
	else
#define wrong
#ifdef wrong
        	*chainptr=ftmp;
#else
	panic("Can't happen");
#endif
#undef wrong
       }
    splx(s);
    return(0);
}

static
int
del_from_chain(chainptr,frwl)
struct ip_fw **chainptr;
struct ip_fw *frwl;
{
    struct ip_fw *ftmp,*ltmp;
    u_short	tport1,tport2,tmpnum;
    char	matches,was_found;
    int s=splnet();

    ftmp=*chainptr;

    if ( ftmp == NULL ) {
#ifdef DEBUG_IPFIREWALL
	printf("ip_fw_ctl:  chain is empty\n");
#endif
	splx(s);
	return( EINVAL );
    			}

    ltmp=NULL;
    was_found=0;

    while( ftmp != NULL )
    {
     matches=1;
     if ((bcmp(&ftmp->src,&frwl->src,sizeof(struct in_addr))) 
     || (bcmp(&ftmp->src_mask,&frwl->src_mask,sizeof(struct in_addr)))
     || (bcmp(&ftmp->dst,&frwl->dst,sizeof(struct in_addr)))
     || (bcmp(&ftmp->dst_mask,&frwl->dst_mask,sizeof(struct in_addr)))
     || (ftmp->flags!=frwl->flags))
        matches=0;
     tport1=ftmp->n_src_p+ftmp->n_dst_p;
     tport2=frwl->n_src_p+frwl->n_dst_p;
     if (tport1!=tport2)
        matches=0;
     else
      if (tport1!=0)
      {
       for (tmpnum=0;tmpnum < tport1 && tmpnum < IP_FW_MAX_PORTS;tmpnum++)
        if (ftmp->ports[tmpnum]!=frwl->ports[tmpnum])
           matches=0;
      }
    if(matches)
      {
        was_found=1;
        if (ltmp)
            {
              ltmp->next=ftmp->next;
	      free(ftmp,M_SOOPTS);
              ftmp=ltmp->next;
            }
        else
            {
             *chainptr=ftmp->next; 
             free(ftmp,M_SOOPTS);
             ftmp=*chainptr;
            }
       
      }
    else
      {
       ltmp = ftmp;
       ftmp = ftmp->next;
      }
    }
    splx(s);
    if (was_found) return 0;
    else return(EINVAL);
}

int
ip_fw_ctl(stage,m)
int stage;	
struct mbuf *m;
{
int *tmp_policy_ptr;
if ( stage == IP_FW_FLUSH )
       {
	free_fw_chain(&ip_fw_blk_chain);
	free_fw_chain(&ip_fw_fwd_chain);
	return(0);
       }  

	if ( m == 0 )	
          {
	    printf("ip_fw_ctl:  NULL mbuf ptr\n");
	    return( EINVAL );
          }

if ( stage == IP_FW_POLICY )
      {
	tmp_policy_ptr=mtod(m,int *);
	if ((*tmp_policy_ptr)!=1 && (*tmp_policy_ptr)!=0)
		return ( EINVAL );
	ip_fw_policy=*tmp_policy_ptr;
	return 0;
      }

	if ( stage == IP_FW_CHK_BLK || stage == IP_FW_CHK_FWD ) {

	    struct ip *ip;
	    if ( m->m_len < sizeof(struct ip) + 2 * sizeof(u_short) )	{
#ifdef DEBUG_IPFIREWALL
		printf("ip_fw_ctl:  mbuf len=%d, want at least %d\n",m->m_len,sizeof(struct ip) + 2 * sizeof(u_short));
#endif
		return( EINVAL );
	    								}
	    ip = mtod(m,struct ip *);
	    if ( ip->ip_hl != sizeof(struct ip) / sizeof(int) )	{
#ifdef DEBUG_IPFIREWALL
		printf("ip_fw_ctl:  ip->ip_hl=%d, want %d\n",ip->ip_hl,sizeof(struct ip)/sizeof(int));
#endif
		return( EINVAL );
	    							}
	    if ( ip_fw_chk(ip,
		stage == IP_FW_CHK_BLK ?
                ip_fw_blk_chain : ip_fw_fwd_chain )
	       ) 
		return(0);
	    	else	{
		return(EACCES);
	    		}

    } else if ( stage == IP_FW_ADD_BLK
	       	 || stage == IP_FW_ADD_FWD
       		 || stage == IP_FW_DEL_BLK
       		 || stage == IP_FW_DEL_FWD
                  ) {

	    struct ip_fw *frwl;

	    if ( m->m_len != sizeof(struct ip_fw) )	{
#ifdef DEBUG_IPFIREWALL
		printf("ip_fw_ctl:  len=%d, want %d\n",m->m_len,sizeof(struct ip_fw));
#endif
		return( EINVAL );
	    							}

	    frwl = mtod(m,struct ip_fw*);
	    if ( (frwl->flags & ~IP_FW_F_MASK) != 0 )	{
#ifdef DEBUG_IPFIREWALL
		printf("ip_fw_ctl:  undefined flag bits set (flags=%x)\n",frwl->flags);
#endif
		return( EINVAL );
	    								}

	    if ( (frwl->flags & IP_FW_F_SRNG) && frwl->n_src_p < 2 ) {
#ifdef DEBUG_IPFIREWALL
		printf("ip_fw_ctl:  src range set but n_src_p=%d\n",frwl->n_src_p);
#endif
		return( EINVAL );
	    }

	    if ( (frwl->flags & IP_FW_F_DRNG) && frwl->n_dst_p < 2 ) {
#ifdef DEBUG_IPFIREWALL
		printf("ip_fw_ctl:  dst range set but n_dst_p=%d\n",frwl->n_dst_p);
#endif
		return( EINVAL );
	    }

	    if ( frwl->n_src_p + frwl->n_dst_p > IP_FW_MAX_PORTS ) {
#ifdef DEBUG_IPFIREWALL
		printf("ip_fw_ctl:  too many ports (%d+%d)\n",frwl->n_src_p,frwl->n_dst_p);
#endif
		return( EINVAL );
	    }

#if 0
	    if ( (frwl->flags & IP_FW_F_KIND) == IP_FW_F_ICMP ) {
#ifdef DEBUG_IPFIREWALL
		printf("ip_fw_ctl:  request for unsupported ICMP frwling\n");
#endif
		return( EINVAL );
	    }

#endif
	    if ( stage == IP_FW_ADD_BLK )
               {
		return( add_to_chain(&ip_fw_blk_chain,frwl));
	       } 
	    if ( stage == IP_FW_ADD_FWD )
               {
		return( add_to_chain(&ip_fw_fwd_chain,frwl));
	       } 
	    if ( stage == IP_FW_DEL_BLK )
               {
		return( del_from_chain(&ip_fw_blk_chain,frwl));
	       } 
	    if ( stage == IP_FW_DEL_FWD )
               {
		return( del_from_chain(&ip_fw_fwd_chain,frwl));
	       } 
	} 

#ifdef DEBUG_IPFIREWALL
printf("ip_fw_ctl:  unknown request %d\n",stage);
#endif
return(EINVAL);

}
OpenPOWER on IntegriCloud