Skip to content

Commit

Permalink
[IPV6]: Allow to replace skbuff by TLV parser.
Browse files Browse the repository at this point in the history
In receiving Mobile IPv6 home address option which is a TLV carried by
destination options header, kernel will try to mangle source adderss
of packet. Think of cloned skbuff it is required to replace it by the
parser just like routing header case.

This is a framework to achieve that to allow TLV parser to replace
inbound skbuff pointer.

Signed-off-by: Masahide NAKAMURA <nakam@linux-ipv6.org>
Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Masahide NAKAMURA authored and David S. Miller committed Sep 22, 2006
1 parent c61a404 commit a80ff03
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion include/net/ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ extern int ip6_ra_control(struct sock *sk, int sel,
void (*destructor)(struct sock *));


extern int ipv6_parse_hopopts(struct sk_buff *skb);
extern int ipv6_parse_hopopts(struct sk_buff **skbp);

extern struct ipv6_txoptions * ipv6_dup_options(struct sock *sk, struct ipv6_txoptions *opt);
extern struct ipv6_txoptions * ipv6_renew_options(struct sock *sk, struct ipv6_txoptions *opt,
Expand Down
29 changes: 19 additions & 10 deletions net/ipv6/exthdrs.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ int ipv6_find_tlv(struct sk_buff *skb, int offset, int type)

struct tlvtype_proc {
int type;
int (*func)(struct sk_buff *skb, int offset);
int (*func)(struct sk_buff **skbp, int offset);
};

/*********************
Expand All @@ -111,8 +111,10 @@ struct tlvtype_proc {

/* An unknown option is detected, decide what to do */

static int ip6_tlvopt_unknown(struct sk_buff *skb, int optoff)
static int ip6_tlvopt_unknown(struct sk_buff **skbp, int optoff)
{
struct sk_buff *skb = *skbp;

switch ((skb->nh.raw[optoff] & 0xC0) >> 6) {
case 0: /* ignore */
return 1;
Expand All @@ -137,8 +139,9 @@ static int ip6_tlvopt_unknown(struct sk_buff *skb, int optoff)

/* Parse tlv encoded option header (hop-by-hop or destination) */

static int ip6_parse_tlv(struct tlvtype_proc *procs, struct sk_buff *skb)
static int ip6_parse_tlv(struct tlvtype_proc *procs, struct sk_buff **skbp)
{
struct sk_buff *skb = *skbp;
struct tlvtype_proc *curr;
int off = skb->h.raw - skb->nh.raw;
int len = ((skb->h.raw[1]+1)<<3);
Expand Down Expand Up @@ -168,13 +171,13 @@ static int ip6_parse_tlv(struct tlvtype_proc *procs, struct sk_buff *skb)
/* type specific length/alignment
checks will be performed in the
func(). */
if (curr->func(skb, off) == 0)
if (curr->func(skbp, off) == 0)
return 0;
break;
}
}
if (curr->type < 0) {
if (ip6_tlvopt_unknown(skb, off) == 0)
if (ip6_tlvopt_unknown(skbp, off) == 0)
return 0;
}
break;
Expand Down Expand Up @@ -213,7 +216,8 @@ static int ipv6_destopt_rcv(struct sk_buff **skbp)
opt->lastopt = skb->h.raw - skb->nh.raw;
opt->dst1 = skb->h.raw - skb->nh.raw;

if (ip6_parse_tlv(tlvprocdestopt_lst, skb)) {
if (ip6_parse_tlv(tlvprocdestopt_lst, skbp)) {
skb = *skbp;
skb->h.raw += ((skb->h.raw[1]+1)<<3);
opt->nhoff = opt->dst1;
return 1;
Expand Down Expand Up @@ -517,8 +521,10 @@ EXPORT_SYMBOL_GPL(ipv6_invert_rthdr);

/* Router Alert as of RFC 2711 */

static int ipv6_hop_ra(struct sk_buff *skb, int optoff)
static int ipv6_hop_ra(struct sk_buff **skbp, int optoff)
{
struct sk_buff *skb = *skbp;

if (skb->nh.raw[optoff+1] == 2) {
IP6CB(skb)->ra = optoff;
return 1;
Expand All @@ -531,8 +537,9 @@ static int ipv6_hop_ra(struct sk_buff *skb, int optoff)

/* Jumbo payload */

static int ipv6_hop_jumbo(struct sk_buff *skb, int optoff)
static int ipv6_hop_jumbo(struct sk_buff **skbp, int optoff)
{
struct sk_buff *skb = *skbp;
u32 pkt_len;

if (skb->nh.raw[optoff+1] != 4 || (optoff&3) != 2) {
Expand Down Expand Up @@ -581,8 +588,9 @@ static struct tlvtype_proc tlvprochopopt_lst[] = {
{ -1, }
};

int ipv6_parse_hopopts(struct sk_buff *skb)
int ipv6_parse_hopopts(struct sk_buff **skbp)
{
struct sk_buff *skb = *skbp;
struct inet6_skb_parm *opt = IP6CB(skb);

/*
Expand All @@ -598,7 +606,8 @@ int ipv6_parse_hopopts(struct sk_buff *skb)
}

opt->hop = sizeof(struct ipv6hdr);
if (ip6_parse_tlv(tlvprochopopt_lst, skb)) {
if (ip6_parse_tlv(tlvprochopopt_lst, skbp)) {
skb = *skbp;
skb->h.raw += (skb->h.raw[1]+1)<<3;
opt->nhoff = sizeof(struct ipv6hdr);
return 1;
Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/ip6_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
}

if (hdr->nexthdr == NEXTHDR_HOP) {
if (ipv6_parse_hopopts(skb) < 0) {
if (ipv6_parse_hopopts(&skb) < 0) {
IP6_INC_STATS_BH(IPSTATS_MIB_INHDRERRORS);
return 0;
}
Expand Down

0 comments on commit a80ff03

Please sign in to comment.