- pf_insert_src_node(): global argument (arg6) is useless, function
authorsashan <sashan@openbsd.org>
Tue, 13 Oct 2015 19:32:31 +0000 (19:32 +0000)
committersashan <sashan@openbsd.org>
Tue, 13 Oct 2015 19:32:31 +0000 (19:32 +0000)
  always gets pointer to rule.

- pf_remove_src_node(): function should always remove matching src node,
  regardless the sn->rule.ptr being NULL or valid rule

- sn->rule.ptr is never NULL, spotted by mpi and Richard Procter _von_ gmail.com

OK mpi@, OK mikeb@

sys/net/pf.c
sys/net/pf_ioctl.c
sys/net/pf_lb.c
sys/net/pfvar.h

index bc5cc6a..174a4cc 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: pf.c,v 1.946 2015/10/08 11:36:51 dlg Exp $ */
+/*     $OpenBSD: pf.c,v 1.947 2015/10/13 19:32:31 sashan Exp $ */
 
 /*
  * Copyright (c) 2001 Daniel Hartmeier
@@ -501,7 +501,7 @@ pf_src_connlimit(struct pf_state **state)
 int
 pf_insert_src_node(struct pf_src_node **sn, struct pf_rule *rule,
     enum pf_sn_types type, sa_family_t af, struct pf_addr *src,
-    struct pf_addr *raddr, int global)
+    struct pf_addr *raddr)
 {
        struct pf_src_node      k;
 
@@ -509,10 +509,7 @@ pf_insert_src_node(struct pf_src_node **sn, struct pf_rule *rule,
                k.af = af;
                k.type = type;
                PF_ACPY(&k.addr, src, af);
-               if (global)
-                       k.rule.ptr = NULL;
-               else
-                       k.rule.ptr = rule;
+               k.rule.ptr = rule;
                pf_status.scounters[SCNT_SRC_NODE_SEARCH]++;
                *sn = RB_FIND(pf_src_tree, &tree_src_tracking, &k);
        }
@@ -531,10 +528,7 @@ pf_insert_src_node(struct pf_src_node **sn, struct pf_rule *rule,
 
                (*sn)->type = type;
                (*sn)->af = af;
-               if (global)
-                       (*sn)->rule.ptr = NULL;
-               else
-                       (*sn)->rule.ptr = rule;
+               (*sn)->rule.ptr = rule;
                PF_ACPY(&(*sn)->addr, src, af);
                if (raddr)
                        PF_ACPY(&(*sn)->raddr, raddr, af);
@@ -550,8 +544,7 @@ pf_insert_src_node(struct pf_src_node **sn, struct pf_rule *rule,
                        return (-1);
                }
                (*sn)->creation = time_uptime;
-               if ((*sn)->rule.ptr != NULL)
-                       (*sn)->rule.ptr->src_nodes++;
+               (*sn)->rule.ptr->src_nodes++;
                pf_status.scounters[SCNT_SRC_NODE_INSERT]++;
                pf_status.src_nodes++;
        } else {
@@ -570,16 +563,14 @@ pf_remove_src_node(struct pf_src_node *sn)
        if (sn->states > 0 || sn->expire > time_uptime)
                return;
 
-       if (sn->rule.ptr != NULL) {
-               sn->rule.ptr->src_nodes--;
-               if (sn->rule.ptr->states_cur == 0 &&
-                   sn->rule.ptr->src_nodes == 0)
-                       pf_rm_rule(NULL, sn->rule.ptr);
-               RB_REMOVE(pf_src_tree, &tree_src_tracking, sn);
-               pf_status.scounters[SCNT_SRC_NODE_REMOVALS]++;
-               pf_status.src_nodes--;
-               pool_put(&pf_src_tree_pl, sn);
-       }
+       sn->rule.ptr->src_nodes--;
+       if (sn->rule.ptr->states_cur == 0 &&
+           sn->rule.ptr->src_nodes == 0)
+               pf_rm_rule(NULL, sn->rule.ptr);
+       RB_REMOVE(pf_src_tree, &tree_src_tracking, sn);
+       pf_status.scounters[SCNT_SRC_NODE_REMOVALS]++;
+       pf_status.src_nodes--;
+       pool_put(&pf_src_tree_pl, sn);
 }
 
 struct pf_src_node *
@@ -3381,7 +3372,7 @@ pf_test_rule(struct pf_pdesc *pd, struct pf_rule **rm, struct pf_state **sm,
 
                if (r->rule_flag & PFRULE_SRCTRACK &&
                    pf_insert_src_node(&sns[PF_SN_NONE], r, PF_SN_NONE, pd->af,
-                   pd->src, NULL, 0) != 0) {
+                   pd->src, NULL) != 0) {
                        REASON_SET(&reason, PFRES_SRCLIMIT);
                        goto cleanup;
                }
index 6939a43..0709b8f 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: pf_ioctl.c,v 1.290 2015/09/04 21:40:25 kettenis Exp $ */
+/*     $OpenBSD: pf_ioctl.c,v 1.291 2015/10/13 19:32:31 sashan Exp $ */
 
 /*
  * Copyright (c) 2001 Daniel Hartmeier
@@ -2175,8 +2175,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p)
                        bzero(&pstore->entry, sizeof(pstore->entry));
                        pstore->rule.ptr = NULL;
                        pstore->kif = NULL;
-                       if (n->rule.ptr != NULL)
-                               pstore->rule.nr = n->rule.ptr->nr;
+                       pstore->rule.nr = n->rule.ptr->nr;
                        pstore->creation = secs - pstore->creation;
                        if (pstore->expire > secs)
                                pstore->expire -= secs;
index 6a8ea98..72d5c27 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: pf_lb.c,v 1.49 2015/08/03 13:33:12 jsg Exp $ */
+/*     $OpenBSD: pf_lb.c,v 1.50 2015/10/13 19:32:31 sashan Exp $ */
 
 /*
  * Copyright (c) 2001 Daniel Hartmeier
@@ -621,8 +621,7 @@ pf_map_addr(sa_family_t af, struct pf_rule *r, struct pf_addr *saddr,
                        pf_remove_src_node(sns[type]);
                        sns[type] = NULL;
                }
-               if (pf_insert_src_node(&sns[type], r, type, af, saddr, naddr,
-                   0))
+               if (pf_insert_src_node(&sns[type], r, type, af, saddr, naddr))
                        return (1);
        }
 
index b540c73..cdb2f7f 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: pfvar.h,v 1.420 2015/08/19 21:22:41 sashan Exp $ */
+/*     $OpenBSD: pfvar.h,v 1.421 2015/10/13 19:32:32 sashan Exp $ */
 
 /*
  * Copyright (c) 2001 Daniel Hartmeier
@@ -1681,7 +1681,7 @@ extern int                         pf_state_insert(struct pfi_kif *,
 int                             pf_insert_src_node(struct pf_src_node **,
                                    struct pf_rule *, enum pf_sn_types,
                                    sa_family_t, struct pf_addr *,
-                                   struct pf_addr *, int);
+                                   struct pf_addr *);
 void                            pf_remove_src_node(struct pf_src_node *);
 struct pf_src_node             *pf_get_src_node(struct pf_state *,
                                    enum pf_sn_types);