summaryrefslogtreecommitdiffstats
path: root/main/ipsec-tools/03-fix-sport-selection.patch
blob: 56cd999b390f6ad8b2dfbca1b24ff5ad852e1b5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
--- a/src/racoon/grabmyaddr.c	14 Mar 2011 17:18:12 -0000	1.28
+++ b/src/racoon/grabmyaddr.c	5 Feb 2013 11:32:59 -0000
@@ -274,13 +274,24 @@
 	struct sockaddr *addr;
 {
 	struct myaddr *my;
+	int port = 0, wport;
 
 	LIST_FOREACH(my, &opened, chain) {
-		if (cmpsaddr((struct sockaddr *) &my->addr, addr) <= CMPSADDR_WILDPORT_MATCH)
+		switch (cmpsaddr((struct sockaddr *) &my->addr, addr)) {
+		case CMPSADDR_MATCH:
 			return extract_port((struct sockaddr *) &my->addr);
+		case CMPSADDR_WILDPORT_MATCH:
+			wport = extract_port((struct sockaddr *) &my->addr);
+			if (port == 0 || wport < port)
+				port = wport;
+			break;
+		}
 	}
+	
+	if (port == 0)
+		port = PORT_ISAKMP;
 
-	return PORT_ISAKMP;
+	return port;
 }
 
 void