summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Gross <vgross@cvs.openbsd.org>2015-09-22 09:34:40 +0000
committerVincent Gross <vgross@cvs.openbsd.org>2015-09-22 09:34:40 +0000
commitdd7de21b596a24acf977a7b0e96adfe3d1797c9f (patch)
treed144ad797607d16828672dd2fe46700867e8b1ab
parente71f9afe442bf8b7872018b94bbfc38c7e3ef07e (diff)
Remove inpt_lastport from struct inpcbtable, use local variables
in in_pcbbind() and in6_pcbsetport() ok claudio@, with input from David Hill
-rw-r--r--sys/netinet/in_pcb.c29
-rw-r--r--sys/netinet/in_pcb.h3
-rw-r--r--sys/netinet6/in6_pcb.c28
3 files changed, 29 insertions, 31 deletions
diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c
index 1a1650063fb..fe26a5a6840 100644
--- a/sys/netinet/in_pcb.c
+++ b/sys/netinet/in_pcb.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: in_pcb.c,v 1.179 2015/09/11 15:29:47 deraadt Exp $ */
+/* $OpenBSD: in_pcb.c,v 1.180 2015/09/22 09:34:38 vgross Exp $ */
/* $NetBSD: in_pcb.c,v 1.25 1996/02/13 23:41:53 christos Exp $ */
/*
@@ -199,7 +199,6 @@ in_pcbinit(struct inpcbtable *table, int hashsize)
&table->inpt_lhash);
if (table->inpt_lhashtbl == NULL)
panic("in_pcbinit: hashinit failed for lport");
- table->inpt_lastport = 0;
table->inpt_count = 0;
arc4random_buf(&table->inpt_key, sizeof(table->inpt_key));
}
@@ -281,8 +280,8 @@ in_pcbbind(struct inpcb *inp, struct mbuf *nam, struct proc *p)
{
struct socket *so = inp->inp_socket;
struct inpcbtable *table = inp->inp_table;
- u_int16_t *lastport = &inp->inp_table->inpt_lastport;
struct sockaddr_in *sin;
+ u_int16_t lastport = 0;
u_int16_t lport = 0;
int wild = 0, reuseport = (so->so_options & SO_REUSEPORT);
int error;
@@ -391,16 +390,16 @@ in_pcbbind(struct inpcb *inp, struct mbuf *nam, struct proc *p)
*/
count = first - last;
if (count)
- *lastport = first - arc4random_uniform(count);
+ lastport = first - arc4random_uniform(count);
do {
if (count-- < 0) /* completely used? */
return (EADDRNOTAVAIL);
- --*lastport;
- if (*lastport > first || *lastport < last)
- *lastport = first;
- lport = htons(*lastport);
- } while (in_baddynamic(*lastport, so->so_proto->pr_protocol) ||
+ --lastport;
+ if (lastport > first || lastport < last)
+ lastport = first;
+ lport = htons(lastport);
+ } while (in_baddynamic(lastport, so->so_proto->pr_protocol) ||
in_pcblookup(table, &zeroin_addr, 0,
&inp->inp_laddr, lport, wild, inp->inp_rtableid));
} else {
@@ -409,16 +408,16 @@ in_pcbbind(struct inpcb *inp, struct mbuf *nam, struct proc *p)
*/
count = last - first;
if (count)
- *lastport = first + arc4random_uniform(count);
+ lastport = first + arc4random_uniform(count);
do {
if (count-- < 0) /* completely used? */
return (EADDRNOTAVAIL);
- ++*lastport;
- if (*lastport < first || *lastport > last)
- *lastport = first;
- lport = htons(*lastport);
- } while (in_baddynamic(*lastport, so->so_proto->pr_protocol) ||
+ ++lastport;
+ if (lastport < first || lastport > last)
+ lastport = first;
+ lport = htons(lastport);
+ } while (in_baddynamic(lastport, so->so_proto->pr_protocol) ||
in_pcblookup(table, &zeroin_addr, 0,
&inp->inp_laddr, lport, wild, inp->inp_rtableid));
}
diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h
index 42c3b694771..8d351cf6802 100644
--- a/sys/netinet/in_pcb.h
+++ b/sys/netinet/in_pcb.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: in_pcb.h,v 1.89 2015/04/16 19:24:13 markus Exp $ */
+/* $OpenBSD: in_pcb.h,v 1.90 2015/09/22 09:34:39 vgross Exp $ */
/* $NetBSD: in_pcb.h,v 1.14 1996/02/13 23:42:00 christos Exp $ */
/*
@@ -152,7 +152,6 @@ struct inpcbtable {
struct inpcbhead *inpt_hashtbl, *inpt_lhashtbl;
SIPHASH_KEY inpt_key;
u_long inpt_hash, inpt_lhash;
- u_int16_t inpt_lastport;
int inpt_count;
};
diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c
index 77d252a575f..866fc9cf800 100644
--- a/sys/netinet6/in6_pcb.c
+++ b/sys/netinet6/in6_pcb.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: in6_pcb.c,v 1.74 2015/09/11 15:29:47 deraadt Exp $ */
+/* $OpenBSD: in6_pcb.c,v 1.75 2015/09/22 09:34:39 vgross Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -294,7 +294,7 @@ in6_pcbsetport(struct in6_addr *laddr, struct inpcb *inp, struct proc *p)
struct socket *so = inp->inp_socket;
struct inpcbtable *table = inp->inp_table;
u_int16_t first, last;
- u_int16_t *lastport = &inp->inp_table->inpt_lastport;
+ u_int16_t lastport = 0;
u_int16_t lport = 0;
int count;
int wild = INPLOOKUP_IPV6;
@@ -334,16 +334,16 @@ in6_pcbsetport(struct in6_addr *laddr, struct inpcb *inp, struct proc *p)
*/
count = first - last;
if (count)
- *lastport = first - arc4random_uniform(count);
+ lastport = first - arc4random_uniform(count);
do {
if (count-- < 0) /* completely used? */
return (EADDRNOTAVAIL);
- --*lastport;
- if (*lastport > first || *lastport < last)
- *lastport = first;
- lport = htons(*lastport);
- } while (in_baddynamic(*lastport, so->so_proto->pr_protocol) ||
+ --lastport;
+ if (lastport > first || lastport < last)
+ lastport = first;
+ lport = htons(lastport);
+ } while (in_baddynamic(lastport, so->so_proto->pr_protocol) ||
in_pcblookup(table, &zeroin6_addr, 0,
&inp->inp_laddr6, lport, wild, inp->inp_rtableid));
} else {
@@ -352,16 +352,16 @@ in6_pcbsetport(struct in6_addr *laddr, struct inpcb *inp, struct proc *p)
*/
count = last - first;
if (count)
- *lastport = first + arc4random_uniform(count);
+ lastport = first + arc4random_uniform(count);
do {
if (count-- < 0) /* completely used? */
return (EADDRNOTAVAIL);
- ++*lastport;
- if (*lastport < first || *lastport > last)
- *lastport = first;
- lport = htons(*lastport);
- } while (in_baddynamic(*lastport, so->so_proto->pr_protocol) ||
+ ++lastport;
+ if (lastport < first || lastport > last)
+ lastport = first;
+ lport = htons(lastport);
+ } while (in_baddynamic(lastport, so->so_proto->pr_protocol) ||
in_pcblookup(table, &zeroin6_addr, 0,
&inp->inp_laddr6, lport, wild, inp->inp_rtableid));
}