tipc: refactor function tipc_sk_anc_data_recv()

We refactor tipc_sk_anc_data_recv() to make it slightly more
comprehensible, but also to facilitate application of some additions
to the code in a future commit.

Reviewed-by: Xin Long <lucien.xin@gmail.com>
Tested-by: Hoang Le <hoang.h.le@dektech.com.au>
Signed-off-by: Jon Maloy <jmaloy@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Jon Maloy 2021-06-02 13:44:25 -04:00 committed by David S. Miller
parent 14623e005a
commit 62633c2f17
1 changed files with 38 additions and 47 deletions

View File

@ -1733,67 +1733,58 @@ static void tipc_sk_set_orig_addr(struct msghdr *m, struct sk_buff *skb)
static int tipc_sk_anc_data_recv(struct msghdr *m, struct sk_buff *skb, static int tipc_sk_anc_data_recv(struct msghdr *m, struct sk_buff *skb,
struct tipc_sock *tsk) struct tipc_sock *tsk)
{ {
struct tipc_msg *msg; struct tipc_msg *hdr;
u32 anc_data[3]; u32 data[3] = {0,};
u32 err; bool has_addr;
u32 dest_type; int dlen, rc;
int has_name;
int res;
if (likely(m->msg_controllen == 0)) if (likely(m->msg_controllen == 0))
return 0; return 0;
msg = buf_msg(skb);
/* Optionally capture errored message object(s) */ hdr = buf_msg(skb);
err = msg ? msg_errcode(msg) : 0; dlen = msg_data_sz(hdr);
if (unlikely(err)) {
anc_data[0] = err; /* Capture errored message object, if any */
anc_data[1] = msg_data_sz(msg); if (msg_errcode(hdr)) {
res = put_cmsg(m, SOL_TIPC, TIPC_ERRINFO, 8, anc_data); if (skb_linearize(skb))
if (res) return -ENOMEM;
return res; hdr = buf_msg(skb);
if (anc_data[1]) { data[0] = msg_errcode(hdr);
if (skb_linearize(skb)) data[1] = dlen;
return -ENOMEM; rc = put_cmsg(m, SOL_TIPC, TIPC_ERRINFO, 8, data);
msg = buf_msg(skb); if (rc || !dlen)
res = put_cmsg(m, SOL_TIPC, TIPC_RETDATA, anc_data[1], return rc;
msg_data(msg)); rc = put_cmsg(m, SOL_TIPC, TIPC_RETDATA, dlen, msg_data(hdr));
if (res) if (rc)
return res; return rc;
}
} }
/* Optionally capture message destination object */ /* Capture TIPC_SERVICE_ADDR/RANGE destination address, if any */
dest_type = msg ? msg_type(msg) : TIPC_DIRECT_MSG; switch (msg_type(hdr)) {
switch (dest_type) {
case TIPC_NAMED_MSG: case TIPC_NAMED_MSG:
has_name = 1; has_addr = true;
anc_data[0] = msg_nametype(msg); data[0] = msg_nametype(hdr);
anc_data[1] = msg_namelower(msg); data[1] = msg_namelower(hdr);
anc_data[2] = msg_namelower(msg); data[2] = data[1];
break; break;
case TIPC_MCAST_MSG: case TIPC_MCAST_MSG:
has_name = 1; has_addr = true;
anc_data[0] = msg_nametype(msg); data[0] = msg_nametype(hdr);
anc_data[1] = msg_namelower(msg); data[1] = msg_namelower(hdr);
anc_data[2] = msg_nameupper(msg); data[2] = msg_nameupper(hdr);
break; break;
case TIPC_CONN_MSG: case TIPC_CONN_MSG:
has_name = !!tsk->conn_addrtype; has_addr = !!tsk->conn_addrtype;
anc_data[0] = msg_nametype(&tsk->phdr); data[0] = msg_nametype(&tsk->phdr);
anc_data[1] = msg_nameinst(&tsk->phdr); data[1] = msg_nameinst(&tsk->phdr);
anc_data[2] = anc_data[1]; data[2] = data[1];
break; break;
default: default:
has_name = 0; has_addr = false;
} }
if (has_name) { if (!has_addr)
res = put_cmsg(m, SOL_TIPC, TIPC_DESTNAME, 12, anc_data); return 0;
if (res) return put_cmsg(m, SOL_TIPC, TIPC_DESTNAME, 12, data);
return res;
}
return 0;
} }
static struct sk_buff *tipc_sk_build_ack(struct tipc_sock *tsk) static struct sk_buff *tipc_sk_build_ack(struct tipc_sock *tsk)