--- zzzz-none-000/linux-3.10.107/net/ipv4/ip_output.c 2017-06-27 09:49:32.000000000 +0000 +++ vr9-7490-729/linux-3.10.107/net/ipv4/ip_output.c 2021-11-10 11:53:56.000000000 +0000 @@ -42,6 +42,12 @@ * Hirokazu Takahashi: sendfile() on UDP works now. */ +/** + * Some part of this file is modified by Ikanos Communications. + * + * Copyright (C) 2013-2014 Ikanos Communications. + */ + #include #include #include @@ -80,6 +86,24 @@ #include #include +#ifdef CONFIG_AVM_PA +#include +#endif + +// AVM/TKL: MERGE fixed relative include paths +#if defined(CONFIG_FUSIV_KERNEL_AP_2_AP) || defined(CONFIG_FUSIV_KERNEL_AP_2_AP_MODULE) +#include +#include +#include +#include +#include +#include +#if defined(CONFIG_IPSEC_AP_SUPPORT) +#include +#include +#endif +#endif + int sysctl_ip_default_ttl __read_mostly = IPDEFTTL; EXPORT_SYMBOL(sysctl_ip_default_ttl); @@ -224,6 +248,12 @@ static int ip_finish_output(struct sk_buff *skb) { + struct rtable *rt = skb_rtable(skb); + struct net_device *dev = rt->dst.dev; + +#if IS_ENABLED(CONFIG_IPSEC_AP_SUPPORT) + unsigned int ivlen=0,padlen=0,encap_len=0; +#endif #if defined(CONFIG_NETFILTER) && defined(CONFIG_XFRM) /* Policy lookup after SNAT yielded a new policy */ if (skb_dst(skb)->xfrm != NULL) { @@ -231,8 +261,34 @@ return dst_output(skb); } #endif - if (skb->len > ip_skb_dst_mtu(skb) && !skb_is_gso(skb)) +#if IS_ENABLED(CONFIG_IPSEC_AP_SUPPORT) + if (skb->apFlowData.encap_protocol == PROCESS_ESP_ENCAP) + { + apSa_t * pApSa = (apSa_t *) skb->apFlowData.pSA; + + ivlen = pApSa->cryptoOperation.ucIvLength; + + if(pApSa->cryptoOperation.eSecapOp == SECAP_ESP_TRANSPORT_OUTGOING_FLOW) + padlen = (skb->len+ESP_PADLEN_PROTO_FLDS_SIZE - IPV4_HDR_LEN)%ivlen; //if IP options are enabled?? + else + padlen = (skb->len+ESP_PADLEN_PROTO_FLDS_SIZE)%ivlen; + + if (padlen) + padlen = ivlen - padlen; + + encap_len = pApSa->uctunHdrLen + ESP_PADLEN_PROTO_FLDS_SIZE; + + encap_len += padlen+pApSa->cryptoOperation.ucIcvTruncLength; + } +#endif +#if IS_ENABLED(CONFIG_IPSEC_AP_SUPPORT) + if ((skb->len + encap_len) > ip_skb_dst_mtu(skb) && !skb_is_gso(skb) && !(dev->features & NETIF_F_DF_RFC2473)) +#else + if (skb->len > ip_skb_dst_mtu(skb) && !skb_is_gso(skb) && !(dev->features & NETIF_F_DF_RFC2473)) +#endif + { return ip_fragment(skb, ip_finish_output2); + } else return ip_finish_output2(skb); } @@ -431,6 +487,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 IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE) to->nf_trace = from->nf_trace; @@ -438,6 +498,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); } @@ -459,6 +534,9 @@ __be16 not_last_frag; struct rtable *rt = skb_rtable(skb); int err = 0; +#if IS_ENABLED(CONFIG_IPSEC_AP_SUPPORT) + unsigned int ivlen=0,padlen=0,encap_len=0; +#endif dev = rt->dst.dev; @@ -488,6 +566,23 @@ if (skb->nf_bridge) mtu -= nf_bridge_mtu_reduction(skb); #endif +#if IS_ENABLED(CONFIG_IPSEC_AP_SUPPORT) + if (skb->apFlowData.encap_protocol == PROCESS_ESP_ENCAP) + { + apSa_t * pApSa = (apSa_t *) skb->apFlowData.pSA; + ivlen = pApSa->cryptoOperation.ucIvLength; + if(pApSa->cryptoOperation.eSecapOp == SECAP_ESP_TRANSPORT_OUTGOING_FLOW) + padlen = (skb->len+ESP_PADLEN_PROTO_FLDS_SIZE - IPV4_HDR_LEN)%ivlen; //if IP options are enabled?? + else + padlen = (skb->len+ESP_PADLEN_PROTO_FLDS_SIZE)%ivlen; + if (padlen) + padlen = ivlen - padlen; + + encap_len = pApSa->uctunHdrLen + ESP_PADLEN_PROTO_FLDS_SIZE ; + encap_len += padlen + pApSa->cryptoOperation.ucIcvTruncLength; + } + mtu -= encap_len; +#endif IPCB(skb)->flags |= IPSKB_FRAG_COMPLETE; /* When frag_list is given, use it. First, check its validity: @@ -552,6 +647,13 @@ ip_copy_metadata(frag, skb); if (offset == 0) ip_options_fragment(frag); +#if defined(CONFIG_FUSIV_KERNEL_BWMON_STATS) || defined(CONFIG_FUSIV_KERNEL_BWMON_STATS_MODULE) + /* usReceivedLength of head SKB is getting duplicated for this + fragment.hence make it zero.usReceivedLength of all fragments + is already summed up and stored in head skb during reassembly. + */ + frag->apFlowData.bwmonInfo.usReceivedLength=0; +#endif offset += skb->len - hlen; iph->frag_off = htons(offset>>3); if (frag->next != NULL) @@ -643,6 +745,31 @@ /* * Set up data on packet */ +#if defined(CONFIG_FUSIV_KERNEL_AP_2_AP) || defined(CONFIG_FUSIV_KERNEL_AP_2_AP_MODULE) +#if defined (CONFIG_FUSIV_VX185) || defined (CONFIG_FUSIV_VX585) + // Bug 25821@dekumar: At this point skb2->head and skb2->data points to data part of + // the cluster (which is assigned in alloc_skb). We have ap_prehdr and unused length prior to + // data part of cluster. we need to copy the preheader from skb to skb2, hence we need to + // move back skb2->head to cluster base address by size of preheader and unused length + + // As of now we are allocationg buffer of size 2304 bytes by creating a new slab + // Its being observed that the addresses are 32 byte aligned. + + // In order to move to base of the cluster we are subtracting ap_prehdr size+unused + //length from skb2->head. + + + // Size of apPreHdr is 68 bytes + unused length is 56 bytes = 124bytes (0x7C). + //Total copied is size of ap pre header + // Jira defect: https://jira.ikanos.com/browse/SHARK-4220 + // Instead of manipulating the skb-> head pointer to reach to the start of the cluster + // use skb->apAlloAddr instead, which will contain the cluster address + if (SKB_APBUF_ALLOCATED (skb) && SKB_APBUF_ALLOCATED (skb2)) + { + memcpy(skb2->apAllocAddr, skb->apAllocAddr, PREHDR_SIZE); + } +#endif +#endif ip_copy_metadata(skb2, skb); skb_reserve(skb2, ll_rs); @@ -685,6 +812,14 @@ */ if (offset == 0) ip_options_fragment(skb); +#if defined(CONFIG_FUSIV_KERNEL_BWMON_STATS) || defined(CONFIG_FUSIV_KERNEL_BWMON_STATS_MODULE) + /* usReceivedLength is used only WAN received packets this Rx length + will be updated by original SKB subsequent fragments this value + should be set to zero to avoid duplicate updation. + */ + else + skb2->apFlowData.bwmonInfo.usReceivedLength=0; +#endif /* * Added AC : If we are fragmenting a fragment that's not the @@ -1532,3 +1667,254 @@ igmp_mc_proc_init(); #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; + } + + if(iph->version!=4) + { + goto fail; + } + 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); + + if(fragInfo->pktType & (1 << PKT_TYPE_VLAN)) + { + pppoeHdr->length -= sizeof(struct vlan_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