5050#include <linux/seq_file.h>
5151#include <trace/events/skb.h>
5252#include "udp_impl.h"
53+ #include "ip6_offload.h"
5354
5455int ipv6_rcv_saddr_equal (const struct sock * sk , const struct sock * sk2 )
5556{
@@ -1343,109 +1344,12 @@ int compat_udpv6_getsockopt(struct sock *sk, int level, int optname,
13431344}
13441345#endif
13451346
1346- static int udp6_ufo_send_check (struct sk_buff * skb )
1347- {
1348- const struct ipv6hdr * ipv6h ;
1349- struct udphdr * uh ;
1350-
1351- if (!pskb_may_pull (skb , sizeof (* uh )))
1352- return - EINVAL ;
1353-
1354- ipv6h = ipv6_hdr (skb );
1355- uh = udp_hdr (skb );
1356-
1357- uh -> check = ~csum_ipv6_magic (& ipv6h -> saddr , & ipv6h -> daddr , skb -> len ,
1358- IPPROTO_UDP , 0 );
1359- skb -> csum_start = skb_transport_header (skb ) - skb -> head ;
1360- skb -> csum_offset = offsetof(struct udphdr , check );
1361- skb -> ip_summed = CHECKSUM_PARTIAL ;
1362- return 0 ;
1363- }
1364-
1365- static struct sk_buff * udp6_ufo_fragment (struct sk_buff * skb ,
1366- netdev_features_t features )
1367- {
1368- struct sk_buff * segs = ERR_PTR (- EINVAL );
1369- unsigned int mss ;
1370- unsigned int unfrag_ip6hlen , unfrag_len ;
1371- struct frag_hdr * fptr ;
1372- u8 * mac_start , * prevhdr ;
1373- u8 nexthdr ;
1374- u8 frag_hdr_sz = sizeof (struct frag_hdr );
1375- int offset ;
1376- __wsum csum ;
1377-
1378- mss = skb_shinfo (skb )-> gso_size ;
1379- if (unlikely (skb -> len <= mss ))
1380- goto out ;
1381-
1382- if (skb_gso_ok (skb , features | NETIF_F_GSO_ROBUST )) {
1383- /* Packet is from an untrusted source, reset gso_segs. */
1384- int type = skb_shinfo (skb )-> gso_type ;
1385-
1386- if (unlikely (type & ~(SKB_GSO_UDP | SKB_GSO_DODGY ) ||
1387- !(type & (SKB_GSO_UDP ))))
1388- goto out ;
1389-
1390- skb_shinfo (skb )-> gso_segs = DIV_ROUND_UP (skb -> len , mss );
1391-
1392- segs = NULL ;
1393- goto out ;
1394- }
1395-
1396- /* Do software UFO. Complete and fill in the UDP checksum as HW cannot
1397- * do checksum of UDP packets sent as multiple IP fragments.
1398- */
1399- offset = skb_checksum_start_offset (skb );
1400- csum = skb_checksum (skb , offset , skb -> len - offset , 0 );
1401- offset += skb -> csum_offset ;
1402- * (__sum16 * )(skb -> data + offset ) = csum_fold (csum );
1403- skb -> ip_summed = CHECKSUM_NONE ;
1404-
1405- /* Check if there is enough headroom to insert fragment header. */
1406- if ((skb_mac_header (skb ) < skb -> head + frag_hdr_sz ) &&
1407- pskb_expand_head (skb , frag_hdr_sz , 0 , GFP_ATOMIC ))
1408- goto out ;
1409-
1410- /* Find the unfragmentable header and shift it left by frag_hdr_sz
1411- * bytes to insert fragment header.
1412- */
1413- unfrag_ip6hlen = ip6_find_1stfragopt (skb , & prevhdr );
1414- nexthdr = * prevhdr ;
1415- * prevhdr = NEXTHDR_FRAGMENT ;
1416- unfrag_len = skb_network_header (skb ) - skb_mac_header (skb ) +
1417- unfrag_ip6hlen ;
1418- mac_start = skb_mac_header (skb );
1419- memmove (mac_start - frag_hdr_sz , mac_start , unfrag_len );
1420-
1421- skb -> mac_header -= frag_hdr_sz ;
1422- skb -> network_header -= frag_hdr_sz ;
1423-
1424- fptr = (struct frag_hdr * )(skb_network_header (skb ) + unfrag_ip6hlen );
1425- fptr -> nexthdr = nexthdr ;
1426- fptr -> reserved = 0 ;
1427- ipv6_select_ident (fptr , (struct rt6_info * )skb_dst (skb ));
1428-
1429- /* Fragment the skb. ipv6 header and the remaining fields of the
1430- * fragment header are updated in ipv6_gso_segment()
1431- */
1432- segs = skb_segment (skb , features );
1433-
1434- out :
1435- return segs ;
1436- }
1437-
14381347static const struct inet6_protocol udpv6_protocol = {
14391348 .handler = udpv6_rcv ,
14401349 .err_handler = udpv6_err ,
14411350 .flags = INET6_PROTO_NOPOLICY |INET6_PROTO_FINAL ,
14421351};
14431352
1444- static const struct net_offload udpv6_offload = {
1445- .gso_send_check = udp6_ufo_send_check ,
1446- .gso_segment = udp6_ufo_fragment ,
1447- };
1448-
14491353/* ------------------------------------------------------------------------ */
14501354#ifdef CONFIG_PROC_FS
14511355
@@ -1568,7 +1472,7 @@ int __init udpv6_init(void)
15681472{
15691473 int ret ;
15701474
1571- ret = inet6_add_offload ( & udpv6_offload , IPPROTO_UDP );
1475+ ret = udp_offload_init ( );
15721476 if (ret )
15731477 goto out ;
15741478
@@ -1585,13 +1489,13 @@ int __init udpv6_init(void)
15851489out_udpv6_protocol :
15861490 inet6_del_protocol (& udpv6_protocol , IPPROTO_UDP );
15871491out_offload :
1588- inet6_del_offload ( & udpv6_offload , IPPROTO_UDP );
1492+ udp_offload_cleanup ( );
15891493 goto out ;
15901494}
15911495
15921496void udpv6_exit (void )
15931497{
15941498 inet6_unregister_protosw (& udpv6_protosw );
15951499 inet6_del_protocol (& udpv6_protocol , IPPROTO_UDP );
1596- inet6_del_offload ( & udpv6_offload , IPPROTO_UDP );
1500+ udp_offload_cleanup ( );
15971501}
0 commit comments