aboutsummaryrefslogtreecommitdiff
path: root/slirp/socket.c
diff options
context:
space:
mode:
authorGuillaume Subiron <maethor@subiron.org>2015-12-19 22:25:00 +0100
committerJason Wang <jasowang@redhat.com>2016-02-04 13:22:06 +0800
commita5fd24aa6d0f26aeb9f15b24daa2d68427631c40 (patch)
tree83dcbdd530a4e23f3408bbc8ba60b54d78fa48dd /slirp/socket.c
parent5379229a2708df3a1506113315214c3ce5325859 (diff)
slirp: Factorizing and cleaning solookup()
solookup() was only compatible with TCP. Having the socket list in argument, it is now compatible with UDP too. Some optimization code is factorized inside the function (the function look at the last returned result before browsing the complete socket list). This prepares for IPv6 support. Signed-off-by: Guillaume Subiron <maethor@subiron.org> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org> Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Jason Wang <jasowang@redhat.com>
Diffstat (limited to 'slirp/socket.c')
-rw-r--r--slirp/socket.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/slirp/socket.c b/slirp/socket.c
index d1034fb536..8f73e906e2 100644
--- a/slirp/socket.c
+++ b/slirp/socket.c
@@ -16,23 +16,34 @@ static void sofcantrcvmore(struct socket *so);
static void sofcantsendmore(struct socket *so);
struct socket *
-solookup(struct socket *head, struct in_addr laddr, u_int lport,
+solookup(struct socket **last, struct socket *head,
+ struct in_addr laddr, u_int lport,
struct in_addr faddr, u_int fport)
{
- struct socket *so;
-
- for (so = head->so_next; so != head; so = so->so_next) {
- if (so->so_lport == lport &&
- so->so_laddr.s_addr == laddr.s_addr &&
- so->so_faddr.s_addr == faddr.s_addr &&
- so->so_fport == fport)
- break;
- }
+ struct socket *so = *last;
+
+ /* Optimisation */
+ if (so != head &&
+ so->so_lport == lport &&
+ so->so_laddr.s_addr == laddr.s_addr &&
+ (!faddr.s_addr ||
+ (so->so_faddr.s_addr == faddr.s_addr &&
+ so->so_fport == fport))) {
+ return so;
+ }
- if (so == head)
- return (struct socket *)NULL;
- return so;
+ for (so = head->so_next; so != head; so = so->so_next) {
+ if (so->so_lport == lport &&
+ so->so_laddr.s_addr == laddr.s_addr &&
+ (!faddr.s_addr ||
+ (so->so_faddr.s_addr == faddr.s_addr &&
+ so->so_fport == fport))) {
+ *last = so;
+ return so;
+ }
+ }
+ return (struct socket *)NULL;
}
/*