Skip to content

Commit

Permalink
inetpeer: Abstract address representation further.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
David S. Miller committed Feb 10, 2011
1 parent b6644cb commit 7a71ed8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
16 changes: 10 additions & 6 deletions include/net/inetpeer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
#include <net/ipv6.h>
#include <asm/atomic.h>

struct inetpeer_addr {
struct inetpeer_addr_base {
union {
__be32 a4;
__be32 a6[4];
__be32 a4;
__be32 a6[4];
};
__u16 family;
};

struct inetpeer_addr {
struct inetpeer_addr_base addr;
__u16 family;
};

struct inet_peer {
Expand Down Expand Up @@ -67,7 +71,7 @@ static inline struct inet_peer *inet_getpeer_v4(__be32 v4daddr, int create)
{
struct inetpeer_addr daddr;

daddr.a4 = v4daddr;
daddr.addr.a4 = v4daddr;
daddr.family = AF_INET;
return inet_getpeer(&daddr, create);
}
Expand All @@ -76,7 +80,7 @@ static inline struct inet_peer *inet_getpeer_v6(struct in6_addr *v6daddr, int cr
{
struct inetpeer_addr daddr;

ipv6_addr_copy((struct in6_addr *)daddr.a6, v6daddr);
ipv6_addr_copy((struct in6_addr *)daddr.addr.a6, v6daddr);
daddr.family = AF_INET6;
return inet_getpeer(&daddr, create);
}
Expand Down
6 changes: 3 additions & 3 deletions net/ipv4/inetpeer.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ static int addr_compare(const struct inetpeer_addr *a,
int i, n = (a->family == AF_INET ? 1 : 4);

for (i = 0; i < n; i++) {
if (a->a6[i] == b->a6[i])
if (a->addr.a6[i] == b->addr.a6[i])
continue;
if (a->a6[i] < b->a6[i])
if (a->addr.a6[i] < b->addr.a6[i])
return -1;
return 1;
}
Expand Down Expand Up @@ -510,7 +510,7 @@ struct inet_peer *inet_getpeer(struct inetpeer_addr *daddr, int create)
p->daddr = *daddr;
atomic_set(&p->refcnt, 1);
atomic_set(&p->rid, 0);
atomic_set(&p->ip_id_count, secure_ip_id(daddr->a4));
atomic_set(&p->ip_id_count, secure_ip_id(daddr->addr.a4));
p->tcp_ts_stamp = 0;
p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
p->rate_tokens = 0;
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/tcp_ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
tcp_death_row.sysctl_tw_recycle &&
(dst = inet_csk_route_req(sk, req)) != NULL &&
(peer = rt_get_peer((struct rtable *)dst)) != NULL &&
peer->daddr.a4 == saddr) {
peer->daddr.addr.a4 == saddr) {
inet_peer_refcheck(peer);
if ((u32)get_seconds() - peer->tcp_ts_stamp < TCP_PAWS_MSL &&
(s32)(peer->tcp_ts - req->ts_recent) >
Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/tcp_ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
tcp_death_row.sysctl_tw_recycle &&
(dst = inet6_csk_route_req(sk, req)) != NULL &&
(peer = rt6_get_peer((struct rt6_info *)dst)) != NULL &&
ipv6_addr_equal((struct in6_addr *)peer->daddr.a6,
ipv6_addr_equal((struct in6_addr *)peer->daddr.addr.a6,
&treq->rmt_addr)) {
inet_peer_refcheck(peer);
if ((u32)get_seconds() - peer->tcp_ts_stamp < TCP_PAWS_MSL &&
Expand Down

0 comments on commit 7a71ed8

Please sign in to comment.