]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/ipfilter/fils.c
This commit was generated by cvs2svn to compensate for changes in r56173,
[FreeBSD/FreeBSD.git] / contrib / ipfilter / fils.c
1 /*
2  * Copyright (C) 1993-1998 by Darren Reed.
3  *
4  * Redistribution and use in source and binary forms are permitted
5  * provided that this notice is preserved and due credit is given
6  * to the original author and the contributors.
7  */
8 #ifdef  __FreeBSD__
9 # include <osreldate.h>
10 #endif
11 #include <stdio.h>
12 #include <string.h>
13 #if !defined(__SVR4) && !defined(__svr4__)
14 # include <strings.h>
15 #endif
16 #include <sys/types.h>
17 #include <sys/time.h>
18 #include <sys/param.h>
19 #include <sys/file.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22 #include <fcntl.h>
23 #include <stddef.h>
24 #include <nlist.h>
25 #include <sys/socket.h>
26 #include <sys/ioctl.h>
27 #include <netinet/in.h>
28 #include <arpa/inet.h>
29 #include <netinet/in_systm.h>
30 #include <netinet/ip.h>
31 #include <net/if.h>
32 #if __FreeBSD_version >= 300000
33 # include <net/if_var.h>
34 #endif
35 #include <netdb.h>
36 #include <arpa/nameser.h>
37 #include <resolv.h>
38 #include <netinet/tcp.h>
39 #include "netinet/ip_compat.h"
40 #include "netinet/ip_fil.h"
41 #include "ipf.h"
42 #include "netinet/ip_proxy.h"
43 #include "netinet/ip_nat.h"
44 #include "netinet/ip_frag.h"
45 #include "netinet/ip_state.h"
46 #include "netinet/ip_auth.h"
47 #include "kmem.h"
48 #if defined(__NetBSD__) || (__OpenBSD__)
49 # include <paths.h>
50 #endif
51
52 #if !defined(lint)
53 static const char sccsid[] = "@(#)fils.c        1.21 4/20/96 (C) 1993-1996 Darren Reed";
54 static const char rcsid[] = "@(#)$Id: fils.c,v 2.2.2.4 1999/12/04 02:06:24 darrenr Exp $";
55 #endif
56
57 extern  char    *optarg;
58
59 #define PRINTF  (void)printf
60 #define FPRINTF (void)fprintf
61 #define F_IN    0
62 #define F_OUT   1
63 #define F_AC    2
64 static  char    *filters[4] = { "ipfilter(in)", "ipfilter(out)",
65                                 "ipacct(in)", "ipacct(out)" };
66
67 int     opts = 0;
68
69 extern  int     main __P((int, char *[]));
70 static  void    showstats __P((int, friostat_t *));
71 static  void    showfrstates __P((int, ipfrstat_t *));
72 static  void    showlist __P((friostat_t *));
73 static  void    showipstates __P((int, ips_stat_t *));
74 static  void    showauthstates __P((int, fr_authstat_t *));
75 static  void    showgroups __P((friostat_t *));
76 static  void    Usage __P((char *));
77 static  void    printlist __P((frentry_t *));
78 static  char    *get_ifname __P((void *));
79
80
81 static void Usage(name)
82 char *name;
83 {
84         fprintf(stderr, "Usage: %s [-aAfhIinosv] [-d <device>]\n", name);
85         exit(1);
86 }
87
88
89 int main(argc,argv)
90 int argc;
91 char *argv[];
92 {
93         fr_authstat_t   frauthst;
94         friostat_t fio;
95         ips_stat_t ipsst;
96         ipfrstat_t ifrst;
97         char    *name = NULL, *device = IPL_NAME;
98         int     c, fd;
99
100         if (openkmem() == -1)
101                 exit(-1);
102
103         (void)setuid(getuid());
104         (void)setgid(getgid());
105
106         while ((c = getopt(argc, argv, "aAfghIinosvd:")) != -1)
107         {
108                 switch (c)
109                 {
110                 case 'a' :
111                         opts |= OPT_ACCNT|OPT_SHOWLIST;
112                         break;
113                 case 'A' :
114                         opts |= OPT_AUTHSTATS;
115                         break;
116                 case 'd' :
117                         device = optarg;
118                         break;
119                 case 'f' :
120                         opts |= OPT_FRSTATES;
121                         break;
122                 case 'g' :
123                         opts |= OPT_GROUPS;
124                         break;
125                 case 'h' :
126                         opts |= OPT_HITS;
127                         break;
128                 case 'i' :
129                         opts |= OPT_INQUE|OPT_SHOWLIST;
130                         break;
131                 case 'I' :
132                         opts |= OPT_INACTIVE;
133                         break;
134                 case 'n' :
135                         opts |= OPT_SHOWLINENO;
136                         break;
137                 case 'o' :
138                         opts |= OPT_OUTQUE|OPT_SHOWLIST;
139                         break;
140                 case 's' :
141                         opts |= OPT_IPSTATES;
142                         break;
143                 case 'v' :
144                         opts |= OPT_VERBOSE;
145                         break;
146                 default :
147                         Usage(argv[0]);
148                         break;
149                 }
150         }
151
152         if ((fd = open(device, O_RDONLY)) < 0) {
153                 perror("open");
154                 exit(-1);
155         }
156
157         bzero((char *)&fio, sizeof(fio));
158         bzero((char *)&ipsst, sizeof(ipsst));
159         bzero((char *)&ifrst, sizeof(ifrst));
160
161         if (ioctl(fd, SIOCGETFS, &fio) == -1) {
162                 perror("ioctl(SIOCGETFS)");
163                 exit(-1);
164         }
165         if ((opts & OPT_IPSTATES)) {
166                 int     sfd = open(IPL_STATE, O_RDONLY);
167
168                 if (sfd == -1) {
169                         perror("open");
170                         exit(-1);
171                 }
172                 if ((ioctl(sfd, SIOCGIPST, &ipsst) == -1)) {
173                         perror("ioctl(SIOCGIPST)");
174                         exit(-1);
175                 }
176                 close(sfd);
177         }
178         if ((opts & OPT_FRSTATES) && (ioctl(fd, SIOCGFRST, &ifrst) == -1)) {
179                 perror("ioctl(SIOCGFRST)");
180                 exit(-1);
181         }
182
183         if (opts & OPT_VERBOSE)
184                 PRINTF("opts %#x name %s\n", opts, name ? name : "<>");
185
186         if ((opts & OPT_AUTHSTATS) &&
187             (ioctl(fd, SIOCATHST, &frauthst) == -1)) {
188                 perror("ioctl(SIOCATHST)");
189                 exit(-1);
190         }
191
192         if (opts & OPT_SHOWLIST) {
193                 showlist(&fio);
194                 if ((opts & OPT_OUTQUE) && (opts & OPT_INQUE)){
195                         opts &= ~OPT_OUTQUE;
196                         showlist(&fio);
197                 }
198         } else {
199                 if (opts & OPT_IPSTATES)
200                         showipstates(fd, &ipsst);
201                 else if (opts & OPT_FRSTATES)
202                         showfrstates(fd, &ifrst);
203                 else if (opts & OPT_AUTHSTATS)
204                         showauthstates(fd, &frauthst);
205                 else if (opts & OPT_GROUPS)
206                         showgroups(&fio);
207                 else
208                         showstats(fd, &fio);
209         }
210         return 0;
211 }
212
213
214 /*
215  * read the kernel stats for packets blocked and passed
216  */
217 static  void    showstats(fd, fp)
218 int     fd;
219 struct  friostat        *fp;
220 {
221         u_32_t  frf = 0;
222
223         if (ioctl(fd, SIOCGETFF, &frf) == -1)
224                 perror("ioctl(SIOCGETFF)");
225
226 #if SOLARIS
227         PRINTF("dropped packets:\tin %lu\tout %lu\n",
228                         fp->f_st[0].fr_drop, fp->f_st[1].fr_drop);
229         PRINTF("non-data packets:\tin %lu\tout %lu\n",
230                         fp->f_st[0].fr_notdata, fp->f_st[1].fr_notdata);
231         PRINTF("no-data packets:\tin %lu\tout %lu\n",
232                         fp->f_st[0].fr_nodata, fp->f_st[1].fr_nodata);
233         PRINTF("non-ip packets:\t\tin %lu\tout %lu\n",
234                         fp->f_st[0].fr_notip, fp->f_st[1].fr_notip);
235         PRINTF("   bad packets:\t\tin %lu\tout %lu\n",
236                         fp->f_st[0].fr_bad, fp->f_st[1].fr_bad);
237 #endif
238         PRINTF(" input packets:\t\tblocked %lu passed %lu nomatch %lu",
239                         fp->f_st[0].fr_block, fp->f_st[0].fr_pass,
240                         fp->f_st[0].fr_nom);
241         PRINTF(" counted %lu\n", fp->f_st[0].fr_acct);
242         PRINTF("output packets:\t\tblocked %lu passed %lu nomatch %lu",
243                         fp->f_st[1].fr_block, fp->f_st[1].fr_pass,
244                         fp->f_st[1].fr_nom);
245         PRINTF(" counted %lu\n", fp->f_st[0].fr_acct);
246         PRINTF(" input packets logged:\tblocked %lu passed %lu\n",
247                         fp->f_st[0].fr_bpkl, fp->f_st[0].fr_ppkl);
248         PRINTF("output packets logged:\tblocked %lu passed %lu\n",
249                         fp->f_st[1].fr_bpkl, fp->f_st[1].fr_ppkl);
250         PRINTF(" packets logged:\tinput %lu output %lu\n",
251                         fp->f_st[0].fr_pkl, fp->f_st[1].fr_pkl);
252         PRINTF(" log failures:\t\tinput %lu output %lu\n",
253                         fp->f_st[0].fr_skip, fp->f_st[1].fr_skip);
254         PRINTF("fragment state(in):\tkept %lu\tlost %lu\n",
255                         fp->f_st[0].fr_nfr, fp->f_st[0].fr_bnfr);
256         PRINTF("fragment state(out):\tkept %lu\tlost %lu\n",
257                         fp->f_st[1].fr_nfr, fp->f_st[1].fr_bnfr);
258         PRINTF("packet state(in):\tkept %lu\tlost %lu\n",
259                         fp->f_st[0].fr_ads, fp->f_st[0].fr_bads);
260         PRINTF("packet state(out):\tkept %lu\tlost %lu\n",
261                         fp->f_st[1].fr_ads, fp->f_st[1].fr_bads);
262         PRINTF("ICMP replies:\t%lu\tTCP RSTs sent:\t%lu\n",
263                         fp->f_st[0].fr_ret, fp->f_st[1].fr_ret);
264         PRINTF("Result cache hits(in):\t%lu\t(out):\t%lu\n",
265                         fp->f_st[0].fr_chit, fp->f_st[1].fr_chit);
266         PRINTF("IN Pullups succeeded:\t%lu\tfailed:\t%lu\n",
267                         fp->f_st[0].fr_pull[0], fp->f_st[0].fr_pull[1]);
268         PRINTF("OUT Pullups succeeded:\t%lu\tfailed:\t%lu\n",
269                         fp->f_st[1].fr_pull[0], fp->f_st[1].fr_pull[1]);
270         PRINTF("Fastroute successes:\t%lu\tfailures:\t%lu\n",
271                         fp->f_froute[0], fp->f_froute[1]);
272         PRINTF("TCP cksum fails(in):\t%lu\t(out):\t%lu\n",
273                         fp->f_st[0].fr_tcpbad, fp->f_st[1].fr_tcpbad);
274
275         PRINTF("Packet log flags set: (%#x)\n", frf);
276         if (frf & FF_LOGPASS)
277                 PRINTF("\tpackets passed through filter\n");
278         if (frf & FF_LOGBLOCK)
279                 PRINTF("\tpackets blocked by filter\n");
280         if (frf & FF_LOGNOMATCH)
281                 PRINTF("\tpackets not matched by filter\n");
282         if (!frf)
283                 PRINTF("\tnone\n");
284 }
285
286
287 static void printlist(fp)
288 frentry_t *fp;
289 {
290         struct  frentry fb;
291         int     n;
292
293         for (n = 1; fp; n++) {
294                 if (kmemcpy((char *)&fb, (u_long)fp, sizeof(fb)) == -1) {
295                         perror("kmemcpy");
296                         return;
297                 }
298                 fp = &fb;
299                 if (opts & OPT_OUTQUE)
300                         fp->fr_flags |= FR_OUTQUE;
301                 if (opts & (OPT_HITS|OPT_VERBOSE))
302 #ifdef  USE_QUAD_T
303                         PRINTF("%qd ", fp->fr_hits);
304 #else
305                         PRINTF("%ld ", fp->fr_hits);
306 #endif
307                 if (opts & (OPT_ACCNT|OPT_VERBOSE))
308 #ifdef  USE_QUAD_T
309                         PRINTF("%qd ", fp->fr_bytes);
310 #else
311                         PRINTF("%ld ", fp->fr_bytes);
312 #endif
313                 if (opts & OPT_SHOWLINENO)
314                         PRINTF("@%d ", n);
315                 printfr(fp);
316                 if (opts & OPT_VERBOSE)
317                         binprint(fp);
318                 if (fp->fr_grp)
319                         printlist(fp->fr_grp);
320                 fp = fp->fr_next;
321         }
322 }
323
324 /*
325  * print out filter rule list
326  */
327 static  void    showlist(fiop)
328 struct  friostat        *fiop;
329 {
330         struct  frentry *fp = NULL;
331         int     i, set;
332
333         set = fiop->f_active;
334         if (opts & OPT_INACTIVE)
335                 set = 1 - set;
336         if (opts & OPT_ACCNT) {
337                 i = F_AC;
338                 if (opts & OPT_OUTQUE) {
339                         fp = (struct frentry *)fiop->f_acctout[set];
340                         i++;
341                 } else if (opts & OPT_INQUE)
342                         fp = (struct frentry *)fiop->f_acctin[set];
343                 else {
344                         FPRINTF(stderr, "No -i or -o given with -a\n");
345                         return;
346                 }
347         } else if (opts & OPT_OUTQUE) {
348                 i = F_OUT;
349                 fp = (struct frentry *)fiop->f_fout[set];
350         } else if (opts & OPT_INQUE) {
351                 i = F_IN;
352                 fp = (struct frentry *)fiop->f_fin[set];
353         } else
354                 return;
355         if (opts & OPT_VERBOSE)
356                 FPRINTF(stderr, "showlist:opts %#x i %d\n", opts, i);
357
358         if (opts & OPT_VERBOSE)
359                 PRINTF("fp %p set %d\n", fp, set);
360         if (!fp) {
361                 FPRINTF(stderr, "empty list for %s%s\n",
362                         (opts & OPT_INACTIVE) ? "inactive " : "", filters[i]);
363                 return;
364         }
365         printlist(fp);
366 }
367
368
369 static void showipstates(fd, ipsp)
370 int fd;
371 ips_stat_t *ipsp;
372 {
373         ipstate_t *istab[IPSTATE_SIZE], ips;
374         int i;
375
376         PRINTF("IP states added:\n\t%lu TCP\n\t%lu UDP\n\t%lu ICMP\n",
377                 ipsp->iss_tcp, ipsp->iss_udp, ipsp->iss_icmp);
378         PRINTF("\t%lu hits\n\t%lu misses\n", ipsp->iss_hits, ipsp->iss_miss);
379         PRINTF("\t%lu maximum\n\t%lu no memory\n\tbuckets in use\t%lu\n",
380                 ipsp->iss_max, ipsp->iss_nomem, ipsp->iss_inuse);
381         PRINTF("\t%lu active\n\t%lu expired\n\t%lu closed\n",
382                 ipsp->iss_active, ipsp->iss_expire, ipsp->iss_fin);
383         if (kmemcpy((char *)istab, (u_long)ipsp->iss_table, sizeof(istab)))
384                 return;
385         for (i = 0; i < IPSTATE_SIZE; i++) {
386                 while (istab[i]) {
387                         if (kmemcpy((char *)&ips, (u_long)istab[i],
388                                     sizeof(ips)) == -1)
389                                 break;
390                         PRINTF("%s -> ", inet_ntoa(ips.is_src));
391                         PRINTF("%s ttl %ld pass %#x pr %d state %d/%d\n",
392                                 inet_ntoa(ips.is_dst), ips.is_age,
393                                 ips.is_pass, ips.is_p, ips.is_state[0],
394                                 ips.is_state[1]);
395 #ifdef  USE_QUAD_T
396                         PRINTF("\tpkts %qd bytes %qd",
397                                 ips.is_pkts, ips.is_bytes);
398 #else
399                         PRINTF("\tpkts %ld bytes %ld",
400                                 ips.is_pkts, ips.is_bytes);
401 #endif
402                         if (ips.is_p == IPPROTO_TCP)
403 #if defined(NetBSD) && (NetBSD >= 199905) && (NetBSD < 1991011) || \
404     (__FreeBSD_version >= 220000) || defined(__OpenBSD__)
405                                 PRINTF("\t%hu -> %hu %x:%x %hu:%hu",
406                                         ntohs(ips.is_sport),
407                                         ntohs(ips.is_dport),
408                                         ips.is_send, ips.is_dend,
409                                         ips.is_maxswin, ips.is_maxdwin);
410 #else
411                                 PRINTF("\t%hu -> %hu %lx:%lx %hu:%hu",
412                                         ntohs(ips.is_sport),
413                                         ntohs(ips.is_dport),
414                                         ips.is_send, ips.is_dend,
415                                         ips.is_maxswin, ips.is_maxdwin);
416 #endif
417                         else if (ips.is_p == IPPROTO_UDP)
418                                 PRINTF(" %hu -> %hu", ntohs(ips.is_sport),
419                                         ntohs(ips.is_dport));
420                         else if (ips.is_p == IPPROTO_ICMP)
421                                 PRINTF(" %hu %hu %d", ips.is_icmp.ics_id,
422                                         ips.is_icmp.ics_seq,
423                                         ips.is_icmp.ics_type);
424
425                         PRINTF("\n\t");
426
427                         if (ips.is_pass & FR_PASS) {
428                                 PRINTF("pass");
429                         } else if (ips.is_pass & FR_BLOCK) {
430                                 PRINTF("block");
431                                 switch (ips.is_pass & FR_RETMASK)
432                                 {
433                                 case FR_RETICMP :
434                                         PRINTF(" return-icmp");
435                                         break;
436                                 case FR_FAKEICMP :
437                                         PRINTF(" return-icmp-as-dest");
438                                         break;
439                                 case FR_RETRST :
440                                         PRINTF(" return-rst");
441                                         break;
442                                 default :
443                                         break;
444                                 }
445                         } else if ((ips.is_pass & FR_LOGMASK) == FR_LOG) {
446                                         PRINTF("log");
447                                 if (ips.is_pass & FR_LOGBODY)
448                                         PRINTF(" body");
449                                 if (ips.is_pass & FR_LOGFIRST)
450                                         PRINTF(" first");
451                         } else if (ips.is_pass & FR_ACCOUNT)
452                                 PRINTF("count");
453
454                         if (ips.is_pass & FR_OUTQUE)
455                                 PRINTF(" out");
456                         else
457                                 PRINTF(" in");
458
459                         if ((ips.is_pass & FR_LOG) != 0) {
460                                 PRINTF(" log");
461                                 if (ips.is_pass & FR_LOGBODY)
462                                         PRINTF(" body");
463                                 if (ips.is_pass & FR_LOGFIRST)
464                                         PRINTF(" first");
465                                 if (ips.is_pass & FR_LOGORBLOCK)
466                                         PRINTF(" or-block");
467                         }
468                         if (ips.is_pass & FR_QUICK)
469                                 PRINTF(" quick");
470                         if (ips.is_pass & FR_KEEPFRAG)
471                                 PRINTF(" keep frags");
472                         /* a given; no? */
473                         if (ips.is_pass & FR_KEEPSTATE)
474                                 PRINTF(" keep state");
475                         PRINTF("\n");
476
477                         PRINTF("\tpkt_flags & %x(%x) = %x,\t",
478                                 ips.is_flags & 0xf, ips.is_flags,
479                                 ips.is_flags >> 4);
480                         PRINTF("\tpkt_options & %x = %x\n", ips.is_optmsk,
481                                 ips.is_opt);
482                         PRINTF("\tpkt_security & %x = %x, pkt_auth & %x = %x\n",
483                                 ips.is_secmsk, ips.is_sec, ips.is_authmsk,
484                                 ips.is_auth);
485                         istab[i] = ips.is_next;
486                         PRINTF("interfaces: in %s[%p] ",
487                                get_ifname(ips.is_ifpin), ips.is_ifpin);
488                         PRINTF("out %s[%p]\n",
489                                get_ifname(ips.is_ifpout), ips.is_ifpout);
490                 }
491         }
492 }
493
494
495 static void showfrstates(fd, ifsp)
496 int fd;
497 ipfrstat_t *ifsp;
498 {
499         struct ipfr *ipfrtab[IPFT_SIZE], ifr;
500         frentry_t fr;
501         int i;
502
503         PRINTF("IP fragment states:\n\t%lu new\n\t%lu expired\n\t%lu hits\n",
504                 ifsp->ifs_new, ifsp->ifs_expire, ifsp->ifs_hits);
505         PRINTF("\t%lu no memory\n\t%lu already exist\n",
506                 ifsp->ifs_nomem, ifsp->ifs_exists);
507         PRINTF("\t%lu inuse\n", ifsp->ifs_inuse);
508         if (kmemcpy((char *)ipfrtab, (u_long)ifsp->ifs_table, sizeof(ipfrtab)))
509                 return;
510         for (i = 0; i < IPFT_SIZE; i++)
511                 while (ipfrtab[i]) {
512                         if (kmemcpy((char *)&ifr, (u_long)ipfrtab[i],
513                                     sizeof(ifr)) == -1)
514                                 break;
515                         PRINTF("%s -> ", inet_ntoa(ifr.ipfr_src));
516                         if (kmemcpy((char *)&fr, (u_long)ifr.ipfr_rule,
517                                     sizeof(fr)) == -1)
518                                 break;
519                         PRINTF("%s %d %d %d %#02x = %#x\n",
520                                 inet_ntoa(ifr.ipfr_dst), ifr.ipfr_id,
521                                 ifr.ipfr_ttl, ifr.ipfr_p, ifr.ipfr_tos,
522                                 fr.fr_flags);
523                         ipfrtab[i] = ifr.ipfr_next;
524                 }
525 }
526
527
528 static void showauthstates(fd, asp)
529 int fd;
530 fr_authstat_t *asp;
531 {
532         frauthent_t *frap, fra;
533
534 #ifdef  USE_QUAD_T
535         printf("Authorisation hits: %qd\tmisses %qd\n", asp->fas_hits,
536                 asp->fas_miss);
537 #else
538         printf("Authorisation hits: %ld\tmisses %ld\n", asp->fas_hits,
539                 asp->fas_miss);
540 #endif
541         printf("nospace %ld\nadded %ld\nsendfail %ld\nsendok %ld\n",
542                 asp->fas_nospace, asp->fas_added, asp->fas_sendfail,
543                 asp->fas_sendok);
544         printf("queok %ld\nquefail %ld\nexpire %ld\n",
545                 asp->fas_queok, asp->fas_quefail, asp->fas_expire);
546
547         frap = asp->fas_faelist;
548         while (frap) {
549                 if (kmemcpy((char *)&fra, (u_long)frap, sizeof(fra)) == -1)
550                         break;
551
552                 printf("age %ld\t", fra.fae_age);
553                 printfr(&fra.fae_fr);
554                 frap = fra.fae_next;
555         }
556 }
557
558
559 static char *get_ifname(ptr)
560 void *ptr;
561 {
562 #if SOLARIS
563         char *ifname;
564         ill_t ill;
565
566         if (ptr == (void *)-1)
567                 return "!";
568         if (ptr == NULL)
569                 return "-";
570
571         if (kmemcpy((char *)&ill, (u_long)ptr, sizeof(ill)) == -1)
572                 return "X";
573         ifname = malloc(ill.ill_name_length + 1);
574         if (kmemcpy(ifname, (u_long)ill.ill_name,
575                     ill.ill_name_length) == -1)
576                 return "X";
577         return ifname;
578 #else
579 # if defined(NetBSD) && (NetBSD >= 199905) && (NetBSD < 1991011) || \
580     defined(__OpenBSD__)
581 #else
582         char buf[32];
583         int len;
584 # endif
585         struct ifnet netif;
586
587         if (ptr == (void *)-1)
588                 return "!";
589         if (ptr == NULL)
590                 return "-";
591
592         if (kmemcpy((char *)&netif, (u_long)ptr, sizeof(netif)) == -1)
593                 return "X";
594 # if defined(NetBSD) && (NetBSD >= 199905) && (NetBSD < 1991011) || \
595     defined(__OpenBSD__)
596         return strdup(netif.if_xname);
597 # else
598         if (kstrncpy(buf, (u_long)netif.if_name, sizeof(buf)) == -1)
599                 return "X";
600         if (netif.if_unit < 10)
601                 len = 2;
602         else if (netif.if_unit < 1000)
603                 len = 3;
604         else if (netif.if_unit < 10000)
605                 len = 4;
606         else
607                 len = 5;
608         buf[sizeof(buf) - len] = '\0';
609         sprintf(buf + strlen(buf), "%d", netif.if_unit % 10000);
610         return strdup(buf);
611 # endif
612 #endif
613 }
614
615
616 static void showgroups(fiop)
617 struct friostat *fiop;
618 {
619         static char *gnames[3] = { "Filter", "Accounting", "Authentication" };
620         frgroup_t *fp, grp;
621         int on, off, i;
622
623         on = fiop->f_active;
624         off = 1 - on;
625
626         for (i = 0; i < 3; i++) {
627                 printf("%s groups (active):\n", gnames[i]);
628                 for (fp = fiop->f_groups[i][on]; fp; fp = grp.fg_next)
629                         if (kmemcpy((char *)&grp, (u_long)fp, sizeof(grp)))
630                                 break;
631                         else
632                                 printf("%hu\n", grp.fg_num);
633                 printf("%s groups (inactive):\n", gnames[i]);
634                 for (fp = fiop->f_groups[i][off]; fp; fp = grp.fg_next)
635                         if (kmemcpy((char *)&grp, (u_long)fp, sizeof(grp)))
636                                 break;
637                         else
638                                 printf("%hu\n", grp.fg_num);
639         }
640 }