Permalink
Browse files

added more comprehensive comment for the code which avoid

multiple binding to 0.0.0.0 in in_pcblookup_local().
  • Loading branch information...
1 parent a7248c5 commit 97324057f99b253e45139e50ba5c8b2e0f05dc13 keiichi committed Feb 3, 2006
Showing with 40 additions and 14 deletions.
  1. +20 −7 freebsd4/sys/netinet/in_pcb.c
  2. +20 −7 freebsd5/sys/netinet/in_pcb.c
@@ -870,12 +870,7 @@ in_rtchange(inp, errno)
/*
* Lookup a PCB based on the local address and port.
*/
-/*
- * we never select the wildcard pcb which has INP_IPV6 flag if we have
- * INP_IPV4 only wildcard pcb. INP_LOOKUP_MAPPED_PCB_COST must be
- * greater than the max value of matchwild (currently 3).
- */
-#define INP_LOOKUP_MAPPED_PCB_COST 4
+#define INP_LOOKUP_MAPPED_PCB_COST 3
struct inpcb *
in_pcblookup_local(pcbinfo, laddr, lport_arg, wild_okay)
struct inpcbinfo *pcbinfo;
@@ -884,7 +879,12 @@ in_pcblookup_local(pcbinfo, laddr, lport_arg, wild_okay)
int wild_okay;
{
register struct inpcb *inp;
- int matchwild = 3 + INP_LOOKUP_MAPPED_PCB_COST, wildcard;
+#ifdef INET6
+ int matchwild = 3 + INP_LOOKUP_MAPPED_PCB_COST;
+#else
+ int matchwild = 3;
+#endif
+ int wildcard;
u_short lport = lport_arg;
if (!wild_okay) {
@@ -938,6 +938,19 @@ in_pcblookup_local(pcbinfo, laddr, lport_arg, wild_okay)
#ifdef INET6
if ((inp->inp_vflag & INP_IPV4) == 0)
continue;
+ /*
+ * We never select the PCB that has
+ * INP_IPV6 flag and is bound to :: if
+ * we have another PCB which is bound
+ * to 0.0.0.0. If a PCB has the
+ * INP_IPV6 flag, then we set its cost
+ * higher than IPv4 only PCBs.
+ *
+ * Note that the case only happens
+ * when a socket is bound to ::, under
+ * the condition that the use of the
+ * mapped address is allowed.
+ */
if ((inp->inp_vflag & INP_IPV6) != 0)
wildcard += INP_LOOKUP_MAPPED_PCB_COST;
#endif
@@ -963,12 +963,7 @@ in_pcbpurgeif0(pcbinfo, ifp)
/*
* Lookup a PCB based on the local address and port.
*/
-/*
- * we never select the wildcard pcb which has INP_IPV6 flag if we have
- * INP_IPV4 only wildcard pcb. INP_LOOKUP_MAPPED_PCB_COST must be
- * greater than the max value of matchwild (currently 3).
- */
-#define INP_LOOKUP_MAPPED_PCB_COST 4
+#define INP_LOOKUP_MAPPED_PCB_COST 3
struct inpcb *
in_pcblookup_local(pcbinfo, laddr, lport_arg, wild_okay)
struct inpcbinfo *pcbinfo;
@@ -977,7 +972,12 @@ in_pcblookup_local(pcbinfo, laddr, lport_arg, wild_okay)
int wild_okay;
{
register struct inpcb *inp;
- int matchwild = 3 + INP_LOOKUP_MAPPED_PCB_COST, wildcard;
+#ifdef INET6
+ int matchwild = 3 + INP_LOOKUP_MAPPED_PCB_COST;
+#else
+ int matchwild = 3;
+#endif
+ int wildcard;
u_short lport = lport_arg;
INP_INFO_WLOCK_ASSERT(pcbinfo);
@@ -1034,6 +1034,19 @@ in_pcblookup_local(pcbinfo, laddr, lport_arg, wild_okay)
#ifdef INET6
if ((inp->inp_vflag & INP_IPV4) == 0)
continue;
+ /*
+ * We never select the PCB that has
+ * INP_IPV6 flag and is bound to :: if
+ * we have another PCB which is bound
+ * to 0.0.0.0. If a PCB has the
+ * INP_IPV6 flag, then we set its cost
+ * higher than IPv4 only PCBs.
+ *
+ * Note that the case only happens
+ * when a socket is bound to ::, under
+ * the condition that the use of the
+ * mapped address is allowed.
+ */
if ((inp->inp_vflag & INP_IPV6) != 0)
wildcard += INP_LOOKUP_MAPPED_PCB_COST;
#endif

0 comments on commit 9732405

Please sign in to comment.