[PATCH 7/8] netlink: add a basic socket diag parser of AF_SMC messages

JingPiao Chen chenjingpiao at gmail.com
Wed Jun 14 08:51:13 UTC 2017


On Tue, Jun 13, 2017 at 11:47:45PM +0300, Dmitry V. Levin wrote:
> On Tue, Jun 13, 2017 at 10:13:24PM +0800, JingPiao Chen wrote:
[...]
> > +#ifdef AF_SMC
> > +static bool
> > +decode_smc_diag_req(struct tcb *const tcp,
> > +    const struct nlmsghdr *const nlmsghdr,
> > +    const kernel_ulong_t addr,
> > +    const kernel_ulong_t len)
> > +{
> > + struct smc_diag_req req;
> > +
> > + if (len < sizeof(req) || umove(tcp, addr, &req))
> > + return false;
> > +
> > + tprints("{diag_family=");
> > + printxval(addrfams, req.diag_family, "AF_???");
> > + tprints(", diag_ext=");
> > + printflags(smc_diag_extended_flags, req.diag_ext,
> > +   "1<<(SMC_DIAG_\?\?\?-1)");
> > + tprints(", id=");
> > + /*
> > + * AF_SMC protocol family socket handler
> > + * keeping the AF_INET sock address.
> > + */
> > + print_inet_diag_sockid(&req.id, AF_INET);
>
> Is it correct?  Does the kernel treat smc_diag_req.id as AF_INET,
AF_INET6,
> or something else?
>

The comment exist in net/smc/af_smc.c: 4
 *  AF_SMC protocol family socket handler keeping the AF_INET sock address
type
 *  applies to SOCK_STREAM sockets only

net/smc/smc_diag.c:
static void smc_diag_msg_common_fill(struct smc_diag_msg *r, struct sock
*sk)
{
struct smc_sock *smc = smc_sk(sk);

r->diag_family = sk->sk_family;
if (!smc->clcsock)
return;
r->id.idiag_sport = htons(smc->clcsock->sk->sk_num);
r->id.idiag_dport = smc->clcsock->sk->sk_dport;
r->id.idiag_if = smc->clcsock->sk->sk_bound_dev_if;
sock_diag_save_cookie(sk, r->id.idiag_cookie);
memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
r->id.idiag_src[0] = smc->clcsock->sk->sk_rcv_saddr;
r->id.idiag_dst[0] = smc->clcsock->sk->sk_daddr;
}

net/ipv4/inet_diag.c:
void inet_diag_msg_common_fill(struct inet_diag_msg *r, struct sock *sk)
{
r->idiag_family = sk->sk_family;

r->id.idiag_sport = htons(sk->sk_num);
r->id.idiag_dport = sk->sk_dport;
r->id.idiag_if = sk->sk_bound_dev_if;
sock_diag_save_cookie(sk, r->id.idiag_cookie);

#if IS_ENABLED(CONFIG_IPV6)
if (sk->sk_family == AF_INET6) {
*(struct in6_addr *)r->id.idiag_src = sk->sk_v6_rcv_saddr;
*(struct in6_addr *)r->id.idiag_dst = sk->sk_v6_daddr;
} else
#endif
{
memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));

r->id.idiag_src[0] = sk->sk_rcv_saddr;
r->id.idiag_dst[0] = sk->sk_daddr;
}
}

--
JingPiao Chen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20170614/f28936b4/attachment.html>


More information about the Strace-devel mailing list