Skip to content

Commit d23deaa

Browse files
xemuldavem330
authored andcommitted
inet_diag: Introduce socket family checks
The new API will specify family to work with. Teach the existing socket walking code to bypass not interesting ones. To preserve compatibility with existing behavior the _compat code sets interesting family to AF_UNSPEC to dump them all. Signed-off-by: Pavel Emelyanov <xemul@parallels.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 25c4cd2 commit d23deaa

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎net/ipv4/inet_diag.c‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,10 @@ static int __inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
743743
continue;
744744
}
745745

746+
if (r->sdiag_family != AF_UNSPEC &&
747+
sk->sk_family != r->sdiag_family)
748+
goto next_listen;
749+
746750
if (r->id.idiag_sport != inet->inet_sport &&
747751
r->id.idiag_sport)
748752
goto next_listen;
@@ -808,6 +812,9 @@ static int __inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
808812
goto next_normal;
809813
if (!(r->idiag_states & (1 << sk->sk_state)))
810814
goto next_normal;
815+
if (r->sdiag_family != AF_UNSPEC &&
816+
sk->sk_family != r->sdiag_family)
817+
goto next_normal;
811818
if (r->id.idiag_sport != inet->inet_sport &&
812819
r->id.idiag_sport)
813820
goto next_normal;
@@ -830,6 +837,9 @@ static int __inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
830837

831838
if (num < s_num)
832839
goto next_dying;
840+
if (r->sdiag_family != AF_UNSPEC &&
841+
tw->tw_family != r->sdiag_family)
842+
goto next_dying;
833843
if (r->id.idiag_sport != tw->tw_sport &&
834844
r->id.idiag_sport)
835845
goto next_dying;
@@ -873,7 +883,7 @@ static int inet_diag_dump_compat(struct sk_buff *skb, struct netlink_callback *c
873883
struct nlattr *bc = NULL;
874884
int hdrlen = sizeof(struct inet_diag_req_compat);
875885

876-
req.sdiag_family = rc->idiag_family;
886+
req.sdiag_family = AF_UNSPEC; /* compatibility */
877887
req.sdiag_protocol = inet_diag_type2proto(cb->nlh->nlmsg_type);
878888
req.idiag_ext = rc->idiag_ext;
879889
req.idiag_states = rc->idiag_states;

0 commit comments

Comments
 (0)