1 /* $FreeBSD: stable/12/sbin/ipf/libipf/printpool.c 371569 2022-02-07 13:57:53Z cy $ */
2
3 /*
4 * Copyright (C) 2012 by Darren Reed.
5 *
6 * See the IPFILTER.LICENCE file for details on licencing.
7 */
8
9 #include "ipf.h"
10
11
12 ip_pool_t *
printpool(ip_pool_t * pp,copyfunc_t copyfunc,char * name,int opts,wordtab_t * fields)13 printpool(ip_pool_t *pp, copyfunc_t copyfunc, char *name, int opts,
14 wordtab_t *fields)
15 {
16 ip_pool_node_t *ipnp, *ipnpn, ipn, **pnext;
17 ip_pool_t ipp;
18
19 if ((*copyfunc)(pp, &ipp, sizeof(ipp)))
20 return (NULL);
21
22 if ((name != NULL) && strncmp(name, ipp.ipo_name, FR_GROUPLEN))
23 return (ipp.ipo_next);
24
25 printpooldata(&ipp, opts);
26
27 if ((ipp.ipo_flags & IPOOL_DELETE) != 0)
28 PRINTF("# ");
29 if ((opts & OPT_DEBUG) == 0)
30 PRINTF("\t{");
31
32 ipnpn = ipp.ipo_list;
33 ipp.ipo_list = NULL;
34 pnext = &ipp.ipo_list;
35 while (ipnpn != NULL) {
36 ipnp = (ip_pool_node_t *)malloc(sizeof(*ipnp));
37 (*copyfunc)(ipnpn, ipnp, sizeof(ipn));
38 ipnpn = ipnp->ipn_next;
39 *pnext = ipnp;
40 pnext = &ipnp->ipn_next;
41 ipnp->ipn_next = NULL;
42 }
43
44 if (ipp.ipo_list == NULL) {
45 putchar(';');
46 } else {
47 for (ipnp = ipp.ipo_list; ipnp != NULL; ipnp = ipnpn) {
48 ipnpn = printpoolnode(ipnp, opts, fields);
49 free(ipnp);
50
51 if ((opts & OPT_DEBUG) == 0) {
52 putchar(';');
53 }
54 }
55 }
56
57 if ((opts & OPT_DEBUG) == 0)
58 PRINTF(" };\n");
59
60 return (ipp.ipo_next);
61 }
62