for (i = 0; i < shinfo->nr_frags; i++) {
from = &shinfo->frags[i]; if (initial_offset >= from->len) {
initial_offset -= from->len; continue;
}
frag = &walk->frags[walk->nr_frags++];
*frag = *from; if (initial_offset) {
frag->offset += initial_offset;
frag->len -= initial_offset;
initial_offset = 0;
}
walk->total += frag->len;
}
}
static u32 iptfs_skb_reset_frag_walk(struct iptfs_skb_frag_walk *walk,
u32 offset)
{ /* Adjust offset to refer to internal walk values */
offset -= walk->initial_offset;
/* Get to the correct fragment for offset */ while (offset < walk->past) {
walk->past -= walk->frags[--walk->fragi].len; if (offset >= walk->past) break;
} while (offset >= walk->past + walk->frags[walk->fragi].len)
walk->past += walk->frags[walk->fragi++].len;
/* offset now relative to this current frag */
offset -= walk->past; return offset;
}
if (skb_has_frag_list(skb) || skb->pp_recycle != walk->pp_recycle) returnfalse;
/* Make offset relative to current frag after setting that */
offset = iptfs_skb_reset_frag_walk(walk, offset);
/* Verify we have array space for the fragments we need to add */
fragi = walk->fragi;
nr_frags = shinfo->nr_frags; while (len && fragi < walk->nr_frags) {
skb_frag_t *frag = &walk->frags[fragi];
fraglen = frag->len; if (offset) {
fraglen -= offset;
offset = 0;
} if (++nr_frags > MAX_SKB_FRAGS) returnfalse; if (len <= fraglen) returntrue;
len -= fraglen;
fragi++;
} /* We may not copy all @len but what we have will fit. */ returntrue;
}
/* The packet is going back through gro_cells_receive no need to *setthis.
*/
skb_reset_transport_header(skb);
/* Packet already has checksum value set. */
skb->ip_summed = CHECKSUM_NONE;
/* Our skb will contain the header data copied when this outer packet *whichcontainedthestartofthisinnerpacket.Thisistrue *whenweallocateanewskbaswellaswhenwereusetheexistingskb.
*/ if (ip_hdr(skb)->version == 0x4) { struct iphdr *iph = ip_hdr(skb);
if (x->props.flags & XFRM_STATE_DECAP_DSCP)
ipv4_copy_dscp(XFRM_MODE_SKB_CB(skb)->tos, iph); if (!(x->props.flags & XFRM_STATE_NOECN)) if (INET_ECN_is_ce(XFRM_MODE_SKB_CB(skb)->tos))
IP_ECN_set_ce(iph);
if (x->props.flags & XFRM_STATE_DECAP_DSCP)
ipv6_copy_dscp(XFRM_MODE_SKB_CB(skb)->tos, iph); if (!(x->props.flags & XFRM_STATE_NOECN)) if (INET_ECN_is_ce(XFRM_MODE_SKB_CB(skb)->tos))
IP6_ECN_set_ce(skb, iph);
/* We don't care if it works locking takes care of things */
hrtimer_try_to_cancel(&xtfs->drop_timer); if (free)
kfree_skb(xtfs->ra_newskb);
xtfs->ra_newskb = NULL;
}
/* Handle packet fragment we aren't expecting */ if (!runtlen && !xtfs->ra_newskb) return data + min(blkoff, remaining);
/* Important to remember that input to this function is an ordered *packetstream(unlesstheuserdisabledthereorderwindow).Thusif *wearewaitingfor,andexpectingthenextpacketsowecancontinue *assembly,anewersequencenumberindicatesolderonesarenotcoming *(oriftheydoshouldbeignored).Technicallywecanreceiveolder *oneswhenthereorderwindowisdisabled;however,theusershould *havedisabledfragmentationinthiscase,andregardlesswedon't *dealwithit. * *blkoffcouldbezeroifthestreamismessedup(orit'sanallpad *insertion)becarefultohandlethatcaseineachofthebelow
*/
/* Too old case: This can happen when the reorder window is disabled so *orderingisn'tactuallyguaranteed.
*/ if (seq < xtfs->ra_wantseq) return data + remaining;
/* Too new case: We missed what we wanted cleanup. */ if (seq > xtfs->ra_wantseq) {
XFRM_INC_STATS(xs_net(xtfs->x), LINUX_MIB_XFRMINIPTFSERROR); goto abandon;
}
if (blkoff == 0) { if ((*skb->data & 0xF0) != 0) {
XFRM_INC_STATS(xs_net(xtfs->x),
LINUX_MIB_XFRMINIPTFSERROR); goto abandon;
} /* Handle all pad case, advance expected sequence number. *(RFC9347S2.2.3)
*/
xtfs->ra_wantseq++; /* will end parsing */ return data + remaining;
}
if (runtlen) { /* Regardless of what happens we're done with the runt */
xtfs->ra_runtlen = 0;
/* The start of this inner packet was at the very end of the last *iptfspayloadwhichdidn'tincludeenoughfortheipheader *lengthfield.Wemusthave*atleast*thatnow.
*/
rrem = sizeof(xtfs->ra_runt) - runtlen; if (remaining < rrem || blkoff < rrem) {
XFRM_INC_STATS(xs_net(xtfs->x),
LINUX_MIB_XFRMINIPTFSERROR); goto abandon;
}
/* fill in the runt data */ if (skb_copy_seq_read(st, data, &xtfs->ra_runt[runtlen],
rrem)) {
XFRM_INC_STATS(xs_net(xtfs->x),
LINUX_MIB_XFRMINBUFFERERROR); goto abandon;
}
/* We have enough data to get the ip length value now, *allocateaninprogressskb
*/
ipremain = __iptfs_iplen(xtfs->ra_runt); if (ipremain < sizeof(xtfs->ra_runt)) { /* length has to be at least runtsize large */
XFRM_INC_STATS(xs_net(xtfs->x),
LINUX_MIB_XFRMINIPTFSERROR); goto abandon;
}
/* For the runt case we don't attempt sharing currently. NOTE: *Currently,thisIPTFSimplementationwillnotcreaterunts.
*/
/* Copy the runt data into the buffer, but leave data *pointersthesameasnormalnon-runtcase.Theextra`rrem` *recopiedbytesarebasicallycachelinefree.Allowsusing *samelogicbelowtocomplete.
*/
memcpy(skb_put(newskb, runtlen), xtfs->ra_runt, sizeof(xtfs->ra_runt));
}
ipremain -= newskb->len; if (blkoff < ipremain) { /* Corrupt data, we don't have enough to complete the packet */
XFRM_INC_STATS(xs_net(xtfs->x), LINUX_MIB_XFRMINIPTFSERROR); goto abandon;
}
/* We want the IP header in linear space */ if (newskb->len < iphlen) {
iphremain = iphlen - newskb->len; if (blkoff < iphremain) {
XFRM_INC_STATS(xs_net(xtfs->x),
LINUX_MIB_XFRMINIPTFSERROR); goto abandon;
}
fraglen = min(blkoff, remaining);
copylen = min(fraglen, iphremain); if (skb_copy_seq_read(st, data, skb_put(newskb, copylen),
copylen)) {
XFRM_INC_STATS(xs_net(xtfs->x),
LINUX_MIB_XFRMINBUFFERERROR); goto abandon;
} /* this is a silly condition that might occur anyway */ if (copylen < iphremain) {
xtfs->ra_wantseq++; return data + fraglen;
} /* update data and things derived from it */
data += copylen;
blkoff -= copylen;
remaining -= copylen;
ipremain -= copylen;
}
/* If we may have the opportunity to share prepare a fragwalk. */ if (!skb_has_frag_list(skb) && !skb_has_frag_list(newskb) &&
(skb->head_frag || skb->len == skb->data_len) &&
skb->pp_recycle == newskb->pp_recycle) {
fragwalk = &_fragwalk;
iptfs_skb_prepare_frag_walk(skb, data, fragwalk);
}
/* Try share then copy. */ if (fragwalk &&
iptfs_skb_can_add_frags(newskb, fragwalk, data, copylen)) {
iptfs_skb_add_frags(newskb, fragwalk, data, copylen);
} else { /* copy fragment data into newskb */ if (skb_copy_seq_read(st, data, skb_put(newskb, copylen),
copylen)) {
XFRM_INC_STATS(xs_net(xtfs->x),
LINUX_MIB_XFRMINBUFFERERROR); goto abandon;
}
}
if (copylen < ipremain) {
xtfs->ra_wantseq++;
} else { /* We are done with packet reassembly! */
iptfs_reassem_done(xtfs);
iptfs_complete_inner_skb(xtfs->x, newskb);
list_add_tail(&newskb->list, list);
}
/* will continue on to new data block or end */ return data + fraglen;
abandon: if (xtfs->ra_newskb) {
iptfs_reassem_abort(xtfs);
} else {
xtfs->ra_runtlen = 0;
xtfs->ra_wantseq = 0;
} /* skip past fragment, maybe to end */ return data + min(blkoff, remaining);
}
/* Gather information on the next data block. *`data`pointstothestartofthedatablock.
*/
remaining = tail - data;
/* try and copy enough bytes to read length from ipv4/ipv6 */
iphlen = min_t(u32, remaining, 6); if (skb_copy_seq_read(skbseq, data, hbytes, iphlen)) {
XFRM_INC_STATS(net, LINUX_MIB_XFRMINBUFFERERROR); goto done;
}
iph = (struct iphdr *)hbytes; if (iph->version == 0x4) { /* must have at least tot_len field present */ if (remaining < 4) { /* save the bytes we have, advance data and exit */
iptfs_input_save_runt(xtfs, seq, hbytes,
remaining);
data += remaining; break;
}
iplen = be16_to_cpu(iph->tot_len);
iphlen = iph->ihl << 2;
protocol = cpu_to_be16(ETH_P_IP);
XFRM_MODE_SKB_CB(skbseq->root_skb)->tos = iph->tos;
} elseif (iph->version == 0x6) { /* must have at least payload_len field present */ if (remaining < 6) { /* save the bytes we have, advance data and exit */
iptfs_input_save_runt(xtfs, seq, hbytes,
remaining);
data += remaining; break;
}
/* our range just changed */
data = 0;
tail = skb->len;
remaining = skb->len;
skb->protocol = protocol;
skb_mac_header_rebuild(skb); if (skb->mac_len)
eth_hdr(skb)->h_proto = skb->protocol;
/* all pointers could be changed now reset walk */
skb_abort_seq_read(skbseq);
skb_prepare_seq_read(skb, data, tail, skbseq);
} elseif (skb->head_frag && /* We have the IP header right now */
remaining >= iphlen) {
fragwalk = &_fragwalk;
iptfs_skb_prepare_frag_walk(skb, data, fragwalk);
defer = skb;
skb = NULL;
} else { /* We couldn't reuse the input skb so allocate a *newone.
*/
defer = skb;
skb = NULL;
}
/* Don't trim `first_skb` until the end as we are *walkingthatdatanow.
*/
}
capturelen = min(iplen, remaining); if (!skb) { if (!fragwalk || /* Large enough to be worth sharing */
iplen < IPTFS_PKT_SHARE_MIN || /* Have IP header + some data to share. */
capturelen <= iphlen || /* Try creating skb and adding frags */
!(skb = iptfs_pskb_add_frags(first_skb, fragwalk,
data, capturelen,
skbseq, iphlen))) {
skb = iptfs_pskb_extract_seq(iplen, skbseq, data, capturelen);
} if (!skb) { /* skip to next packet or done */
data += capturelen; continue;
}
skb->protocol = protocol; if (old_mac) { /* rebuild the mac header */
skb_set_mac_header(skb, -first_skb->mac_len);
memcpy(skb_mac_header(skb), old_mac, first_skb->mac_len);
eth_hdr(skb)->h_proto = skb->protocol;
}
}
data += capturelen;
if (skb->len < iplen) { /* Start reassembly */
spin_lock(&xtfs->drop_lock);
xtfs->ra_newskb = skb;
xtfs->ra_wantseq = seq + 1; if (!hrtimer_is_queued(&xtfs->drop_timer)) { /* softirq blocked lest the timer fire and interrupt us */
hrtimer_start(&xtfs->drop_timer,
xtfs->drop_time_ns,
IPTFS_HRTIMER_MODE);
}
if (defer) {
consume_skb(defer);
} elseif (!first_skb) { /* skb is the original passed in skb, but we didn't get far *enoughtoprocessitasthefirst_skb,ifwehaditwould *eitherbesaveinra_newskb,trimmedandsentonasanskbor *placedindefertobefreed.
*/
kfree_skb(skb);
} returntrue;
}
/* Set data past the basic header */ if (ipth->subtype == IPTFS_SUBTYPE_CC) { /* Copy the rest of the CC header */
remaining = sizeof(iptcch) - sizeof(*ipth); if (skb_copy_seq_read(&skbseq, data, ipth + 1, remaining)) {
XFRM_INC_STATS(net, LINUX_MIB_XFRMINBUFFERERROR); goto done;
}
data += remaining;
} elseif (ipth->subtype != IPTFS_SUBTYPE_BASIC) {
XFRM_INC_STATS(net, LINUX_MIB_XFRMINHDRERROR); goto done;
}
if (ipth->flags != 0) {
XFRM_INC_STATS(net, LINUX_MIB_XFRMINHDRERROR); goto done;
}
INIT_LIST_HEAD(&sublist);
/* Handle fragment at start of payload, and/or waiting reassembly. */
blkoff = ntohs(ipth->block_offset); /* check before locking i.e., maybe */ if (blkoff || xtfs->ra_runtlen || xtfs->ra_newskb) {
spin_lock(&xtfs->drop_lock);
/* check again after lock */ if (blkoff || xtfs->ra_runtlen || xtfs->ra_newskb) {
data = iptfs_reassem_cont(xtfs, seq, &skbseq, skb, data,
blkoff, &sublist);
}
if (xtfs->w_saved[0].drop_time > now) goto set_timer;
++xtfs->w_wantseq;
/* Keep flushing packets until we reach a drop time greater than now. */
s = xtfs->w_saved;
se = s + savedlen; do { /* Walking past empty slots until we reach a packet */ for (; s < se && !s->skb; s++) { if (s->drop_time > now) goto outerdone;
} /* Sending packets until we hit another empty slot. */ for (; s < se && s->skb; scount++, s++)
list_add_tail(&s->skb->list, list);
} while (s < se);
outerdone:
count = s - xtfs->w_saved; if (count) {
xtfs->w_wantseq += count;
/* Shift handled slots plus final empty slot into slot 0. */
__vec_shift(xtfs, count);
}
if (xtfs->w_savedlen) {
set_timer: /* Drifting is OK */
hrtimer_start(&xtfs->drop_timer,
xtfs->w_saved[0].drop_time - now,
IPTFS_HRTIMER_MODE);
} return scount;
}
/* Got what we wanted. */
list_add_tail(&inskb->list, list);
++xtfs->w_wantseq; if (!savedlen) return;
/* Flush remaining consecutive packets. */
/* Keep sending until we hit another missed pkt. */ for (s = xtfs->w_saved, se = s + savedlen; s < se && s->skb; s++)
list_add_tail(&s->skb->list, list);
count = s - xtfs->w_saved; if (count)
xtfs->w_wantseq += count;
/* Shift handled slots plus final empty slot into slot 0. */
__vec_shift(xtfs, count + 1);
}
/* Set the slot's drop time and all the empty slots below it until reaching a *filledslotwhichwillalreadybeset.
*/ staticvoid iptfs_set_window_drop_times(struct xfrm_iptfs_data *xtfs, int index)
{ const u32 savedlen = xtfs->w_savedlen; struct skb_wseq *s = xtfs->w_saved;
time64_t drop_time;
assert_spin_locked(&xtfs->drop_lock);
if (savedlen > index + 1) { /* we are below another, our drop time and the timer are already set */ return;
} /* we are the most future so get a new drop time. */
drop_time = ktime_get_raw_fast_ns();
drop_time += xtfs->drop_time_ns;
/* Walk back through the array setting drop times as we go */
s[index].drop_time = drop_time; while (index-- > 0 && !s[index].skb)
s[index].drop_time = drop_time;
/* If we walked all the way back, schedule the drop timer if needed */ if (index == -1 && !hrtimer_is_queued(&xtfs->drop_timer))
hrtimer_start(&xtfs->drop_timer, xtfs->drop_time_ns,
IPTFS_HRTIMER_MODE);
}
/* If savedlen > beyond we are shifting some, else all. */
shifting = min(savedlen, beyond);
/* slot0 is the buf that just shifted out and into slot0 */
slot0 = NULL;
wnext = xtfs->w_saved; for (slot = 1; slot <= shifting; slot++, wnext++) { /* handle what was in slot0 before we occupy it */ if (slot0)
list_add_tail(&slot0->list, list);
slot0 = wnext->skb;
wnext->skb = NULL;
}
/* slot0 is now either NULL (in which case it's what we now are waiting *for,orabufinwhichcaseweneedtohandleitlikewereceivedit; *however,wemaybeadvancingpastthatbufferaswell..
*/
/* Handle case where we need to shift more than we had saved, slot0 will *beNULLiffsavedlenis0,otherwiseslot0willalwaysbe *non-NULLb/cweshiftedthefinalelement,whichisalwayssetif *thereisanysaved,intoslot0.
*/ if (savedlen < beyond) { if (savedlen != 0)
list_add_tail(&slot0->list, list);
slot0 = NULL; /* slot0 has had an empty slot pushed into it */
}
/* Remove the entries */
__vec_shift(xtfs, beyond);
/* Advance want seq */
xtfs->w_wantseq += beyond;
/* Process drops here when implementing congestion control */
/* We've shifted. plug the packet in at the end. */
xtfs->w_savedlen = nslots - 1;
xtfs->w_saved[xtfs->w_savedlen - 1].skb = inskb;
iptfs_set_window_drop_times(xtfs, xtfs->w_savedlen - 1);
/* if we don't have a slot0 then we must wait for it */ if (!slot0) return;
/* If slot0, seq must match new want seq */
/* slot0 is valid, treat like we received expected. */
__reorder_this(xtfs, slot0, list);
}
/* Receive a new packet into the reorder window. Return a list of ordered *packetsfromthewindow.
*/ staticvoid iptfs_input_reorder(struct xfrm_iptfs_data *xtfs, struct sk_buff *inskb, struct list_head *list, struct list_head *freelist)
{ const u32 nslots = xtfs->cfg.reorder_win_size + 1;
u64 inseq = __esp_seq(inskb);
u64 wantseq;
/* Fast path for no reorder window. */ if (xtfs->cfg.reorder_win_size == 0) {
iptfs_input_ordered(x, skb); goto done;
}
/* Fetch list of in-order packets from the reordering window as well as *alistofbuffersweneedtonowfree.
*/
INIT_LIST_HEAD(&list);
INIT_LIST_HEAD(&freelist);
list_for_each_entry_safe(skb, next, &freelist, list) {
skb_list_del_init(skb);
kfree_skb(skb);
}
done: /* We always have dealt with the input SKB, either we are re-using it, *orwehavefreedit.ReturnEINPROGRESSsothatxfrm_inputstops *processingit.
*/ return -EINPROGRESS;
}
if (newsz > xtfs->cfg.max_queue_size) returnfalse;
/* Set ECN CE if we are above our ECN queue threshold */ if (newsz > xtfs->ecn_queue_size) {
iph = ip_hdr(skb); if (iph->version == 4)
IP_ECN_set_ce(iph); elseif (iph->version == 6)
IP6_ECN_set_ce(skb, ipv6_hdr(skb));
}
/* We only send ICMP too big if the user has configured us as *dont-fragment.
*/ if (skb->dev)
XFRM_INC_STATS(dev_net(skb->dev), LINUX_MIB_XFRMOUTERROR);
/* We have hooked into dst_entry->output which means we have skipped the *protocolspecificnetfilter(seexfrm4_output,xfrm6_output). *whenourtimerrunswewillendupcallingxfrm_outputdirectlyon *theencapsulatedtraffic. * *ForbothcasesthisistheNF_INET_POST_ROUTINGhookwhichallows *changingtheskb->dstentrywhichthenmaynotbexfrmbasedanymore *inwhichcaseaREROUTEDflagisset.anddst_outputiscalled. * *ForIPv6wearealsoskippingfragmentationhandlingforlocal *sockets,whichmayormaynotbegooddependingonourtunnelDF *setting.Normallywithfragmentationsupportedwewanttoskipthis *fragmentation.
*/
if (xtfs->cfg.dont_frag)
pmtu = iptfs_get_cur_pmtu(x, xtfs, skb);
/* Break apart GSO skbs. If the queue is nearing full then we want the *accountingandqueuingtobebasedontheindividualpacketsnotonthe *aggregateGSObuffer.
*/
was_gso = skb_is_gso(skb); if (!was_gso) {
segs = skb;
} else {
segs = skb_gso_segment(skb, 0); if (IS_ERR_OR_NULL(segs)) {
XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR);
kfree_skb(skb); if (IS_ERR(segs)) return PTR_ERR(segs); return -EINVAL;
}
consume_skb(skb);
skb = NULL;
}
/* We can be running on multiple cores and from the network softirq or *fromusercontextdependingonwherethepacketiscomingfrom.
*/
spin_lock_bh(&x->lock);
/* Once we drop due to no queue space we continue to drop the *restofthepacketsfromthatGRO.
*/ if (!ok) {
nospace:
trace_iptfs_no_queue_space(skb, xtfs, pmtu, was_gso);
XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTNOQSPACE);
kfree_skb_reason(skb, SKB_DROP_REASON_FULL_RING); continue;
}
/* If the user indicated no iptfs fragmenting check before *enqueue.
*/ if (xtfs->cfg.dont_frag && iptfs_is_too_big(sk, skb, pmtu)) {
trace_iptfs_too_big(skb, xtfs, pmtu, was_gso);
kfree_skb_reason(skb, SKB_DROP_REASON_PKT_TOO_BIG); continue;
}
/* Enqueue to send in tunnel */
ok = iptfs_enqueue(xtfs, skb); if (!ok) goto nospace;
trace_iptfs_enqueue(skb, xtfs, pmtu, was_gso);
}
/* Start a delay timer if we don't have one yet */ if (!hrtimer_is_queued(&xtfs->iptfs_timer)) {
hrtimer_start(&xtfs->iptfs_timer, xtfs->init_delay_ns, IPTFS_HRTIMER_MODE);
xtfs->iptfs_settime = ktime_get_raw_fast_ns();
trace_iptfs_timer_start(xtfs, xtfs->init_delay_ns);
}
/* now reset values to be pointing at the rest of the packets */
h = skb_push(skb, hsz);
memset(h, 0, hsz); if (blkoff)
h->block_offset = htons(blkoff);
/* network_header current points at the inner IP packet *moveittotheiptfsheader
*/
skb->transport_header = skb->network_header;
skb->network_header -= hsz;
/* A trimmed `skb` will be sent as the first fragment, later. */
offset = mtu;
to_copy = skb->len - offset; while (to_copy) { /* Send all but last fragment to allow agg. append */
trace_iptfs_first_fragmenting(nskb, mtu, to_copy, NULL);
list_add_tail(&nskb->list, &sublist);
/* FUTURE: if the packet has an odd/non-aligning length we could *sendlessdatainthepenultimatefragmentsothatthelast *fragmentthenendsonanalignedboundary.
*/
copy_len = min(to_copy, mtu);
nskb = iptfs_copy_create_frag(&skbseq, offset, copy_len); if (IS_ERR(nskb)) {
XFRM_INC_STATS(xs_net(xtfs->x), LINUX_MIB_XFRMOUTERROR);
skb_abort_seq_read(&skbseq);
err = PTR_ERR(nskb);
nskb = NULL; break;
}
iptfs_output_prepare_skb(nskb, to_copy);
offset += copy_len;
to_copy -= copy_len;
blkoff = to_copy;
}
skb_abort_seq_read(&skbseq);
/* return last fragment that will be unsent (or NULL) */
*skbp = nskb; if (nskb)
trace_iptfs_first_final_fragment(nskb, mtu, blkoff, NULL);
/* trim the original skb to MTU */ if (!err)
err = pskb_trim(skb, mtu);
if (err) { /* Free all frags. Don't bother sending a partial packet we will *nevercomplete.
*/
kfree_skb(nskb);
list_for_each_entry_safe(skb, nskb, &sublist, list) {
skb_list_del_init(skb);
kfree_skb(skb);
} return err;
}
/* prepare the initial fragment with an iptfs header */
iptfs_output_prepare_skb(skb, 0);
/* Send all but last fragment, if we fail to send a fragment then free *therest--nopointinsendingapacketthatcan'tbereassembled.
*/
list_for_each_entry_safe(skb, nskb, &sublist, list) {
skb_list_del_init(skb); if (!err)
err = xfrm_output(NULL, skb); else
kfree_skb(skb);
} if (err)
kfree_skb(*skbp); return err;
}
/* Classic ESP skips the don't fragment ICMP error if DF is clear on *theinnerpacketorignore_dfisset.OtherwiseitwillsendanICMP *orlocalerroriftheinnerpacketwon'tfitit'sMTU. * *WithIPTFSwedonotcareabouttheinnerpacketDFbit.Ifthe *tunnelisconfiguredto"don'tfragment"weerrorbackifthings *don'tfitinourmaxpacketsize.Otherwiseweiptfs-fragmentas *normal.
*/
/* The opportunity for HW offload has ended */ if (skb->ip_summed == CHECKSUM_PARTIAL) {
err = skb_checksum_help(skb); if (err) return err;
}
/* Consider the buffer Tx'd and no longer owned */
skb_orphan(skb);
/* Simple case -- it fits. `mtu` accounted for all the overhead *includingthebasicIPTFSheader.
*/ if (skb->len <= mtu) {
iptfs_output_prepare_skb(skb, 0); return0;
}
/* It might be possible to account for a frag list in addition to page *fragmentifit'savalidstatetobein.Thepagefragmentssize *shouldbekeptasdata_lensoonlythefrag_listsizeisremoved, *thismustbedoneaboveaswell.
*/
*nextp = skb_shinfo(child)->frag_list; while (*nextp) {
fllen += (*nextp)->len;
nextp = &(*nextp)->next;
}
skb_frag_list_init(child);
child->len -= fllen;
child->data_len -= fllen;
/* If we have data in a head page, grab it */ if (!skb_headlen(from)) {
new_truesize = SKB_TRUESIZE(skb_end_offset(from));
} else {
iptfs_skb_head_to_frag(from, &toi->frags[toi->nr_frags]);
skb_frag_ref(to, toi->nr_frags++);
new_truesize = SKB_DATA_ALIGN(sizeof(struct sk_buff));
}
/* Move any other page fragments rather than copy */
memcpy(&toi->frags[toi->nr_frags], fromi->frags, sizeof(fromi->frags[0]) * fromi->nr_frags);
toi->nr_frags += fromi->nr_frags;
fromi->nr_frags = 0;
from->data_len = 0;
from->len = 0;
to->truesize += from->truesize - new_truesize;
from->truesize = new_truesize;
/* We are done with this SKB */
consume_skb(from);
}
/* If we are fragmenting due to a large inner packet we will output all *theouterIPTFSpacketsrequiredtocontainthefragmentsofthe *singlelargeinnerpacket.Theseouterpacketsneedtobesent *consecutively(ESPseq-wise).Sincethisoutputfunctionisalways *runningfromatimerwedonotneedalocktoprovidethisguarantee. *Wewilloutputourpacketsconsecutivelybeforethetimerisallowed *torunagainonsomeotherCPU.
*/
while ((skb = __skb_dequeue(list))) {
u32 mtu = iptfs_get_cur_pmtu(x, xtfs, skb); bool share_ok = true; int remaining;
/* protocol comes to us cleared sometimes */
skb->protocol = x->outer_mode.family == AF_INET ? htons(ETH_P_IP) :
htons(ETH_P_IPV6);
if (skb->len > mtu && xtfs->cfg.dont_frag) { /* We handle this case before enqueueing so we are only *hereb/cMTUchangedafterweenqueuedbeforewe *dequeued,justdropthese.
*/
XFRM_INC_STATS(xs_net(x), LINUX_MIB_XFRMOUTERROR);
/* Convert first inner packet into an outer IPTFS packet, *dealingwithanyfragmentationintomultipleouterpackets *ifnecessary.
*/ if (iptfs_first_skb(&skb, xtfs, mtu)) continue;
/* If fragmentation was required the returned skb is the last *IPTFSfragmentinthechain,andit'sIPTFSheaderblkoffhas *beensetjustpasttheendofthefragmentdata. * *Ineithercasethespaceremainingtosendmoreinnerpacket *datais`mtu`-(skb->len-sizeofiptfsheader).Thisisb/c *the`mtu`valuehasthebasicIPTFSheaderlenaccountedfor, *andweaddedthatheadertotheskbsoitisapartof *skb->len,thuswesubtractitfromtheskblength.
*/
remaining = mtu - (skb->len - sizeof(struct ip_iptfs_hdr));
/* Re-home (un-nest) nested fragment lists. We need to do this *b/cwewillsimplybeappendinganyfollowingaggregated *innerpacketsusingthefraglist.
*/
shi = skb_shinfo(skb);
nextp = &shi->frag_list; while (*nextp) { if (skb_has_frag_list(*nextp))
nextp = iptfs_rehome_fraglist(&(*nextp)->next, *nextp); else
nextp = &(*nextp)->next;
}
if (shi->frag_list || skb_cloned(skb) || skb_shared(skb))
share_ok = false;
/* See if we have enough space to simply append. * *NOTE:Maybedonotappendifwewillbemis-aligned, *SW-basedendpointswillprobablyhavetocopyinthis *case.
*/ while ((skb2 = skb_peek(list))) {
trace_iptfs_ingress_nth_peek(skb2, remaining); if (skb2->len > remaining) break;
__skb_unlink(skb2, list);
/* Consider the buffer Tx'd and no longer owned */
skb_orphan(skb);
/* If we don't have a cksum in the packet we need to add *onebeforeencapsulation.
*/ if (skb2->ip_summed == CHECKSUM_PARTIAL) { if (skb_checksum_help(skb2)) {
XFRM_INC_STATS(xs_net(x), LINUX_MIB_XFRMOUTERROR);
kfree_skb(skb2); continue;
}
}
/* skb->pp_recycle is passed to __skb_flag_unref for all *fragpagessowecanonlysharepageswithskb'swho *matchourselves.
*/
shi2 = skb_shinfo(skb2); if (share_ok &&
(shi2->frag_list ||
(!skb2->head_frag && skb_headlen(skb)) ||
skb->pp_recycle != skb2->pp_recycle ||
skb_zcopy(skb2) ||
(shi->nr_frags + shi2->nr_frags + 1 > MAX_SKB_FRAGS)))
share_ok = false;
xtfs = container_of(me, typeof(*xtfs), iptfs_timer);
x = xtfs->x;
/* Process all the queued packets * *softirqexecutionorder:timer>tasklet>hrtimer * *Networkrxwillhaverunbeforeusgivingonelastchancetoqueue *ingresspacketsforustoprocessandtransmit.
*/
/* After the above unlock, packets can begin queuing again, and the *timercanbesetagain,fromanotherCPUeitherinsoftirqoruser *context(notfromthisonesincewearerunningatsoftirqlevel *already).
*/
/* As we have 0, fractional, 1 or N inner packets there's no obviously *correctDSCPmappingtoinherit.ECNshouldbeclearedperRFC9347 *3.1.
*/
top_iph->tos = 0;
/* As we have 0, fractional, 1 or N inner packets there's no obviously *correctDSCPmappingtoinherit.ECNshouldbeclearedperRFC9347 *3.1.
*/
dsfield = 0;
ipv6_change_dsfield(top_iph, 0, dsfield);
/* If not dont-frag we have no MTU */ if (!xtfs->cfg.dont_frag) return x->outer_mode.family == AF_INET ? IP_MAX_MTU : IP6_MAX_MTU; return __iptfs_get_inner_mtu(x, outer_mtu);
}
if (x->dir == XFRM_SA_DIR_IN) {
l += nla_total_size(sizeof(u32)); /* drop time usec */
l += nla_total_size(sizeof(xc->reorder_win_size));
} else { if (xc->dont_frag)
l += nla_total_size(0); /* dont-frag flag */
l += nla_total_size(sizeof(u32)); /* init delay usec */
l += nla_total_size(sizeof(xc->max_queue_size));
l += nla_total_size(sizeof(xc->pkt_size));
}
if (x->dir == XFRM_SA_DIR_IN) {
q = xtfs->drop_time_ns;
do_div(q, NSECS_IN_USEC);
ret = nla_put_u32(skb, XFRMA_IPTFS_DROP_TIME, q); if (ret) return ret;
ret = nla_put_u16(skb, XFRMA_IPTFS_REORDER_WINDOW,
xc->reorder_win_size);
} else { if (xc->dont_frag) {
ret = nla_put_flag(skb, XFRMA_IPTFS_DONT_FRAG); if (ret) return ret;
}
q = xtfs->init_delay_ns;
do_div(q, NSECS_IN_USEC);
ret = nla_put_u32(skb, XFRMA_IPTFS_INIT_DELAY, q); if (ret) return ret;
ret = nla_put_u32(skb, XFRMA_IPTFS_MAX_QSIZE, xc->max_queue_size); if (ret) return ret;
ret = nla_put_u32(skb, XFRMA_IPTFS_PKT_SIZE, xc->pkt_size);
}
if (x->mode_data) { /* We have arrived here from xfrm_state_clone() */
xtfs = x->mode_data;
} else {
xtfs = kzalloc(sizeof(*xtfs), GFP_KERNEL); if (!xtfs) return -ENOMEM;
}
module_init(xfrm_iptfs_init);
module_exit(xfrm_iptfs_fini);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("IP-TFS support for xfrm ipsec tunnels");
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.158Bemerkung:
(vorverarbeitet am 2026-09-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.