<div dir="ltr">Hi Andrei,<div><br></div><div>this patch is for <a href="https://github.com/xemul/criu/issues/73">https://github.com/xemul/criu/issues/73</a></div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-12-27 22:08 GMT+03:00 Andrei Vagin <span dir="ltr"><<a href="mailto:avagin@virtuozzo.com" target="_blank">avagin@virtuozzo.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Tue, Dec 20, 2016 at 05:17:34PM +0300, <a href="mailto:the7winds@yandex.ru">the7winds@yandex.ru</a> wrote:<br>
> From: Gleb Valin <<a href="mailto:the7winds@yandex.ru">the7winds@yandex.ru</a>><br>
><br>
> If socket type is SOCK_PACKET it restores binding with proper address structure.<br>
<br>
</span>Hi Gleb,<br>
<br>
Could you give more details about this patch? I remember that Pavel did<br>
something with packet sockets.<br>
<br>
commit fc7071d05e1b7140bcc39f0a45a86c<wbr>46bdbcb716<br>
Author: Pavel Emelyanov <<a href="mailto:xemul@parallels.com">xemul@parallels.com</a>><br>
Date: Thu Aug 9 16:17:41 2012 +0400<br>
<br>
net: Packet sockets basic support<br>
<br>
Support only basic packet socket functionality -- create and bind.<br>
This should be enough to start testing dhclient inside container.<br>
Other stuff (filter, mmaps, fanouts, etc.) will come later.<br>
<br>
Signed-off-by: Pavel Emelyanov <<a href="mailto:xemul@parallels.com">xemul@parallels.com</a>><br>
<div><div class="h5"><br>
><br>
> Signed-off-by: Gleb Valin <<a href="mailto:the7winds@yandex.ru">the7winds@yandex.ru</a>><br>
> Signed-off-by: Eugene Batalov <<a href="mailto:eabatalov89@gmail.com">eabatalov89@gmail.com</a>><br>
> ---<br>
> criu/sk-packet.c | 54 ++++++++++++++++++++++++++++++<wbr>++++++++++++++++++++++++<br>
> 1 file changed, 54 insertions(+)<br>
><br>
> diff --git a/criu/sk-packet.c b/criu/sk-packet.c<br>
> index bcd4ff33..a7657bfc 100644<br>
> --- a/criu/sk-packet.c<br>
> +++ b/criu/sk-packet.c<br>
> @@ -1,5 +1,7 @@<br>
> #include <linux/if_packet.h><br>
> #include <sys/socket.h><br>
> +#include <net/if.h><br>
> +#include <sys/ioctl.h><br>
> #include <linux/netlink.h><br>
> #include <linux/rtnetlink.h><br>
> #include <libnl3/netlink/msg.h><br>
> @@ -403,6 +405,55 @@ static int restore_rings(int sk, PacketSockEntry *psk)<br>
> return 0;<br>
> }<br>
><br>
> +static int open_packet_sk_spkt(<wbr>PacketSockEntry *pse)<br>
> +{<br>
> + struct sockaddr addr_spkt;<br>
> + int sk;<br>
> +<br>
> + sk = socket(PF_PACKET, pse->type, pse->protocol);<br>
> + if (sk < 0) {<br>
> + pr_perror("Can't create packet socket");<br>
> + return -1;<br>
> + }<br>
> +<br>
> + memset(&addr_spkt, 0, sizeof(addr_spkt));<br>
> + addr_spkt.sa_family = AF_PACKET;<br>
> +<br>
> + // if the socket was bound to any device<br>
> + if (pse->ifindex > 0) {<br>
> + const size_t sa_data_size = sizeof(addr_spkt.sa_data);<br>
> + struct ifreq req;<br>
> +<br>
> + memset(&req, 0, sizeof(req));<br>
> + req.ifr_ifindex = pse->ifindex;<br>
> +<br>
> + if (ioctl(sk, SIOCGIFNAME, &req) < 0) {<br>
> + pr_perror("Can't get interface name (ifindex %d)", pse->ifindex);<br>
> + goto err;<br>
> + }<br>
> +<br>
> + strncpy(addr_spkt.sa_data, req.ifr_name, sa_data_size);<br>
> + addr_spkt.sa_data[sa_data_size - 1] = 0;<br>
> +<br>
> + if (bind(sk, &addr_spkt, sizeof(addr_spkt)) < 0) {<br>
> + pr_perror("Can't bind packet socket to %s", req.ifr_name);<br>
> + goto err;<br>
> + }<br>
> + }<br>
> +<br>
> + if (rst_file_params(sk, pse->fown, pse->flags))<br>
> + goto err;<br>
> +<br>
> + if (restore_socket_opts(sk, pse->opts))<br>
> + goto err;<br>
> +<br>
> + return sk;<br>
> +<br>
> +err:<br>
> + close(sk);<br>
> + return -1;<br>
> +}<br>
> +<br>
> static int open_packet_sk(struct file_desc *d)<br>
> {<br>
> struct packet_sock_info *psi;<br>
> @@ -415,6 +466,9 @@ static int open_packet_sk(struct file_desc *d)<br>
><br>
> pr_info("Opening packet socket id %#x\n", pse->id);<br>
><br>
> + if (pse->type == SOCK_PACKET)<br>
> + return open_packet_sk_spkt(pse);<br>
> +<br>
> sk = socket(PF_PACKET, pse->type, pse->protocol);<br>
> if (sk < 0) {<br>
> pr_perror("Can't create packet sock");<br>
> --<br>
> 2.11.0<br>
><br>
</div></div>> ______________________________<wbr>_________________<br>
> CRIU mailing list<br>
> <a href="mailto:CRIU@openvz.org">CRIU@openvz.org</a><br>
> <a href="https://lists.openvz.org/mailman/listinfo/criu" rel="noreferrer" target="_blank">https://lists.openvz.org/<wbr>mailman/listinfo/criu</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Best regards,<br>Eugene Batalov.</div>
</div>