Commit cdc6f4c1 authored by Andrei Vagin's avatar Andrei Vagin Committed by Pavel Emelyanov

soccr: add source and destination addresses to libsoccr_sk_data

These addresses will be used to restore half-closed sockets,
we will need to send a fake fin packet for that.

And in the next patch connect() will be moved into soccr.
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent a73eb530
......@@ -85,4 +85,8 @@ struct rst_tcp_sock {
bool reuseaddr;
};
union libsoccr_addr;
int restore_sockaddr(union libsoccr_addr *sa,
int family, u32 pb_port, u32 *pb_addr, u32 ifindex);
#endif /* __CR_SK_INET_H__ */
......@@ -11,6 +11,8 @@
#include <string.h>
#include <stdlib.h>
#include "../soccr/soccr.h"
#include "libnetlink.h"
#include "cr_options.h"
#include "imgset.h"
......@@ -655,12 +657,7 @@ err:
return -1;
}
union sockaddr_inet {
struct sockaddr_in v4;
struct sockaddr_in6 v6;
};
static int restore_sockaddr(union sockaddr_inet *sa,
int restore_sockaddr(union libsoccr_addr *sa,
int family, u32 pb_port, u32 *pb_addr, u32 ifindex)
{
BUILD_BUG_ON(sizeof(sa->v4.sin_addr.s_addr) > PB_ALEN_INET * sizeof(u32));
......@@ -695,7 +692,7 @@ static int restore_sockaddr(union sockaddr_inet *sa,
int inet_bind(int sk, struct inet_sk_info *ii)
{
bool rst_freebind = false;
union sockaddr_inet addr;
union libsoccr_addr addr;
int addr_size, ifindex = 0;
if (ii->ie->ifname) {
......@@ -751,7 +748,7 @@ int inet_bind(int sk, struct inet_sk_info *ii)
int inet_connect(int sk, struct inet_sk_info *ii)
{
union sockaddr_inet addr;
union libsoccr_addr addr;
int addr_size;
addr_size = restore_sockaddr(&addr, ii->ie->family,
......
......@@ -338,6 +338,15 @@ static int restore_tcp_conn_state(int sk, struct libsoccr_sk *socr, struct inet_
data.rcv_wup = tse->rcv_wup;
}
if (restore_sockaddr(&data.src_addr,
ii->ie->family, ii->ie->src_port,
ii->ie->src_addr, 0) < 0)
goto err_c;
if (restore_sockaddr(&data.dst_addr,
ii->ie->family, ii->ie->dst_port,
ii->ie->dst_addr, 0) < 0)
goto err_c;
(void)data;
if (libsoccr_set_sk_data_unbound(socr, &data, sizeof(data)))
......
#ifndef __LIBSOCCR_H__
#define __LIBSOCCR_H__
#include <linux/types.h>
#include <netinet/in.h>
#include <stdint.h>
#include "config.h"
......@@ -57,6 +58,12 @@ void libsoccr_set_log(unsigned int level, void (*fn)(unsigned int level, const c
*/
struct libsoccr_sk;
union libsoccr_addr {
struct sockaddr sa;
struct sockaddr_in v4;
struct sockaddr_in6 v6;
};
/*
* Connection info that should be saved after fetching from the
* socket and given back into the library in two steps (see below).
......@@ -80,6 +87,9 @@ struct libsoccr_sk_data {
__u32 max_window;
__u32 rcv_wnd;
__u32 rcv_wup;
union libsoccr_addr src_addr;
union libsoccr_addr dst_addr;
};
/*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment