--- zzzz-none-000/linux-2.6.32.61/net/ipv4/ip_output.c 2013-06-10 09:43:48.000000000 +0000 +++ ar10-7272-687/linux-2.6.32.61/net/ipv4/ip_output.c 2017-04-18 12:50:00.000000000 +0000 @@ -80,6 +80,25 @@ #include #include +#if defined(CONFIG_NF_CONNTRACK) && ( defined(CONFIG_IFX_PPA_API) || defined(CONFIG_IFX_PPA_API_MODULE)) +IFX_int32_t cpu_port_extended_cfg_get( int fd ) { + #include +#endif +#ifdef CONFIG_MAPPING +#include "proto_trans.h" /* for ip_mapping() */ +#endif + +#ifdef CONFIG_LTQ_NETFILTER_PROCFS +int sysctl_netfilter_postrouting_enable = 1; +int sysctl_netfilter_output_enable = 1; +#endif + +#if defined(CONFIG_FUSIV_KERNEL_AP_2_AP) || defined(CONFIG_FUSIV_KERNEL_AP_2_AP_MODULE) +#include +#include +#include +#endif + int sysctl_ip_default_ttl __read_mostly = IPDEFTTL; /* Generate a checksum for an outgoing IP datagram. */ @@ -95,6 +114,11 @@ iph->tot_len = htons(skb->len); ip_send_check(iph); + +#ifdef CONFIG_LTQ_NETFILTER_PROCFS + if (!sysctl_netfilter_output_enable) + return dst_output(skb); +#endif return nf_hook(PF_INET, NF_INET_LOCAL_OUT, skb, NULL, skb_dst(skb)->dev, dst_output); } @@ -200,7 +224,22 @@ kfree_skb(skb); skb = skb2; } - +#if !defined(CONFIG_IFX_PPA_AVM_USAGE) && ( defined(CONFIG_IFX_PPA_API) || defined(CONFIG_IFX_PPA_API_MODULE)) + if ( ppa_hook_session_add_fn != NULL ) + { + struct nf_conn *ct; + + enum ip_conntrack_info ctinfo; + uint32_t flags; + + ct = nf_ct_get(skb, &ctinfo); + + flags = 0; // post routing + flags |= CTINFO2DIR(ctinfo) == IP_CT_DIR_ORIGINAL ? PPA_F_SESSION_ORG_DIR : PPA_F_SESSION_REPLY_DIR; + + ppa_hook_session_add_fn(skb, ct, flags); + } +#endif if (dst->hh) return neigh_hh_output(dst->hh, skb); else if (dst->neighbour) @@ -231,8 +270,14 @@ #endif if (skb->len > ip_skb_dst_mtu(skb) && !skb_is_gso(skb)) return ip_fragment(skb, ip_finish_output2); - else + else { + skb_mark_priority(skb); +#ifdef CONFIG_LTQ_NETFILTER_PROCFS + if (!sysctl_netfilter_postrouting_enable) + return ip_finish_output2(skb); +#endif return ip_finish_output2(skb); + } } int ip_mc_output(struct sk_buff *skb) @@ -268,10 +313,16 @@ #endif ) { struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC); - if (newskb) - NF_HOOK(PF_INET, NF_INET_POST_ROUTING, newskb, + if (newskb) { +#ifdef CONFIG_LTQ_NETFILTER_PROCFS + if (!sysctl_netfilter_postrouting_enable) + ip_dev_loopback_xmit(newskb); + else +#endif + NF_HOOK(PF_INET, NF_INET_POST_ROUTING, newskb, NULL, newskb->dev, ip_dev_loopback_xmit); + } } /* Multicasts with ttl 0 must not go beyond the host */ @@ -284,9 +335,15 @@ if (rt->rt_flags&RTCF_BROADCAST) { struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC); - if (newskb) + if (newskb) { +#ifdef CONFIG_LTQ_NETFILTER_PROCFS + if (!sysctl_netfilter_postrouting_enable) + ip_dev_loopback_xmit(newskb); + else +#endif NF_HOOK(PF_INET, NF_INET_POST_ROUTING, newskb, NULL, newskb->dev, ip_dev_loopback_xmit); + } } return NF_HOOK_COND(PF_INET, NF_INET_POST_ROUTING, skb, NULL, skb->dev, @@ -297,7 +354,16 @@ int ip_output(struct sk_buff *skb) { struct net_device *dev = skb_dst(skb)->dev; - +#ifdef CONFIG_MAPPING + struct rtable *rt; + struct iphdr *myiph; + myiph = (struct iphdr *)ip_hdr(skb); + rt = (struct rtable *)skb_dst(skb); + if (rt->mapping) { /* Packet translation for local output */ + ip_mapping(skb, rt->src_prefix, rt->dst_prefix); + return 0; + } +#endif IP_UPD_PO_STATS(dev_net(dev), IPSTATS_MIB_OUT, skb->len); skb->dev = dev; @@ -390,6 +456,7 @@ skb->priority = sk->sk_priority; skb->mark = sk->sk_mark; + res = ip_local_out(skb); rcu_read_unlock(); return res; @@ -418,6 +485,10 @@ #ifdef CONFIG_NET_SCHED to->tc_index = from->tc_index; #endif +#ifdef CONFIG_AVM_PA + memcpy(&to->avm_pa.pktinfo, &from->avm_pa.pktinfo, + sizeof(from->avm_pa.pktinfo)); +#endif nf_copy(to, from); #if defined(CONFIG_NETFILTER_XT_TARGET_TRACE) || \ defined(CONFIG_NETFILTER_XT_TARGET_TRACE_MODULE) @@ -426,6 +497,21 @@ #if defined(CONFIG_IP_VS) || defined(CONFIG_IP_VS_MODULE) to->ipvs_property = from->ipvs_property; #endif + +#if defined(CONFIG_FUSIV_KERNEL_AP_2_AP) || defined(CONFIG_FUSIV_KERNEL_AP_2_AP_MODULE) + memcpy(&(to->apFlowData),&(from->apFlowData),sizeof(from->apFlowData)); +#else +/* Copy the QOS related information from packet to the corresponding + fragments also */ +#if defined(CONFIG_FUSIV_KERNEL_HOST_IPQOS) || defined(CONFIG_FUSIV_KERNEL_HOST_IPQOS_MODULE) +#if CONFIG_FUSIV_KERNEL_IPQOS_APQOS + memcpy(&(to->apFlowData.qosInfo),&(from->apFlowData.qosInfo),sizeof(from->apFlowData.qosInfo)); +#else + memcpy(&(to->qosInfo),&(from->qosInfo),sizeof(from->qosInfo)); +#endif +#endif +#endif + skb_copy_secmark(to, from); } @@ -729,6 +815,7 @@ } static inline int ip_ufo_append_data(struct sock *sk, + struct sk_buff_head *queue, int getfrag(void *from, char *to, int offset, int len, int odd, struct sk_buff *skb), void *from, int length, int hh_len, int fragheaderlen, @@ -741,7 +828,7 @@ * device, so create one single skb packet containing complete * udp datagram */ - if ((skb = skb_peek_tail(&sk->sk_write_queue)) == NULL) { + if ((skb = skb_peek_tail(queue)) == NULL) { skb = sock_alloc_send_skb(sk, hh_len + fragheaderlen + transhdrlen + 20, (flags & MSG_DONTWAIT), &err); @@ -768,35 +855,24 @@ /* specify the length of each IP datagram fragment */ skb_shinfo(skb)->gso_size = mtu - fragheaderlen; skb_shinfo(skb)->gso_type = SKB_GSO_UDP; - __skb_queue_tail(&sk->sk_write_queue, skb); + __skb_queue_tail(queue, skb); } return skb_append_datato_frags(sk, skb, getfrag, from, (length - transhdrlen)); } -/* - * ip_append_data() and ip_append_page() can make one large IP datagram - * from many pieces of data. Each pieces will be holded on the socket - * until ip_push_pending_frames() is called. Each piece can be a page - * or non-page data. - * - * Not only UDP, other transport protocols - e.g. raw sockets - can use - * this interface potentially. - * - * LATER: length must be adjusted by pad at tail, when it is required. - */ -int ip_append_data(struct sock *sk, - int getfrag(void *from, char *to, int offset, int len, - int odd, struct sk_buff *skb), - void *from, int length, int transhdrlen, - struct ipcm_cookie *ipc, struct rtable **rtp, - unsigned int flags) +static int __ip_append_data(struct sock *sk, struct sk_buff_head *queue, + struct inet_cork *cork, + int getfrag(void *from, char *to, int offset, + int len, int odd, struct sk_buff *skb), + void *from, int length, int transhdrlen, + unsigned int flags) { struct inet_sock *inet = inet_sk(sk); struct sk_buff *skb; - struct ip_options *opt = NULL; + struct ip_options *opt = inet->cork.opt; int hh_len; int exthdrlen; int mtu; @@ -805,59 +881,18 @@ int offset = 0; unsigned int maxfraglen, fragheaderlen; int csummode = CHECKSUM_NONE; - struct rtable *rt; - - if (flags&MSG_PROBE) - return 0; + struct rtable *rt = (struct rtable *)cork->dst; - if (skb_queue_empty(&sk->sk_write_queue)) { - /* - * setup for corking. - */ - opt = ipc->opt ? &ipc->opt->opt : NULL; - if (opt) { - if (inet->cork.opt == NULL) { - inet->cork.opt = kmalloc(sizeof(struct ip_options) + 40, sk->sk_allocation); - if (unlikely(inet->cork.opt == NULL)) - return -ENOBUFS; - } - memcpy(inet->cork.opt, opt, sizeof(struct ip_options)+opt->optlen); - inet->cork.flags |= IPCORK_OPT; - inet->cork.addr = ipc->addr; - } - rt = *rtp; - if (unlikely(!rt)) - return -EFAULT; - /* - * We steal reference to this route, caller should not release it - */ - *rtp = NULL; - inet->cork.fragsize = mtu = inet->pmtudisc == IP_PMTUDISC_PROBE ? - rt->u.dst.dev->mtu : - dst_mtu(rt->u.dst.path); - inet->cork.dst = &rt->u.dst; - inet->cork.length = 0; - sk->sk_sndmsg_page = NULL; - sk->sk_sndmsg_off = 0; - if ((exthdrlen = rt->u.dst.header_len) != 0) { - length += exthdrlen; - transhdrlen += exthdrlen; - } - } else { - rt = (struct rtable *)inet->cork.dst; - if (inet->cork.flags & IPCORK_OPT) - opt = inet->cork.opt; - - transhdrlen = 0; - exthdrlen = 0; - mtu = inet->cork.fragsize; - } + exthdrlen = transhdrlen ? rt->u.dst.header_len : 0; + length += exthdrlen; + transhdrlen += exthdrlen; + mtu = inet->cork.fragsize; hh_len = LL_RESERVED_SPACE(rt->u.dst.dev); fragheaderlen = sizeof(struct iphdr) + (opt ? opt->optlen : 0); maxfraglen = ((mtu - fragheaderlen) & ~7) + fragheaderlen; - if (inet->cork.length + length > 0xFFFF - fragheaderlen) { + if (cork->length + length > 0xFFFF - fragheaderlen) { ip_local_error(sk, EMSGSIZE, rt->rt_dst, inet->dport, mtu-exthdrlen); return -EMSGSIZE; } @@ -872,15 +907,15 @@ !exthdrlen) csummode = CHECKSUM_PARTIAL; - skb = skb_peek_tail(&sk->sk_write_queue); + skb = skb_peek_tail(queue); - inet->cork.length += length; + cork->length += length; if (((length > mtu) || (skb && skb_is_gso(skb))) && (sk->sk_protocol == IPPROTO_UDP) && (rt->u.dst.dev->features & NETIF_F_UFO)) { - err = ip_ufo_append_data(sk, getfrag, from, length, hh_len, - fragheaderlen, transhdrlen, mtu, - flags); + err = ip_ufo_append_data(sk, queue, getfrag, from, length, + hh_len, fragheaderlen, transhdrlen, + mtu, flags); if (err) goto error; return 0; @@ -954,7 +989,7 @@ else /* only the initial fragment is time stamped */ - ipc->shtx.flags = 0; + cork->tx_flags = 0; } if (skb == NULL) goto error; @@ -965,7 +1000,7 @@ skb->ip_summed = csummode; skb->csum = 0; skb_reserve(skb, hh_len); - *skb_tx(skb) = ipc->shtx; + skb_shinfo(skb)->tx_flags = cork->tx_flags; /* * Find where to start putting bytes. @@ -1002,7 +1037,7 @@ /* * Put the packet on the pending queue. */ - __skb_queue_tail(&sk->sk_write_queue, skb); + __skb_queue_tail(queue, skb); continue; } @@ -1022,8 +1057,8 @@ } else { int i = skb_shinfo(skb)->nr_frags; skb_frag_t *frag = &skb_shinfo(skb)->frags[i-1]; - struct page *page = sk->sk_sndmsg_page; - int off = sk->sk_sndmsg_off; + struct page *page = cork->page; + int off = cork->off; unsigned int left; if (page && (left = PAGE_SIZE - off) > 0) { @@ -1035,7 +1070,7 @@ goto error; } get_page(page); - skb_fill_page_desc(skb, i, page, sk->sk_sndmsg_off, 0); + skb_fill_page_desc(skb, i, page, off, 0); frag = &skb_shinfo(skb)->frags[i]; } } else if (i < MAX_SKB_FRAGS) { @@ -1046,8 +1081,8 @@ err = -ENOMEM; goto error; } - sk->sk_sndmsg_page = page; - sk->sk_sndmsg_off = 0; + cork->page = page; + cork->off = 0; skb_fill_page_desc(skb, i, page, 0, 0); frag = &skb_shinfo(skb)->frags[i]; @@ -1059,7 +1094,7 @@ err = -EFAULT; goto error; } - sk->sk_sndmsg_off += copy; + cork->off += copy; frag->size += copy; skb->len += copy; skb->data_len += copy; @@ -1073,11 +1108,88 @@ return 0; error: - inet->cork.length -= length; + cork->length -= length; IP_INC_STATS(sock_net(sk), IPSTATS_MIB_OUTDISCARDS); return err; } +static int ip_setup_cork(struct sock *sk, struct inet_cork *cork, + struct ipcm_cookie *ipc, struct rtable **rtp) +{ + struct inet_sock *inet = inet_sk(sk); + struct ip_options *opt; + struct rtable *rt = *rtp; + + if (unlikely(!rt)) + return -EFAULT; + + /* + * setup for corking. + */ + opt = ipc->opt ? &ipc->opt->opt : NULL; + if (opt) { + if (cork->opt == NULL) { + cork->opt = kmalloc(sizeof(struct ip_options) + 40, + sk->sk_allocation); + if (unlikely(cork->opt == NULL)) + return -ENOBUFS; + } + memcpy(cork->opt, opt, sizeof(struct ip_options) + opt->optlen); + cork->flags |= IPCORK_OPT; + cork->addr = ipc->addr; + } + + /* + * We steal reference to this route, caller should not release it + */ + *rtp = NULL; + cork->fragsize = inet->pmtudisc == IP_PMTUDISC_PROBE ? + rt->u.dst.dev->mtu : dst_mtu(rt->u.dst.path); + cork->dst = &rt->u.dst; + cork->length = 0; + cork->tx_flags = ipc->tx_flags; + cork->page = NULL; + cork->off = 0; + + return 0; +} + +/* + * ip_append_data() and ip_append_page() can make one large IP datagram + * from many pieces of data. Each pieces will be holded on the socket + * until ip_push_pending_frames() is called. Each piece can be a page + * or non-page data. + * + * Not only UDP, other transport protocols - e.g. raw sockets - can use + * this interface potentially. + * + * LATER: length must be adjusted by pad at tail, when it is required. + */ +int ip_append_data(struct sock *sk, + int getfrag(void *from, char *to, int offset, int len, + int odd, struct sk_buff *skb), + void *from, int length, int transhdrlen, + struct ipcm_cookie *ipc, struct rtable **rtp, + unsigned int flags) +{ + struct inet_sock *inet = inet_sk(sk); + int err; + + if (flags&MSG_PROBE) + return 0; + + if (skb_queue_empty(&sk->sk_write_queue)) { + err = ip_setup_cork(sk, &inet->cork, ipc, rtp); + if (err) + return err; + } else { + transhdrlen = 0; + } + + return __ip_append_data(sk, &sk->sk_write_queue, &inet->cork, getfrag, + from, length, transhdrlen, flags); +} + ssize_t ip_append_page(struct sock *sk, struct page *page, int offset, size_t size, int flags) { @@ -1221,40 +1333,41 @@ return err; } -static void ip_cork_release(struct inet_sock *inet) +static void ip_cork_release(struct inet_cork *cork) { - inet->cork.flags &= ~IPCORK_OPT; - kfree(inet->cork.opt); - inet->cork.opt = NULL; - dst_release(inet->cork.dst); - inet->cork.dst = NULL; + cork->flags &= ~IPCORK_OPT; + kfree(cork->opt); + cork->opt = NULL; + dst_release(cork->dst); + cork->dst = NULL; } /* * Combined all pending IP fragments on the socket as one IP datagram * and push them out. */ -int ip_push_pending_frames(struct sock *sk) +struct sk_buff *__ip_make_skb(struct sock *sk, + struct sk_buff_head *queue, + struct inet_cork *cork) { struct sk_buff *skb, *tmp_skb; struct sk_buff **tail_skb; struct inet_sock *inet = inet_sk(sk); struct net *net = sock_net(sk); struct ip_options *opt = NULL; - struct rtable *rt = (struct rtable *)inet->cork.dst; + struct rtable *rt = (struct rtable *)cork->dst; struct iphdr *iph; __be16 df = 0; __u8 ttl; - int err = 0; - if ((skb = __skb_dequeue(&sk->sk_write_queue)) == NULL) + if ((skb = __skb_dequeue(queue)) == NULL) goto out; tail_skb = &(skb_shinfo(skb)->frag_list); /* move skb->data to ip header from ext header */ if (skb->data < skb_network_header(skb)) __skb_pull(skb, skb_network_offset(skb)); - while ((tmp_skb = __skb_dequeue(&sk->sk_write_queue)) != NULL) { + while ((tmp_skb = __skb_dequeue(queue)) != NULL) { __skb_pull(tmp_skb, skb_network_header_len(skb)); *tail_skb = tmp_skb; tail_skb = &(tmp_skb->next); @@ -1280,8 +1393,8 @@ ip_dont_fragment(sk, &rt->u.dst))) df = htons(IP_DF); - if (inet->cork.flags & IPCORK_OPT) - opt = inet->cork.opt; + if (cork->flags & IPCORK_OPT) + opt = cork->opt; if (rt->rt_type == RTN_MULTICAST) ttl = inet->mc_ttl; @@ -1293,7 +1406,7 @@ iph->ihl = 5; if (opt) { iph->ihl += opt->optlen>>2; - ip_options_build(skb, opt, inet->cork.addr, rt, 0); + ip_options_build(skb, opt, cork->addr, rt, 0); } iph->tos = inet->tos; iph->frag_off = df; @@ -1309,44 +1422,95 @@ * Steal rt from cork.dst to avoid a pair of atomic_inc/atomic_dec * on dst refcount */ - inet->cork.dst = NULL; + cork->dst = NULL; skb_dst_set(skb, &rt->u.dst); if (iph->protocol == IPPROTO_ICMP) icmp_out_count(net, ((struct icmphdr *) skb_transport_header(skb))->type); - /* Netfilter gets whole the not fragmented skb. */ + ip_cork_release(cork); +out: + return skb; +} + +int ip_send_skb(struct sk_buff *skb) +{ + struct net *net = sock_net(skb->sk); + int err; + err = ip_local_out(skb); if (err) { if (err > 0) err = net_xmit_errno(err); if (err) - goto error; + IP_INC_STATS(net, IPSTATS_MIB_OUTDISCARDS); } -out: - ip_cork_release(inet); return err; +} -error: - IP_INC_STATS(net, IPSTATS_MIB_OUTDISCARDS); - goto out; +int ip_push_pending_frames(struct sock *sk) +{ + struct sk_buff *skb; + + skb = ip_finish_skb(sk); + if (!skb) + return 0; + + /* Netfilter gets whole the not fragmented skb. */ + return ip_send_skb(skb); } /* * Throw away all pending data on the socket. */ -void ip_flush_pending_frames(struct sock *sk) +static void __ip_flush_pending_frames(struct sock *sk, + struct sk_buff_head *queue, + struct inet_cork *cork) { struct sk_buff *skb; - while ((skb = __skb_dequeue_tail(&sk->sk_write_queue)) != NULL) + while ((skb = __skb_dequeue_tail(queue)) != NULL) kfree_skb(skb); - ip_cork_release(inet_sk(sk)); + ip_cork_release(cork); +} + +void ip_flush_pending_frames(struct sock *sk) +{ + __ip_flush_pending_frames(sk, &sk->sk_write_queue, &inet_sk(sk)->cork); } +struct sk_buff *ip_make_skb(struct sock *sk, + int getfrag(void *from, char *to, int offset, + int len, int odd, struct sk_buff *skb), + void *from, int length, int transhdrlen, + struct ipcm_cookie *ipc, struct rtable **rtp, + unsigned int flags) +{ + struct inet_cork cork = {}; + struct sk_buff_head queue; + int err; + + if (flags & MSG_PROBE) + return NULL; + + __skb_queue_head_init(&queue); + + err = ip_setup_cork(sk, &cork, ipc, rtp); + if (err) + return ERR_PTR(err); + + err = __ip_append_data(sk, &queue, &cork, getfrag, + from, length, transhdrlen, flags); + if (err) { + __ip_flush_pending_frames(sk, &queue, &cork); + return ERR_PTR(err); + } + + return __ip_make_skb(sk, &queue, &cork); +} /* * Fetch data from kernel space and fill in checksum if needed. @@ -1382,7 +1546,7 @@ daddr = ipc.addr = rt->rt_src; ipc.opt = NULL; - ipc.shtx.flags = 0; + ipc.tx_flags = 0; if (replyopts.opt.opt.optlen) { ipc.opt = &replyopts.opt; @@ -1445,6 +1609,248 @@ #endif } +#if defined(CONFIG_FUSIV_KERNEL_AP_2_AP) || defined(CONFIG_FUSIV_KERNEL_AP_2_AP_MODULE) + +void fragmentPacket(struct sk_buff *skb, + struct fragmentInfo *fragInfo) +{ + struct sk_buff *skb2; + struct iphdr *iph = NULL; + struct pppoe_hdr *pppoeHdr = NULL; + unsigned int mtu, hlen = 0, left, len; + unsigned int ll_rs = RESERVED_SPACE_FOR_FRAGMENT; + unsigned int align = 4; /* For aligning IP header to 32-bit boundary */ + int raw = 0; + int offset; + int ptr; + int err = 0; + int macHdrLen = 0; + __be16 not_last_frag; + + if (fragInfo->moduleType == MODULE_TYPE_ADSL) + { + iph = (struct iphdr *)(skb->network_header); + hlen = (((unsigned char *) iph - ((unsigned char *) skb->data)) + + (iph->ihl * 4)); + macHdrLen = hlen - (iph->ihl * 4); + } + else if (fragInfo->moduleType == MODULE_TYPE_WLAN) + { + iph = (struct iphdr *)(skb->data + fragInfo->l2HeaderLen); + hlen = fragInfo->l2HeaderLen + (iph->ihl * 4); + macHdrLen = fragInfo->l2HeaderLen; + } + + mtu = fragInfo->mtuSize - hlen; + + left = skb->len - hlen; /* Space per frame */ + ptr = raw + hlen; /* Where to start from */ + + /* + * Fragment the datagram. + */ + + offset = (ntohs(iph->frag_off) & IP_OFFSET) << 3; + not_last_frag = iph->frag_off & htons(IP_MF); + + /* + * Keep copying data until we run out. + */ + + while (left > 0) + { + len = left; + + /* IF: it doesn't fit, use 'mtu' - the data space left */ + + if (len > mtu) + len = mtu; + + /* IF: we are not sending upto and including the packet end + then align the next start on an eight byte boundary */ + + if (len < left) + { + len &= ~7; + } + + /* + * Allocate buffer. + */ + + if ((skb2 = dev_alloc_skb(len + hlen + ll_rs + align)) == NULL) + { + printk("fragmentPacket: no memory for new fragment!\n"); + goto fail; + } + + /* + * Align IP header on 32-bit boundary as per the source buffer + * alignment. + */ + + skb_reserve(skb2, ((unsigned long) skb->data & 0x3)); + + /* + * Allow skbuff to have some head room, for growing at the front, + * required basically for WLAN protocol to add header + */ + + skb_reserve(skb2, ll_rs); + + /* + * Set up data on packet + */ + + ip_copy_metadata(skb2, skb); + skb_put(skb2, len + hlen); + + if (macHdrLen) + skb2->mac_header = skb2->data; + + skb2->network_header = skb2->data + macHdrLen; + skb2->transport_header = skb2->data + hlen; + + /* + * Charge the memory for the fragment to any owner + * it might possess + */ + + if (skb->sk) + skb_set_owner_w(skb2, skb->sk); + + /* + * Copy the packet header into the new buffer. + */ + + if (macHdrLen) + memcpy(skb2->mac_header, skb->data, macHdrLen); + + memcpy(skb2->network_header, skb->data + macHdrLen, hlen - macHdrLen); + + /* + * Copy a block of the IP datagram. + */ + + memcpy(skb2->transport_header, skb->data + ptr, len); + + memcpy(skb2->cb, skb->cb, sizeof(skb->cb)); + + left -= len; + + /* If PPPoE packet, update the total length in PPPoE Header */ + + if ((fragInfo->pktType & (1 << PKT_TYPE_PPPOE)) && + (fragInfo->pktType & (1 << PKT_TYPE_VLAN))) + { + pppoeHdr = (struct pppoe_hdr *) ((unsigned char *) skb2->data + + sizeof(struct ethhdr) + + sizeof(struct vlan_hdr)); + } + else if (fragInfo->pktType & (1 << PKT_TYPE_PPPOE)) + { + pppoeHdr = (struct pppoe_hdr *) ((unsigned char *) skb2->data + + sizeof(struct ethhdr)); + } + + if (pppoeHdr) + pppoeHdr->length = len + hlen - sizeof(struct ethhdr) + - sizeof(struct pppoe_hdr); + + /* + * Fill in the new header fields. + */ + + iph = (struct iphdr *)(skb2->network_header); + iph->frag_off = htons((offset >> 3)); + + /* ANK: dirty, but effective trick. Upgrade options only if + * the segment to be fragmented was THE FIRST (otherwise, + * options are already fixed) and make it ONCE + * on the initial skb, so that all the following fragments + * will inherit fixed options. + */ + +#if 0 // Commented out assuming that there will be no ip options in the pkt + if (offset == 0) + ip_options_fragment(skb); +#endif + + /* + * Added AC : If we are fragmenting a fragment that's not the + * last fragment then keep MF on each bit + */ + + if (left > 0 || not_last_frag) + iph->frag_off |= htons(IP_MF); + + ptr += len; + offset += len; + + /* + * Put this fragment into the sending queue. + */ + + iph->tot_len = htons(len + (iph->ihl * 4)); + + ip_send_check(iph); + + err = (fragInfo->fragment_xmit_ptr)(skb2, skb2->dev); + + if (err) + goto fail; + + IP_INC_STATS(sock_net(skb->sk), IPSTATS_MIB_FRAGCREATES); + } + + kfree_skb(skb); + IP_INC_STATS(sock_net(skb->sk), IPSTATS_MIB_FRAGOKS); + + return; + +fail: + kfree_skb(skb); + IP_INC_STATS(sock_net(skb->sk), IPSTATS_MIB_FRAGFAILS); + + return; +} + +void checkIfFragmentNeeded(struct sk_buff *skb, + struct fragmentInfo *fragInfo) +{ + unsigned short ipLen; + + ipLen = fragInfo->totalLength - fragInfo->l2HeaderLen; + + if ((fragInfo->mtuSize) && (ipLen > fragInfo->mtuSize)) + { + struct iphdr *ipHdr; + + ipHdr = (struct iphdr *)(skb->data + fragInfo->l2HeaderLen); + + if (ipHdr->frag_off & htons(IP_DF)) + kfree_skb(skb); + else + return fragmentPacket(skb, fragInfo); + } + else + { + (fragInfo->fragment_xmit_ptr)(skb, skb->dev); + + return; + } +} + +EXPORT_SYMBOL(fragmentPacket); +EXPORT_SYMBOL(checkIfFragmentNeeded); + +#endif EXPORT_SYMBOL(ip_generic_getfrag); EXPORT_SYMBOL(ip_queue_xmit); EXPORT_SYMBOL(ip_send_check); + +#if defined(CONFIG_IFX_PPA_API_MODULE) +EXPORT_SYMBOL(ip_mc_output); +EXPORT_SYMBOL(ip_forward); +EXPORT_SYMBOL(ip_local_deliver); +#endif