Skip to content

Commit 7a71ed8

Browse files
committed
inetpeer: Abstract address representation further.
Future changes will add caching information, and some of these new elements will be addresses. Since the family is implicit via the ->daddr.family member, replicating the family in ever address we store is entirely redundant. Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b6644cb commit 7a71ed8

4 files changed

Lines changed: 15 additions & 11 deletions

File tree

‎include/net/inetpeer.h‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@
1515
#include <net/ipv6.h>
1616
#include <asm/atomic.h>
1717

18-
struct inetpeer_addr {
18+
struct inetpeer_addr_base {
1919
union {
20-
__be32 a4;
21-
__be32 a6[4];
20+
__be32 a4;
21+
__be32 a6[4];
2222
};
23-
__u16 family;
23+
};
24+
25+
struct inetpeer_addr {
26+
struct inetpeer_addr_base addr;
27+
__u16 family;
2428
};
2529

2630
struct inet_peer {
@@ -67,7 +71,7 @@ static inline struct inet_peer *inet_getpeer_v4(__be32 v4daddr, int create)
6771
{
6872
struct inetpeer_addr daddr;
6973

70-
daddr.a4 = v4daddr;
74+
daddr.addr.a4 = v4daddr;
7175
daddr.family = AF_INET;
7276
return inet_getpeer(&daddr, create);
7377
}
@@ -76,7 +80,7 @@ static inline struct inet_peer *inet_getpeer_v6(struct in6_addr *v6daddr, int cr
7680
{
7781
struct inetpeer_addr daddr;
7882

79-
ipv6_addr_copy((struct in6_addr *)daddr.a6, v6daddr);
83+
ipv6_addr_copy((struct in6_addr *)daddr.addr.a6, v6daddr);
8084
daddr.family = AF_INET6;
8185
return inet_getpeer(&daddr, create);
8286
}

‎net/ipv4/inetpeer.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ static int addr_compare(const struct inetpeer_addr *a,
167167
int i, n = (a->family == AF_INET ? 1 : 4);
168168

169169
for (i = 0; i < n; i++) {
170-
if (a->a6[i] == b->a6[i])
170+
if (a->addr.a6[i] == b->addr.a6[i])
171171
continue;
172-
if (a->a6[i] < b->a6[i])
172+
if (a->addr.a6[i] < b->addr.a6[i])
173173
return -1;
174174
return 1;
175175
}
@@ -510,7 +510,7 @@ struct inet_peer *inet_getpeer(struct inetpeer_addr *daddr, int create)
510510
p->daddr = *daddr;
511511
atomic_set(&p->refcnt, 1);
512512
atomic_set(&p->rid, 0);
513-
atomic_set(&p->ip_id_count, secure_ip_id(daddr->a4));
513+
atomic_set(&p->ip_id_count, secure_ip_id(daddr->addr.a4));
514514
p->tcp_ts_stamp = 0;
515515
p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
516516
p->rate_tokens = 0;

‎net/ipv4/tcp_ipv4.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
13411341
tcp_death_row.sysctl_tw_recycle &&
13421342
(dst = inet_csk_route_req(sk, req)) != NULL &&
13431343
(peer = rt_get_peer((struct rtable *)dst)) != NULL &&
1344-
peer->daddr.a4 == saddr) {
1344+
peer->daddr.addr.a4 == saddr) {
13451345
inet_peer_refcheck(peer);
13461346
if ((u32)get_seconds() - peer->tcp_ts_stamp < TCP_PAWS_MSL &&
13471347
(s32)(peer->tcp_ts - req->ts_recent) >

‎net/ipv6/tcp_ipv6.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
13231323
tcp_death_row.sysctl_tw_recycle &&
13241324
(dst = inet6_csk_route_req(sk, req)) != NULL &&
13251325
(peer = rt6_get_peer((struct rt6_info *)dst)) != NULL &&
1326-
ipv6_addr_equal((struct in6_addr *)peer->daddr.a6,
1326+
ipv6_addr_equal((struct in6_addr *)peer->daddr.addr.a6,
13271327
&treq->rmt_addr)) {
13281328
inet_peer_refcheck(peer);
13291329
if ((u32)get_seconds() - peer->tcp_ts_stamp < TCP_PAWS_MSL &&

0 commit comments

Comments
 (0)