Commit 4ee3345b authored by Pavel Emelyanov's avatar Pavel Emelyanov

packet: Support fanout

This one may be present and may be not, thus it's optional in the image.
The C-binding we use report the field absense in the parsed stream via
the has_xxx field, but in the google docs it's stated, that

	"When a message is parsed, if it does not contain an optional
	 element, the corresponding field in the parsed object is set
	 to the default value for that field."

Thus, I also declare the default value for it to be not zero as 0 is
a valid fanout configuration.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 12b826dc
...@@ -18,4 +18,8 @@ extern int packet_receive_one(struct nlmsghdr *h, void *arg); ...@@ -18,4 +18,8 @@ extern int packet_receive_one(struct nlmsghdr *h, void *arg);
#ifndef PACKET_VNET_HDR #ifndef PACKET_VNET_HDR
#define PACKET_VNET_HDR 15 #define PACKET_VNET_HDR 15
#endif #endif
#ifndef PACKET_FANOUT
#define PACKET_FANOUT 18
#endif
#endif #endif
...@@ -26,4 +26,5 @@ message packet_sock_entry { ...@@ -26,4 +26,5 @@ message packet_sock_entry {
required uint32 timestamp = 14; required uint32 timestamp = 14;
required uint32 copy_thresh = 15; required uint32 copy_thresh = 15;
repeated packet_mclist mclist = 16; repeated packet_mclist mclist = 16;
optional uint32 fanout = 17 [ default = 0xffffffff ];
} }
...@@ -35,8 +35,11 @@ struct packet_sock_desc { ...@@ -35,8 +35,11 @@ struct packet_sock_desc {
struct packet_diag_info nli; struct packet_diag_info nli;
int mreq_n; int mreq_n;
struct packet_diag_mclist *mreqs; struct packet_diag_mclist *mreqs;
unsigned int fanout;
}; };
#define NO_FANOUT ((unsigned int)-1)
void show_packetsk(int fd, struct cr_options *o) void show_packetsk(int fd, struct cr_options *o)
{ {
pb_show_plain(fd, PB_PACKETSK); pb_show_plain(fd, PB_PACKETSK);
...@@ -140,6 +143,11 @@ static int dump_one_packet_fd(int lfd, u32 id, const struct fd_parms *p) ...@@ -140,6 +143,11 @@ static int dump_one_packet_fd(int lfd, u32 id, const struct fd_parms *p)
if (ret) if (ret)
goto out; goto out;
if (sd->fanout != NO_FANOUT) {
psk.has_fanout = true;
psk.fanout = sd->fanout;
}
ret = pb_write_one(fdset_fd(glob_fdset, CR_FD_PACKETSK), &psk, PB_PACKETSK); ret = pb_write_one(fdset_fd(glob_fdset, CR_FD_PACKETSK), &psk, PB_PACKETSK);
out: out:
for (i = 0; i < psk.n_mclist; i++) for (i = 0; i < psk.n_mclist; i++)
...@@ -202,6 +210,11 @@ int packet_receive_one(struct nlmsghdr *hdr, void *arg) ...@@ -202,6 +210,11 @@ int packet_receive_one(struct nlmsghdr *hdr, void *arg)
if (packet_save_mreqs(sd, tb[PACKET_DIAG_MCLIST])) if (packet_save_mreqs(sd, tb[PACKET_DIAG_MCLIST]))
return -1; return -1;
if (tb[PACKET_DIAG_FANOUT])
sd->fanout = *(__u32 *)RTA_DATA(tb[PACKET_DIAG_FANOUT]);
else
sd->fanout = NO_FANOUT;
return sk_collect_one(m->pdiag_ino, PF_PACKET, &sd->sd); return sk_collect_one(m->pdiag_ino, PF_PACKET, &sd->sd);
} }
...@@ -299,6 +312,12 @@ static int open_packet_sk(struct file_desc *d) ...@@ -299,6 +312,12 @@ static int open_packet_sk(struct file_desc *d)
if (restore_mreqs(sk, pse)) if (restore_mreqs(sk, pse))
goto err_cl; goto err_cl;
if (pse->has_fanout) {
pr_info("Restoring fanout %x\n", pse->fanout);
if (restore_opt(sk, SOL_PACKET, PACKET_FANOUT, &pse->fanout))
goto err_cl;
}
if (rst_file_params(sk, pse->fown, pse->flags)) if (rst_file_params(sk, pse->fown, pse->flags))
goto err_cl; goto err_cl;
......
...@@ -273,7 +273,8 @@ int collect_sockets(int pid) ...@@ -273,7 +273,8 @@ int collect_sockets(int pid)
req.r.p.sdiag_family = AF_PACKET; req.r.p.sdiag_family = AF_PACKET;
req.r.p.sdiag_protocol = 0; req.r.p.sdiag_protocol = 0;
req.r.p.pdiag_show = PACKET_SHOW_INFO | PACKET_SHOW_MCLIST; req.r.p.pdiag_show = PACKET_SHOW_INFO | PACKET_SHOW_MCLIST |
PACKET_SHOW_FANOUT;
tmp = do_rtnl_req(nl, &req, sizeof(req), packet_receive_one, NULL); tmp = do_rtnl_req(nl, &req, sizeof(req), packet_receive_one, NULL);
if (tmp) if (tmp)
err = tmp; err = tmp;
......
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