* [PATCH iproute2] ss: Show more info (ring,fanout) for packet socks
@ 2015-05-13 9:39 Vadim Kochan
2015-05-13 21:10 ` Willem de Bruijn
0 siblings, 1 reply; 7+ messages in thread
From: Vadim Kochan @ 2015-05-13 9:39 UTC (permalink / raw)
To: netdev; +Cc: Vadim Kochan
From: Vadim Kochan <vadim4j@gmail.com>
Print such info like version, tx/rx ring, fanout for
packet sockets when '-e' option was specified.
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
---
Would it be problematic for parsers as it uses '-e' option? Or
may be it would be better to use '-e -e' ?
misc/ss.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 79 insertions(+), 2 deletions(-)
diff --git a/misc/ss.c b/misc/ss.c
index 870cad1..74797a8 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -2834,13 +2834,27 @@ static int packet_stats_print(struct sockstat *s, const struct filter *f)
return 0;
}
+static void packet_show_ring(struct packet_diag_ring *ring)
+{
+ printf("blk_size:%d", ring->pdr_block_size);
+ printf(",blk_nr:%d", ring->pdr_block_nr);
+ printf(",frm_size:%d", ring->pdr_frame_size);
+ printf(",frm_nr:%d", ring->pdr_frame_nr);
+ printf(",tmo:%d", ring->pdr_retire_tmo);
+ printf(",features:0x%x", ring->pdr_features);
+}
+
static int packet_show_sock(const struct sockaddr_nl *addr,
struct nlmsghdr *nlh, void *arg)
{
const struct filter *f = arg;
struct packet_diag_msg *r = NLMSG_DATA(nlh);
+ struct packet_diag_info *pinfo = NULL;
+ struct packet_diag_ring *ring_rx = NULL, *ring_tx = NULL;
struct rtattr *tb[PACKET_DIAG_MAX+1];
struct sockstat stat = {};
+ uint32_t fanout = 0;
+ bool has_fanout = false;
parse_rtattr(tb, PACKET_DIAG_MAX, (struct rtattr*)(r+1),
nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
@@ -2861,16 +2875,78 @@ static int packet_show_sock(const struct sockaddr_nl *addr,
}
if (tb[PACKET_DIAG_INFO]) {
- struct packet_diag_info *pinfo = RTA_DATA(tb[PACKET_DIAG_INFO]);
+ pinfo = RTA_DATA(tb[PACKET_DIAG_INFO]);
stat.lport = stat.iface = pinfo->pdi_index;
}
if (tb[PACKET_DIAG_UID])
stat.uid = *(__u32 *)RTA_DATA(tb[PACKET_DIAG_UID]);
+ if (tb[PACKET_DIAG_RX_RING])
+ ring_rx = RTA_DATA(tb[PACKET_DIAG_RX_RING]);
+
+ if (tb[PACKET_DIAG_TX_RING])
+ ring_tx = RTA_DATA(tb[PACKET_DIAG_TX_RING]);
+
+ if (tb[PACKET_DIAG_FANOUT]) {
+ has_fanout = true;
+ fanout = *(uint32_t *)RTA_DATA(tb[PACKET_DIAG_FANOUT]);
+ }
+
if (packet_stats_print(&stat, f))
return 0;
+ if (show_details) {
+ if (pinfo) {
+ printf("\n\tver:%d", pinfo->pdi_version);
+ printf(" cpy_thresh:%d", pinfo->pdi_copy_thresh);
+ printf(" flags( ");
+ if (pinfo->pdi_flags & PDI_RUNNING)
+ printf("running");
+ if (pinfo->pdi_flags & PDI_AUXDATA)
+ printf(" auxdata");
+ if (pinfo->pdi_flags & PDI_ORIGDEV)
+ printf(" origdev");
+ if (pinfo->pdi_flags & PDI_VNETHDR)
+ printf(" vnethdr");
+ if (pinfo->pdi_flags & PDI_LOSS)
+ printf(" loss");
+ if (!pinfo->pdi_flags)
+ printf("0");
+ printf(" )");
+ }
+ if (ring_rx) {
+ printf("\n\tring_rx(");
+ packet_show_ring(ring_rx);
+ printf(")");
+ }
+ if (ring_tx) {
+ printf("\n\tring_tx(");
+ packet_show_ring(ring_tx);
+ printf(")");
+ }
+ if (has_fanout) {
+ uint16_t type = (fanout >> 16) & 0xffff;
+
+ printf("\n\tfanout(");
+ printf("id:%d,", fanout & 0xff);
+ printf("type:0x%x", type);
+ if (type == 0)
+ printf("(hash)");
+ else if (type == 1)
+ printf("(lb)");
+ else if (type == 2)
+ printf("(cpu)");
+ else if (type == 3)
+ printf("(rollover)");
+ else if (type == 4)
+ printf("(random)");
+ else if (type == 5)
+ printf("(qm)");
+ printf(")");
+ }
+ }
+
if (show_bpf && tb[PACKET_DIAG_FILTER]) {
struct sock_filter *fil =
RTA_DATA(tb[PACKET_DIAG_FILTER]);
@@ -2894,7 +2970,8 @@ static int packet_show_netlink(struct filter *f)
DIAG_REQUEST(req, struct packet_diag_req r);
req.r.sdiag_family = AF_PACKET;
- req.r.pdiag_show = PACKET_SHOW_INFO | PACKET_SHOW_MEMINFO | PACKET_SHOW_FILTER;
+ req.r.pdiag_show = PACKET_SHOW_INFO | PACKET_SHOW_MEMINFO |
+ PACKET_SHOW_FILTER | PACKET_SHOW_RING_CFG | PACKET_SHOW_FANOUT;
return handle_netlink_request(f, &req.nlh, sizeof(req), packet_show_sock);
}
--
2.3.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH iproute2] ss: Show more info (ring,fanout) for packet socks
2015-05-13 9:39 [PATCH iproute2] ss: Show more info (ring,fanout) for packet socks Vadim Kochan
@ 2015-05-13 21:10 ` Willem de Bruijn
2015-05-14 11:09 ` Vadim Kochan
0 siblings, 1 reply; 7+ messages in thread
From: Willem de Bruijn @ 2015-05-13 21:10 UTC (permalink / raw)
To: Vadim Kochan; +Cc: Network Development
> + }
> + if (has_fanout) {
> + uint16_t type = (fanout >> 16) & 0xffff;
type can be modified by flags in the upper 8 bits. Better
mask those out and report them separately.
> +
> + printf("\n\tfanout(");
> + printf("id:%d,", fanout & 0xff);
> + printf("type:0x%x", type);
> + if (type == 0)
> + printf("(hash)");
> + else if (type == 1)
> + printf("(lb)");
> + else if (type == 2)
> + printf("(cpu)");
> + else if (type == 3)
> + printf("(rollover)");
> + else if (type == 4)
> + printf("(random)");
> + else if (type == 5)
> + printf("(qm)");
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH iproute2] ss: Show more info (ring,fanout) for packet socks
2015-05-13 21:10 ` Willem de Bruijn
@ 2015-05-14 11:09 ` Vadim Kochan
2015-05-14 19:54 ` Willem de Bruijn
0 siblings, 1 reply; 7+ messages in thread
From: Vadim Kochan @ 2015-05-14 11:09 UTC (permalink / raw)
To: Willem de Bruijn; +Cc: Vadim Kochan, Network Development
On Wed, May 13, 2015 at 05:10:38PM -0400, Willem de Bruijn wrote:
> > + }
> > + if (has_fanout) {
> > + uint16_t type = (fanout >> 16) & 0xffff;
>
> type can be modified by flags in the upper 8 bits. Better
> mask those out and report them separately.
Kernel puts only id & type in diag message, flags are stored in separated
member of 'struct packet_sock'.
>
> > +
> > + printf("\n\tfanout(");
> > + printf("id:%d,", fanout & 0xff);
> > + printf("type:0x%x", type);
> > + if (type == 0)
> > + printf("(hash)");
> > + else if (type == 1)
> > + printf("(lb)");
> > + else if (type == 2)
> > + printf("(cpu)");
> > + else if (type == 3)
> > + printf("(rollover)");
> > + else if (type == 4)
> > + printf("(random)");
> > + else if (type == 5)
> > + printf("(qm)");
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH iproute2] ss: Show more info (ring,fanout) for packet socks
2015-05-14 11:09 ` Vadim Kochan
@ 2015-05-14 19:54 ` Willem de Bruijn
2015-05-14 20:21 ` Vadim Kochan
0 siblings, 1 reply; 7+ messages in thread
From: Willem de Bruijn @ 2015-05-14 19:54 UTC (permalink / raw)
To: Vadim Kochan; +Cc: Network Development
On Thu, May 14, 2015 at 7:09 AM, Vadim Kochan <vadim4j@gmail.com> wrote:
> On Wed, May 13, 2015 at 05:10:38PM -0400, Willem de Bruijn wrote:
>> > + }
>> > + if (has_fanout) {
>> > + uint16_t type = (fanout >> 16) & 0xffff;
>>
>> type can be modified by flags in the upper 8 bits. Better
>> mask those out and report them separately.
> Kernel puts only id & type in diag message, flags are stored in separated
> member of 'struct packet_sock'.
I don't mean pdi_flags, but
PACKET_FANOUT_FLAG_ROLLOVER
PACKET_FANOUT_FLAG_DEFRAG
which are passed as part of this u32 by the process during setsockopt
PACKET_FANOUT.
>
>>
>> > +
>> > + printf("\n\tfanout(");
>> > + printf("id:%d,", fanout & 0xff);
>> > + printf("type:0x%x", type);
>> > + if (type == 0)
>> > + printf("(hash)");
>> > + else if (type == 1)
>> > + printf("(lb)");
>> > + else if (type == 2)
>> > + printf("(cpu)");
>> > + else if (type == 3)
>> > + printf("(rollover)");
>> > + else if (type == 4)
>> > + printf("(random)");
>> > + else if (type == 5)
>> > + printf("(qm)");
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH iproute2] ss: Show more info (ring,fanout) for packet socks
2015-05-14 19:54 ` Willem de Bruijn
@ 2015-05-14 20:21 ` Vadim Kochan
2015-05-14 20:39 ` Willem de Bruijn
0 siblings, 1 reply; 7+ messages in thread
From: Vadim Kochan @ 2015-05-14 20:21 UTC (permalink / raw)
To: Willem de Bruijn; +Cc: Vadim Kochan, Network Development
On Thu, May 14, 2015 at 03:54:41PM -0400, Willem de Bruijn wrote:
> On Thu, May 14, 2015 at 7:09 AM, Vadim Kochan <vadim4j@gmail.com> wrote:
> > On Wed, May 13, 2015 at 05:10:38PM -0400, Willem de Bruijn wrote:
> >> > + }
> >> > + if (has_fanout) {
> >> > + uint16_t type = (fanout >> 16) & 0xffff;
> >>
> >> type can be modified by flags in the upper 8 bits. Better
> >> mask those out and report them separately.
> > Kernel puts only id & type in diag message, flags are stored in separated
> > member of 'struct packet_sock'.
>
> I don't mean pdi_flags, but
>
> PACKET_FANOUT_FLAG_ROLLOVER
> PACKET_FANOUT_FLAG_DEFRAG
sure, I understood what you meant.
>
> which are passed as part of this u32 by the process during setsockopt
> PACKET_FANOUT.
>
OK, its better to look into the kernel:
net/packet/af_packet.c
static int fanout_add(struct sock *sk, u16 id, u16 type_flags)
{
struct packet_fanout *f, *match;
u8 type = type_flags & 0xff;
u8 flags = type_flags >> 8;
...
match->id = id;
match->type = type;
match->flags = flags;
...
}
As I see this function is called from setsockopt, takes type_flags and splits it into type & flags
and store them separately in struct packet_fanout.
Then what I see in:
net/packet/diag.c:
static int pdiag_put_fanout(struct packet_sock *po, struct sk_buff *nlskb)
{
int ret = 0;
mutex_lock(&fanout_mutex);
if (po->fanout) {
u32 val;
val = (u32)po->fanout->id | ((u32)po->fanout->type << 16);
ret = nla_put_u32(nlskb, PACKET_DIAG_FANOUT, val);
}
mutex_unlock(&fanout_mutex);
return ret;
}
I see that to put flags here it needs to use po->fanout->flags and mix
them into u32 val, but instead I see that it uses only id & type.
Please correct me if I am wrong.
Thanks,
> >
> >>
> >> > +
> >> > + printf("\n\tfanout(");
> >> > + printf("id:%d,", fanout & 0xff);
> >> > + printf("type:0x%x", type);
> >> > + if (type == 0)
> >> > + printf("(hash)");
> >> > + else if (type == 1)
> >> > + printf("(lb)");
> >> > + else if (type == 2)
> >> > + printf("(cpu)");
> >> > + else if (type == 3)
> >> > + printf("(rollover)");
> >> > + else if (type == 4)
> >> > + printf("(random)");
> >> > + else if (type == 5)
> >> > + printf("(qm)");
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH iproute2] ss: Show more info (ring,fanout) for packet socks
2015-05-14 20:21 ` Vadim Kochan
@ 2015-05-14 20:39 ` Willem de Bruijn
2015-05-14 20:44 ` Vadim Kochan
0 siblings, 1 reply; 7+ messages in thread
From: Willem de Bruijn @ 2015-05-14 20:39 UTC (permalink / raw)
To: Vadim Kochan; +Cc: Network Development
On Thu, May 14, 2015 at 4:21 PM, Vadim Kochan <vadim4j@gmail.com> wrote:
> On Thu, May 14, 2015 at 03:54:41PM -0400, Willem de Bruijn wrote:
>> On Thu, May 14, 2015 at 7:09 AM, Vadim Kochan <vadim4j@gmail.com> wrote:
>> > On Wed, May 13, 2015 at 05:10:38PM -0400, Willem de Bruijn wrote:
>> >> > + }
>> >> > + if (has_fanout) {
>> >> > + uint16_t type = (fanout >> 16) & 0xffff;
>> >>
>> >> type can be modified by flags in the upper 8 bits. Better
>> >> mask those out and report them separately.
>> > Kernel puts only id & type in diag message, flags are stored in separated
>> > member of 'struct packet_sock'.
>>
>> I don't mean pdi_flags, but
>>
>> PACKET_FANOUT_FLAG_ROLLOVER
>> PACKET_FANOUT_FLAG_DEFRAG
> sure, I understood what you meant.
>>
>> which are passed as part of this u32 by the process during setsockopt
>> PACKET_FANOUT.
>>
> OK, its better to look into the kernel:
>
> net/packet/af_packet.c
>
> static int fanout_add(struct sock *sk, u16 id, u16 type_flags)
> {
> struct packet_fanout *f, *match;
> u8 type = type_flags & 0xff;
> u8 flags = type_flags >> 8;
>
> ...
>
> match->id = id;
> match->type = type;
> match->flags = flags;
>
> ...
> }
>
> As I see this function is called from setsockopt, takes type_flags and splits it into type & flags
> and store them separately in struct packet_fanout.
>
> Then what I see in:
>
> net/packet/diag.c:
>
>
> static int pdiag_put_fanout(struct packet_sock *po, struct sk_buff *nlskb)
> {
> int ret = 0;
>
> mutex_lock(&fanout_mutex);
> if (po->fanout) {
> u32 val;
>
> val = (u32)po->fanout->id | ((u32)po->fanout->type << 16);
> ret = nla_put_u32(nlskb, PACKET_DIAG_FANOUT, val);
> }
> mutex_unlock(&fanout_mutex);
>
> return ret;
> }
>
> I see that to put flags here it needs to use po->fanout->flags and mix
> them into u32 val, but instead I see that it uses only id & type.
>
> Please correct me if I am wrong.
Thanks for the details. You are correct. Flags are not mixed in, like
are in the getsockopt case. In that case, type can only be 8 bits.
>
> Thanks,
>> >
>> >>
>> >> > +
>> >> > + printf("\n\tfanout(");
>> >> > + printf("id:%d,", fanout & 0xff);
ID can be 16 bits.
>> >> > + printf("type:0x%x", type);
>> >> > + if (type == 0)
>> >> > + printf("(hash)");
>> >> > + else if (type == 1)
>> >> > + printf("(lb)");
>> >> > + else if (type == 2)
>> >> > + printf("(cpu)");
>> >> > + else if (type == 3)
>> >> > + printf("(rollover)");
>> >> > + else if (type == 4)
>> >> > + printf("(random)");
>> >> > + else if (type == 5)
>> >> > + printf("(qm)");
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH iproute2] ss: Show more info (ring,fanout) for packet socks
2015-05-14 20:39 ` Willem de Bruijn
@ 2015-05-14 20:44 ` Vadim Kochan
0 siblings, 0 replies; 7+ messages in thread
From: Vadim Kochan @ 2015-05-14 20:44 UTC (permalink / raw)
To: Willem de Bruijn; +Cc: Vadim Kochan, Network Development
On Thu, May 14, 2015 at 04:39:01PM -0400, Willem de Bruijn wrote:
> On Thu, May 14, 2015 at 4:21 PM, Vadim Kochan <vadim4j@gmail.com> wrote:
> > On Thu, May 14, 2015 at 03:54:41PM -0400, Willem de Bruijn wrote:
> >> On Thu, May 14, 2015 at 7:09 AM, Vadim Kochan <vadim4j@gmail.com> wrote:
> >> > On Wed, May 13, 2015 at 05:10:38PM -0400, Willem de Bruijn wrote:
> >> >> > + }
> >> >> > + if (has_fanout) {
> >> >> > + uint16_t type = (fanout >> 16) & 0xffff;
> >> >>
> >> >> type can be modified by flags in the upper 8 bits. Better
> >> >> mask those out and report them separately.
> >> > Kernel puts only id & type in diag message, flags are stored in separated
> >> > member of 'struct packet_sock'.
> >>
> >> I don't mean pdi_flags, but
> >>
> >> PACKET_FANOUT_FLAG_ROLLOVER
> >> PACKET_FANOUT_FLAG_DEFRAG
> > sure, I understood what you meant.
> >>
> >> which are passed as part of this u32 by the process during setsockopt
> >> PACKET_FANOUT.
> >>
> > OK, its better to look into the kernel:
> >
> > net/packet/af_packet.c
> >
> > static int fanout_add(struct sock *sk, u16 id, u16 type_flags)
> > {
> > struct packet_fanout *f, *match;
> > u8 type = type_flags & 0xff;
> > u8 flags = type_flags >> 8;
> >
> > ...
> >
> > match->id = id;
> > match->type = type;
> > match->flags = flags;
> >
> > ...
> > }
> >
> > As I see this function is called from setsockopt, takes type_flags and splits it into type & flags
> > and store them separately in struct packet_fanout.
> >
> > Then what I see in:
> >
> > net/packet/diag.c:
> >
> >
> > static int pdiag_put_fanout(struct packet_sock *po, struct sk_buff *nlskb)
> > {
> > int ret = 0;
> >
> > mutex_lock(&fanout_mutex);
> > if (po->fanout) {
> > u32 val;
> >
> > val = (u32)po->fanout->id | ((u32)po->fanout->type << 16);
> > ret = nla_put_u32(nlskb, PACKET_DIAG_FANOUT, val);
> > }
> > mutex_unlock(&fanout_mutex);
> >
> > return ret;
> > }
> >
> > I see that to put flags here it needs to use po->fanout->flags and mix
> > them into u32 val, but instead I see that it uses only id & type.
> >
> > Please correct me if I am wrong.
>
> Thanks for the details. You are correct. Flags are not mixed in, like
> are in the getsockopt case. In that case, type can only be 8 bits.
>
> >
> > Thanks,
> >> >
> >> >>
> >> >> > +
> >> >> > + printf("\n\tfanout(");
> >> >> > + printf("id:%d,", fanout & 0xff);
>
> ID can be 16 bits.
Right, will fix it in v2, thanks!
>
> >> >> > + printf("type:0x%x", type);
> >> >> > + if (type == 0)
> >> >> > + printf("(hash)");
> >> >> > + else if (type == 1)
> >> >> > + printf("(lb)");
> >> >> > + else if (type == 2)
> >> >> > + printf("(cpu)");
> >> >> > + else if (type == 3)
> >> >> > + printf("(rollover)");
> >> >> > + else if (type == 4)
> >> >> > + printf("(random)");
> >> >> > + else if (type == 5)
> >> >> > + printf("(qm)");
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-05-14 20:44 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-13 9:39 [PATCH iproute2] ss: Show more info (ring,fanout) for packet socks Vadim Kochan
2015-05-13 21:10 ` Willem de Bruijn
2015-05-14 11:09 ` Vadim Kochan
2015-05-14 19:54 ` Willem de Bruijn
2015-05-14 20:21 ` Vadim Kochan
2015-05-14 20:39 ` Willem de Bruijn
2015-05-14 20:44 ` Vadim Kochan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).