Commit 0b8cf496 authored by David S. Miller's avatar David S. Miller

Merge nuts.davemloft.net:/disk1/BK/xfrm-icmp-2.6

into nuts.davemloft.net:/disk1/BK/net-2.6
parents af597aa6 1f68baf8
......@@ -421,13 +421,51 @@ static __inline__ int addr_match(void *token1, void *token2, int prefixlen)
return 1;
}
static __inline__
u16 xfrm_flowi_sport(struct flowi *fl)
{
u16 port;
switch(fl->proto) {
case IPPROTO_TCP:
case IPPROTO_UDP:
port = fl->fl_ip_sport;
break;
case IPPROTO_ICMP:
case IPPROTO_ICMPV6:
port = htons(fl->fl_icmp_type);
break;
default:
port = 0; /*XXX*/
}
return port;
}
static __inline__
u16 xfrm_flowi_dport(struct flowi *fl)
{
u16 port;
switch(fl->proto) {
case IPPROTO_TCP:
case IPPROTO_UDP:
port = fl->fl_ip_dport;
break;
case IPPROTO_ICMP:
case IPPROTO_ICMPV6:
port = htons(fl->fl_icmp_code);
break;
default:
port = 0; /*XXX*/
}
return port;
}
static inline int
__xfrm4_selector_match(struct xfrm_selector *sel, struct flowi *fl)
{
return addr_match(&fl->fl4_dst, &sel->daddr, sel->prefixlen_d) &&
addr_match(&fl->fl4_src, &sel->saddr, sel->prefixlen_s) &&
!((fl->fl_ip_dport^sel->dport)&sel->dport_mask) &&
!((fl->fl_ip_sport^sel->sport)&sel->sport_mask) &&
!((xfrm_flowi_dport(fl) ^ sel->dport) & sel->dport_mask) &&
!((xfrm_flowi_sport(fl) ^ sel->sport) & sel->sport_mask) &&
(fl->proto == sel->proto || !sel->proto) &&
(fl->oif == sel->ifindex || !sel->ifindex);
}
......@@ -437,8 +475,8 @@ __xfrm6_selector_match(struct xfrm_selector *sel, struct flowi *fl)
{
return addr_match(&fl->fl6_dst, &sel->daddr, sel->prefixlen_d) &&
addr_match(&fl->fl6_src, &sel->saddr, sel->prefixlen_s) &&
!((fl->fl_ip_dport^sel->dport)&sel->dport_mask) &&
!((fl->fl_ip_sport^sel->sport)&sel->sport_mask) &&
!((xfrm_flowi_dport(fl) ^ sel->dport) & sel->dport_mask) &&
!((xfrm_flowi_sport(fl) ^ sel->sport) & sel->sport_mask) &&
(fl->proto == sel->proto || !sel->proto) &&
(fl->oif == sel->ifindex || !sel->ifindex);
}
......
......@@ -323,6 +323,51 @@ static int raw_send_hdrinc(struct sock *sk, void *from, int length,
return err;
}
static void raw_probe_proto_opt(struct flowi *fl, struct msghdr *msg)
{
struct iovec *iov;
u8 *type = NULL;
u8 *code = NULL;
int probed = 0;
int i;
if (!msg->msg_iov)
return;
for (i = 0; i < msg->msg_iovlen; i++) {
iov = &msg->msg_iov[i];
if (!iov)
continue;
switch (fl->proto) {
case IPPROTO_ICMP:
/* check if one-byte field is readable or not. */
if (iov->iov_base && iov->iov_len < 1)
break;
if (!type) {
type = iov->iov_base;
/* check if code field is readable or not. */
if (iov->iov_len > 1)
code = type + 1;
} else if (!code)
code = iov->iov_base;
if (type && code) {
fl->fl_icmp_type = *type;
fl->fl_icmp_code = *code;
probed = 1;
}
break;
default:
probed = 1;
break;
}
if (probed)
break;
}
}
static int raw_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
size_t len)
{
......@@ -429,6 +474,9 @@ static int raw_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
.proto = inet->hdrincl ? IPPROTO_RAW :
sk->sk_protocol,
};
if (!inet->hdrincl)
raw_probe_proto_opt(&fl, msg);
err = ip_route_output_flow(&rt, &fl, sk, !(msg->msg_flags&MSG_DONTWAIT));
}
if (err)
......
......@@ -183,6 +183,15 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl)
}
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];
}
break;
case IPPROTO_ESP:
if (pskb_may_pull(skb, xprth + 4 - skb->data)) {
u32 *ehdr = (u32 *)xprth;
......
......@@ -555,6 +555,52 @@ static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
return err;
}
static void rawv6_probe_proto_opt(struct flowi *fl, struct msghdr *msg)
{
struct iovec *iov;
u8 *type = NULL;
u8 *code = NULL;
int probed = 0;
int i;
if (!msg->msg_iov)
return;
for (i = 0; i < msg->msg_iovlen; i++) {
iov = &msg->msg_iov[i];
if (!iov)
continue;
switch (fl->proto) {
case IPPROTO_ICMPV6:
/* check if one-byte field is readable or not. */
if (iov->iov_base && iov->iov_len < 1)
break;
if (!type) {
type = iov->iov_base;
/* check if code field is readable or not. */
if (iov->iov_len > 1)
code = type + 1;
} else if (!code)
code = iov->iov_base;
if (type && code) {
fl->fl_icmp_type = *type;
fl->fl_icmp_code = *code;
probed = 1;
}
break;
default:
probed = 1;
break;
}
if (probed)
break;
}
}
static int rawv6_sendmsg(struct kiocb *iocb, struct sock *sk,
struct msghdr *msg, size_t len)
{
......@@ -674,6 +720,8 @@ static int rawv6_sendmsg(struct kiocb *iocb, struct sock *sk,
opt = fl6_merge_options(&opt_space, flowlabel, opt);
fl.proto = proto;
rawv6_probe_proto_opt(&fl, msg);
ipv6_addr_copy(&fl.fl6_dst, daddr);
if (ipv6_addr_any(&fl.fl6_src) && !ipv6_addr_any(&np->saddr))
ipv6_addr_copy(&fl.fl6_src, &np->saddr);
......
......@@ -213,6 +213,16 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl)
fl->proto = nexthdr;
return;
case IPPROTO_ICMPV6:
if (pskb_may_pull(skb, skb->nh.raw + offset + 2 - skb->data)) {
u8 *icmp = (u8 *)exthdr;
fl->fl_icmp_type = icmp[0];
fl->fl_icmp_code = icmp[1];
}
fl->proto = nexthdr;
return;
/* XXX Why are there these headers? */
case IPPROTO_AH:
case IPPROTO_ESP:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment