Commit 216a3a65 authored by Pavel Emelyanov's avatar Pavel Emelyanov

sk: Add level to socket option dump/restore helpers

Packet socket need SOL_PACKET one.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 6949a848
...@@ -55,7 +55,10 @@ extern int dump_one_unix(struct fd_parms *p, int lfd, const struct cr_fdset *set ...@@ -55,7 +55,10 @@ extern int dump_one_unix(struct fd_parms *p, int lfd, const struct cr_fdset *set
extern int inet_collect_one(struct nlmsghdr *h, int family, int type, int proto); extern int inet_collect_one(struct nlmsghdr *h, int family, int type, int proto);
extern int unix_receive_one(struct nlmsghdr *h, void *); extern int unix_receive_one(struct nlmsghdr *h, void *);
extern int do_dump_opt(int sk, int name, void *val, int len); extern int do_dump_opt(int sk, int level, int name, void *val, int len);
#define dump_opt(s, n, f) do_dump_opt(s, n, f, sizeof(*f)) #define dump_opt(s, l, n, f) do_dump_opt(s, l, n, f, sizeof(*f))
extern int do_restore_opt(int sk, int level, int name, void *val, int len);
#define restore_opt(s, l, n, f) do_restore_opt(s, l, n, f, sizeof(*f))
#endif /* CR_SOCKETS_H__ */ #endif /* CR_SOCKETS_H__ */
...@@ -130,9 +130,9 @@ static struct inet_sk_desc *gen_uncon_sk(int lfd, const struct fd_parms *p) ...@@ -130,9 +130,9 @@ static struct inet_sk_desc *gen_uncon_sk(int lfd, const struct fd_parms *p)
sk->sd.ino = p->stat.st_ino; sk->sd.ino = p->stat.st_ino;
ret = do_dump_opt(lfd, SO_DOMAIN, &sk->sd.family, sizeof(sk->sd.family)); ret = do_dump_opt(lfd, SOL_SOCKET, SO_DOMAIN, &sk->sd.family, sizeof(sk->sd.family));
ret |= do_dump_opt(lfd, SO_TYPE, &sk->type, sizeof(sk->type)); ret |= do_dump_opt(lfd, SOL_SOCKET, SO_TYPE, &sk->type, sizeof(sk->type));
ret |= do_dump_opt(lfd, SO_PROTOCOL, &sk->proto, sizeof(sk->proto)); ret |= do_dump_opt(lfd, SOL_SOCKET, SO_PROTOCOL, &sk->proto, sizeof(sk->proto));
if (ret) if (ret)
goto err; goto err;
......
...@@ -32,7 +32,7 @@ static int dump_one_packet_fd(int lfd, u32 id, const struct fd_parms *p) ...@@ -32,7 +32,7 @@ static int dump_one_packet_fd(int lfd, u32 id, const struct fd_parms *p)
pr_info("Dumping packet socket fd %d id %#x\n", lfd, id); pr_info("Dumping packet socket fd %d id %#x\n", lfd, id);
if (dump_opt(lfd, SO_TYPE, &type)) if (dump_opt(lfd, SOL_SOCKET, SO_TYPE, &type))
return -1; return -1;
psk.id = id; psk.id = id;
......
...@@ -51,49 +51,47 @@ int sk_collect_one(int ino, int family, struct socket_desc *d) ...@@ -51,49 +51,47 @@ int sk_collect_one(int ino, int family, struct socket_desc *d)
return 0; return 0;
} }
static int do_restore_opt(int sk, int name, void *val, int len) int do_restore_opt(int sk, int level, int name, void *val, int len)
{ {
if (setsockopt(sk, SOL_SOCKET, name, val, len) < 0) { if (setsockopt(sk, level, name, val, len) < 0) {
pr_perror("Can't set SOL_SOCKET:%d (len %d)", name, len); pr_perror("Can't set %d:%d (len %d)", level, name, len);
return -1; return -1;
} }
return 0; return 0;
} }
#define restore_opt(s, n, f) do_restore_opt(s, n, f, sizeof(*f))
int restore_socket_opts(int sk, SkOptsEntry *soe) int restore_socket_opts(int sk, SkOptsEntry *soe)
{ {
int ret = 0; int ret = 0;
struct timeval tv; struct timeval tv;
ret |= restore_opt(sk, SO_SNDBUFFORCE, &soe->so_sndbuf); ret |= restore_opt(sk, SOL_SOCKET, SO_SNDBUFFORCE, &soe->so_sndbuf);
ret |= restore_opt(sk, SO_RCVBUFFORCE, &soe->so_rcvbuf); ret |= restore_opt(sk, SOL_SOCKET, SO_RCVBUFFORCE, &soe->so_rcvbuf);
tv.tv_sec = soe->so_snd_tmo_sec; tv.tv_sec = soe->so_snd_tmo_sec;
tv.tv_usec = soe->so_snd_tmo_usec; tv.tv_usec = soe->so_snd_tmo_usec;
ret |= restore_opt(sk, SO_SNDTIMEO, &tv); ret |= restore_opt(sk, SOL_SOCKET, SO_SNDTIMEO, &tv);
tv.tv_sec = soe->so_rcv_tmo_sec; tv.tv_sec = soe->so_rcv_tmo_sec;
tv.tv_usec = soe->so_rcv_tmo_usec; tv.tv_usec = soe->so_rcv_tmo_usec;
ret |= restore_opt(sk, SO_RCVTIMEO, &tv); ret |= restore_opt(sk, SOL_SOCKET, SO_RCVTIMEO, &tv);
return ret; return ret;
} }
int do_dump_opt(int sk, int name, void *val, int len) int do_dump_opt(int sk, int level, int name, void *val, int len)
{ {
socklen_t aux = len; socklen_t aux = len;
if (getsockopt(sk, SOL_SOCKET, name, val, &aux) < 0) { if (getsockopt(sk, level, name, val, &aux) < 0) {
pr_perror("Can't get SOL_SOCKET:%d opt", name); pr_perror("Can't get %d:%d opt", level, name);
return -1; return -1;
} }
if (aux != len) { if (aux != len) {
pr_err("Len mismatch on SOL_SOCKET:%d : %d, want %d\n", pr_err("Len mismatch on %d:%d : %d, want %d\n",
name, aux, len); level, name, aux, len);
return -1; return -1;
} }
...@@ -105,14 +103,14 @@ int dump_socket_opts(int sk, SkOptsEntry *soe) ...@@ -105,14 +103,14 @@ int dump_socket_opts(int sk, SkOptsEntry *soe)
int ret = 0; int ret = 0;
struct timeval tv; struct timeval tv;
ret |= dump_opt(sk, SO_SNDBUF, &soe->so_sndbuf); ret |= dump_opt(sk, SOL_SOCKET, SO_SNDBUF, &soe->so_sndbuf);
ret |= dump_opt(sk, SO_RCVBUF, &soe->so_rcvbuf); ret |= dump_opt(sk, SOL_SOCKET, SO_RCVBUF, &soe->so_rcvbuf);
ret |= dump_opt(sk, SO_SNDTIMEO, &tv); ret |= dump_opt(sk, SOL_SOCKET, SO_SNDTIMEO, &tv);
soe->so_snd_tmo_sec = tv.tv_sec; soe->so_snd_tmo_sec = tv.tv_sec;
soe->so_snd_tmo_usec = tv.tv_usec; soe->so_snd_tmo_usec = tv.tv_usec;
ret |= dump_opt(sk, SO_RCVTIMEO, &tv); ret |= dump_opt(sk, SOL_SOCKET, SO_RCVTIMEO, &tv);
soe->so_rcv_tmo_sec = tv.tv_sec; soe->so_rcv_tmo_sec = tv.tv_sec;
soe->so_rcv_tmo_usec = tv.tv_usec; soe->so_rcv_tmo_usec = tv.tv_usec;
...@@ -123,7 +121,7 @@ int dump_socket(struct fd_parms *p, int lfd, const struct cr_fdset *cr_fdset) ...@@ -123,7 +121,7 @@ int dump_socket(struct fd_parms *p, int lfd, const struct cr_fdset *cr_fdset)
{ {
int family; int family;
if (dump_opt(lfd, SO_DOMAIN, &family)) if (dump_opt(lfd, SOL_SOCKET, SO_DOMAIN, &family))
return -1; return -1;
switch (family) { switch (family) {
......
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