Skip to content

Commit

Permalink
net: Make flowi ports AF dependent.
Browse files Browse the repository at this point in the history
Create two sets of port member accessors, one set prefixed by fl4_*
and the other prefixed by fl6_*

This will let us to create AF optimal flow instances.

It will work because every context in which we access the ports,
we have to be fully aware of which AF the flowi is anyways.

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
davem330 committed Mar 12, 2011
1 parent 08704bc commit 6281dcc
Show file tree
Hide file tree
Showing 28 changed files with 139 additions and 129 deletions.
21 changes: 14 additions & 7 deletions include/net/flow.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,20 @@ struct flowi {
#define fl4_scope flowi_scope

union flowi_uli uli_u;
#define fl_ip_sport uli_u.ports.sport
#define fl_ip_dport uli_u.ports.dport
#define fl_icmp_type uli_u.icmpt.type
#define fl_icmp_code uli_u.icmpt.code
#define fl_ipsec_spi uli_u.spi
#define fl_mh_type uli_u.mht.type
#define fl_gre_key uli_u.gre_key
#define fl4_sport uli_u.ports.sport
#define fl4_dport uli_u.ports.dport
#define fl4_icmp_type uli_u.icmpt.type
#define fl4_icmp_code uli_u.icmpt.code
#define fl4_ipsec_spi uli_u.spi
#define fl4_mh_type uli_u.mht.type
#define fl4_gre_key uli_u.gre_key
#define fl6_sport uli_u.ports.sport
#define fl6_dport uli_u.ports.dport
#define fl6_icmp_type uli_u.icmpt.type
#define fl6_icmp_code uli_u.icmpt.code
#define fl6_ipsec_spi uli_u.spi
#define fl6_mh_type uli_u.mht.type
#define fl6_gre_key uli_u.gre_key
} __attribute__((__aligned__(BITS_PER_LONG/8)));

#define FLOW_DIR_IN 0
Expand Down
43 changes: 23 additions & 20 deletions include/net/route.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ static inline struct rtable *ip_route_output_ports(struct net *net, struct sock
.fl4_src = saddr,
.fl4_tos = tos,
.flowi_proto = proto,
.fl_ip_dport = dport,
.fl_ip_sport = sport,
.fl4_dport = dport,
.fl4_sport = sport,
};
if (sk)
security_sk_classify_flow(sk, &fl);
Expand All @@ -175,7 +175,7 @@ static inline struct rtable *ip_route_output_gre(struct net *net,
.fl4_src = saddr,
.fl4_tos = tos,
.flowi_proto = IPPROTO_GRE,
.fl_gre_key = gre_key,
.fl4_gre_key = gre_key,
};
return ip_route_output_key(net, &fl);
}
Expand Down Expand Up @@ -228,14 +228,16 @@ static inline struct rtable *ip_route_connect(__be32 dst, __be32 src, u32 tos,
__be16 sport, __be16 dport,
struct sock *sk, bool can_sleep)
{
struct flowi fl = { .flowi_oif = oif,
.flowi_mark = sk->sk_mark,
.fl4_dst = dst,
.fl4_src = src,
.fl4_tos = tos,
.flowi_proto = protocol,
.fl_ip_sport = sport,
.fl_ip_dport = dport };
struct flowi fl = {
.flowi_oif = oif,
.flowi_mark = sk->sk_mark,
.fl4_dst = dst,
.fl4_src = src,
.fl4_tos = tos,
.flowi_proto = protocol,
.fl4_sport = sport,
.fl4_dport = dport,
};
struct net *net = sock_net(sk);
struct rtable *rt;

Expand Down Expand Up @@ -264,15 +266,16 @@ static inline struct rtable *ip_route_newports(struct rtable *rt,
__be16 dport, struct sock *sk)
{
if (sport != orig_sport || dport != orig_dport) {
struct flowi fl = { .flowi_oif = rt->rt_oif,
.flowi_mark = rt->rt_mark,
.fl4_dst = rt->rt_key_dst,
.fl4_src = rt->rt_key_src,
.fl4_tos = rt->rt_tos,
.flowi_proto = protocol,
.fl_ip_sport = sport,
.fl_ip_dport = dport };

struct flowi fl = {
.flowi_oif = rt->rt_oif,
.flowi_mark = rt->rt_mark,
.fl4_dst = rt->rt_key_dst,
.fl4_src = rt->rt_key_src,
.fl4_tos = rt->rt_tos,
.flowi_proto = protocol,
.fl4_sport = sport,
.fl4_dport = dport
};
if (inet_sk(sk)->transparent)
fl.flowi_flags |= FLOWI_FLAG_ANYSRC;
if (protocol == IPPROTO_TCP)
Expand Down
18 changes: 9 additions & 9 deletions include/net/xfrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -800,25 +800,25 @@ static inline bool addr_match(const void *token1, const void *token2,
}

static __inline__
__be16 xfrm_flowi_sport(const struct flowi *fl)
__be16 xfrm_flowi_sport(const struct flowi *fl, const union flowi_uli *uli)
{
__be16 port;
switch(fl->flowi_proto) {
case IPPROTO_TCP:
case IPPROTO_UDP:
case IPPROTO_UDPLITE:
case IPPROTO_SCTP:
port = fl->fl_ip_sport;
port = uli->ports.sport;
break;
case IPPROTO_ICMP:
case IPPROTO_ICMPV6:
port = htons(fl->fl_icmp_type);
port = htons(uli->icmpt.type);
break;
case IPPROTO_MH:
port = htons(fl->fl_mh_type);
port = htons(uli->mht.type);
break;
case IPPROTO_GRE:
port = htons(ntohl(fl->fl_gre_key) >> 16);
port = htons(ntohl(uli->gre_key) >> 16);
break;
default:
port = 0; /*XXX*/
Expand All @@ -827,22 +827,22 @@ __be16 xfrm_flowi_sport(const struct flowi *fl)
}

static __inline__
__be16 xfrm_flowi_dport(const struct flowi *fl)
__be16 xfrm_flowi_dport(const struct flowi *fl, const union flowi_uli *uli)
{
__be16 port;
switch(fl->flowi_proto) {
case IPPROTO_TCP:
case IPPROTO_UDP:
case IPPROTO_UDPLITE:
case IPPROTO_SCTP:
port = fl->fl_ip_dport;
port = uli->ports.dport;
break;
case IPPROTO_ICMP:
case IPPROTO_ICMPV6:
port = htons(fl->fl_icmp_code);
port = htons(uli->icmpt.code);
break;
case IPPROTO_GRE:
port = htons(ntohl(fl->fl_gre_key) & 0xffff);
port = htons(ntohl(uli->gre_key) & 0xffff);
break;
default:
port = 0; /*XXX*/
Expand Down
4 changes: 2 additions & 2 deletions net/dccp/ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,8 @@ static struct dst_entry* dccp_v4_route_skb(struct net *net, struct sock *sk,
.fl4_src = ip_hdr(skb)->daddr,
.fl4_tos = RT_CONN_FLAGS(sk),
.flowi_proto = sk->sk_protocol,
.fl_ip_sport = dccp_hdr(skb)->dccph_dport,
.fl_ip_dport = dccp_hdr(skb)->dccph_sport,
.fl4_sport = dccp_hdr(skb)->dccph_dport,
.fl4_dport = dccp_hdr(skb)->dccph_sport,
};

security_skb_classify_flow(skb, &fl);
Expand Down
20 changes: 10 additions & 10 deletions net/dccp/ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
ipv6_addr_copy(&fl.fl6_dst, &np->daddr);
ipv6_addr_copy(&fl.fl6_src, &np->saddr);
fl.flowi_oif = sk->sk_bound_dev_if;
fl.fl_ip_dport = inet->inet_dport;
fl.fl_ip_sport = inet->inet_sport;
fl.fl6_dport = inet->inet_dport;
fl.fl6_sport = inet->inet_sport;
security_sk_classify_flow(sk, &fl);

dst = ip6_dst_lookup_flow(sk, &fl, NULL, false);
Expand Down Expand Up @@ -253,8 +253,8 @@ static int dccp_v6_send_response(struct sock *sk, struct request_sock *req,
ipv6_addr_copy(&fl.fl6_src, &ireq6->loc_addr);
fl.fl6_flowlabel = 0;
fl.flowi_oif = ireq6->iif;
fl.fl_ip_dport = inet_rsk(req)->rmt_port;
fl.fl_ip_sport = inet_rsk(req)->loc_port;
fl.fl6_dport = inet_rsk(req)->rmt_port;
fl.fl6_sport = inet_rsk(req)->loc_port;
security_req_classify_flow(req, &fl);

opt = np->opt;
Expand Down Expand Up @@ -323,8 +323,8 @@ static void dccp_v6_ctl_send_reset(struct sock *sk, struct sk_buff *rxskb)

fl.flowi_proto = IPPROTO_DCCP;
fl.flowi_oif = inet6_iif(rxskb);
fl.fl_ip_dport = dccp_hdr(skb)->dccph_dport;
fl.fl_ip_sport = dccp_hdr(skb)->dccph_sport;
fl.fl6_dport = dccp_hdr(skb)->dccph_dport;
fl.fl6_sport = dccp_hdr(skb)->dccph_sport;
security_skb_classify_flow(rxskb, &fl);

/* sk = NULL, but it is safe for now. RST socket required. */
Expand Down Expand Up @@ -535,8 +535,8 @@ static struct sock *dccp_v6_request_recv_sock(struct sock *sk,
final_p = fl6_update_dst(&fl, opt, &final);
ipv6_addr_copy(&fl.fl6_src, &ireq6->loc_addr);
fl.flowi_oif = sk->sk_bound_dev_if;
fl.fl_ip_dport = inet_rsk(req)->rmt_port;
fl.fl_ip_sport = inet_rsk(req)->loc_port;
fl.fl6_dport = inet_rsk(req)->rmt_port;
fl.fl6_sport = inet_rsk(req)->loc_port;
security_sk_classify_flow(sk, &fl);

dst = ip6_dst_lookup_flow(sk, &fl, final_p, false);
Expand Down Expand Up @@ -957,8 +957,8 @@ static int dccp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
ipv6_addr_copy(&fl.fl6_dst, &np->daddr);
ipv6_addr_copy(&fl.fl6_src, saddr ? saddr : &np->saddr);
fl.flowi_oif = sk->sk_bound_dev_if;
fl.fl_ip_dport = usin->sin6_port;
fl.fl_ip_sport = inet->inet_sport;
fl.fl6_dport = usin->sin6_port;
fl.fl6_sport = inet->inet_sport;
security_sk_classify_flow(sk, &fl);

final_p = fl6_update_dst(&fl, np->opt, &final);
Expand Down
4 changes: 2 additions & 2 deletions net/ipv4/icmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ static struct rtable *icmp_route_lookup(struct net *net, struct sk_buff *skb_in,
.fl4_src = saddr,
.fl4_tos = RT_TOS(tos),
.flowi_proto = IPPROTO_ICMP,
.fl_icmp_type = type,
.fl_icmp_code = code,
.fl4_icmp_type = type,
.fl4_icmp_code = code,
};
struct rtable *rt, *rt2;
int err;
Expand Down
4 changes: 2 additions & 2 deletions net/ipv4/inet_connection_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ struct dst_entry *inet_csk_route_req(struct sock *sk,
.fl4_tos = RT_CONN_FLAGS(sk),
.flowi_proto = sk->sk_protocol,
.flowi_flags = inet_sk_flowi_flags(sk),
.fl_ip_sport = inet_sk(sk)->inet_sport,
.fl_ip_dport = ireq->rmt_port,
.fl4_sport = inet_sk(sk)->inet_sport,
.fl4_dport = ireq->rmt_port,
};
struct net *net = sock_net(sk);

Expand Down
4 changes: 2 additions & 2 deletions net/ipv4/ip_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -1479,8 +1479,8 @@ void ip_send_reply(struct sock *sk, struct sk_buff *skb, struct ip_reply_arg *ar
.fl4_dst = daddr,
.fl4_src = rt->rt_spec_dst,
.fl4_tos = RT_TOS(ip_hdr(skb)->tos),
.fl_ip_sport = tcp_hdr(skb)->dest,
.fl_ip_dport = tcp_hdr(skb)->source,
.fl4_sport = tcp_hdr(skb)->dest,
.fl4_dport = tcp_hdr(skb)->source,
.flowi_proto = sk->sk_protocol,
.flowi_flags = ip_reply_arg_flowi_flags(arg),
};
Expand Down
4 changes: 2 additions & 2 deletions net/ipv4/netfilter/nf_nat_standalone.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static void nat_decode_session(struct sk_buff *skb, struct flowi *fl)
t->dst.protonum == IPPROTO_UDPLITE ||
t->dst.protonum == IPPROTO_DCCP ||
t->dst.protonum == IPPROTO_SCTP)
fl->fl_ip_dport = t->dst.u.tcp.port;
fl->fl4_dport = t->dst.u.tcp.port;
}

statusbit ^= IPS_NAT_MASK;
Expand All @@ -67,7 +67,7 @@ static void nat_decode_session(struct sk_buff *skb, struct flowi *fl)
t->dst.protonum == IPPROTO_UDPLITE ||
t->dst.protonum == IPPROTO_DCCP ||
t->dst.protonum == IPPROTO_SCTP)
fl->fl_ip_sport = t->src.u.tcp.port;
fl->fl4_sport = t->src.u.tcp.port;
}
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions net/ipv4/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ static int raw_probe_proto_opt(struct flowi *fl, struct msghdr *msg)
code = iov->iov_base;

if (type && code) {
if (get_user(fl->fl_icmp_type, type) ||
get_user(fl->fl_icmp_code, code))
if (get_user(fl->fl4_icmp_type, type) ||
get_user(fl->fl4_icmp_code, code))
return -EFAULT;
probed = 1;
}
Expand Down
4 changes: 2 additions & 2 deletions net/ipv4/syncookies.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
.fl4_tos = RT_CONN_FLAGS(sk),
.flowi_proto = IPPROTO_TCP,
.flowi_flags = inet_sk_flowi_flags(sk),
.fl_ip_sport = th->dest,
.fl_ip_dport = th->source,
.fl4_sport = th->dest,
.fl4_dport = th->source,
};
security_req_classify_flow(req, &fl);
rt = ip_route_output_key(sock_net(sk), &fl);
Expand Down
10 changes: 5 additions & 5 deletions net/ipv4/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ static int udp_push_pending_frames(struct sock *sk)
if (!skb)
goto out;

err = udp_send_skb(skb, fl->fl4_dst, fl->fl_ip_dport);
err = udp_send_skb(skb, fl->fl4_dst, fl->fl4_dport);

out:
up->len = 0;
Expand Down Expand Up @@ -917,8 +917,8 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
.flowi_proto = sk->sk_protocol,
.flowi_flags = (inet_sk_flowi_flags(sk) |
FLOWI_FLAG_CAN_SLEEP),
.fl_ip_sport = inet->inet_sport,
.fl_ip_dport = dport,
.fl4_sport = inet->inet_sport,
.fl4_dport = dport,
};
struct net *net = sock_net(sk);

Expand Down Expand Up @@ -973,9 +973,9 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
* Now cork the socket to pend data.
*/
inet->cork.fl.fl4_dst = daddr;
inet->cork.fl.fl_ip_dport = dport;
inet->cork.fl.fl4_dport = dport;
inet->cork.fl.fl4_src = saddr;
inet->cork.fl.fl_ip_sport = inet->inet_sport;
inet->cork.fl.fl4_sport = inet->inet_sport;
up->pending = AF_INET;

do_append_data:
Expand Down
18 changes: 9 additions & 9 deletions net/ipv4/xfrm4_policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,41 +117,41 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
pskb_may_pull(skb, xprth + 4 - skb->data)) {
__be16 *ports = (__be16 *)xprth;

fl->fl_ip_sport = ports[!!reverse];
fl->fl_ip_dport = ports[!reverse];
fl->fl4_sport = ports[!!reverse];
fl->fl4_dport = ports[!reverse];
}
break;

case IPPROTO_ICMP:
if (pskb_may_pull(skb, xprth + 2 - skb->data)) {
u8 *icmp = xprth;

fl->fl_icmp_type = icmp[0];
fl->fl_icmp_code = icmp[1];
fl->fl4_icmp_type = icmp[0];
fl->fl4_icmp_code = icmp[1];
}
break;

case IPPROTO_ESP:
if (pskb_may_pull(skb, xprth + 4 - skb->data)) {
__be32 *ehdr = (__be32 *)xprth;

fl->fl_ipsec_spi = ehdr[0];
fl->fl4_ipsec_spi = ehdr[0];
}
break;

case IPPROTO_AH:
if (pskb_may_pull(skb, xprth + 8 - skb->data)) {
__be32 *ah_hdr = (__be32*)xprth;

fl->fl_ipsec_spi = ah_hdr[1];
fl->fl4_ipsec_spi = ah_hdr[1];
}
break;

case IPPROTO_COMP:
if (pskb_may_pull(skb, xprth + 4 - skb->data)) {
__be16 *ipcomp_hdr = (__be16 *)xprth;

fl->fl_ipsec_spi = htonl(ntohs(ipcomp_hdr[1]));
fl->fl4_ipsec_spi = htonl(ntohs(ipcomp_hdr[1]));
}
break;

Expand All @@ -163,13 +163,13 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
if (greflags[0] & GRE_KEY) {
if (greflags[0] & GRE_CSUM)
gre_hdr++;
fl->fl_gre_key = gre_hdr[1];
fl->fl4_gre_key = gre_hdr[1];
}
}
break;

default:
fl->fl_ipsec_spi = 0;
fl->fl4_ipsec_spi = 0;
break;
}
}
Expand Down
Loading

0 comments on commit 6281dcc

Please sign in to comment.