aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/af_inet.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/ipv4/af_inet.c')
-rw-r--r--net/ipv4/af_inet.c69
1 files changed, 56 insertions, 13 deletions
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 5c5db6636704..9e481992dbae 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -370,7 +370,11 @@ lookup_protocol:
370 */ 370 */
371 inet->inet_sport = htons(inet->inet_num); 371 inet->inet_sport = htons(inet->inet_num);
372 /* Add to protocol hash chains. */ 372 /* Add to protocol hash chains. */
373 sk->sk_prot->hash(sk); 373 err = sk->sk_prot->hash(sk);
374 if (err) {
375 sk_common_release(sk);
376 goto out;
377 }
374 } 378 }
375 379
376 if (sk->sk_prot->init) { 380 if (sk->sk_prot->init) {
@@ -1091,12 +1095,6 @@ void inet_unregister_protosw(struct inet_protosw *p)
1091} 1095}
1092EXPORT_SYMBOL(inet_unregister_protosw); 1096EXPORT_SYMBOL(inet_unregister_protosw);
1093 1097
1094/*
1095 * Shall we try to damage output packets if routing dev changes?
1096 */
1097
1098int sysctl_ip_dynaddr __read_mostly;
1099
1100static int inet_sk_reselect_saddr(struct sock *sk) 1098static int inet_sk_reselect_saddr(struct sock *sk)
1101{ 1099{
1102 struct inet_sock *inet = inet_sk(sk); 1100 struct inet_sock *inet = inet_sk(sk);
@@ -1127,7 +1125,7 @@ static int inet_sk_reselect_saddr(struct sock *sk)
1127 if (new_saddr == old_saddr) 1125 if (new_saddr == old_saddr)
1128 return 0; 1126 return 0;
1129 1127
1130 if (sysctl_ip_dynaddr > 1) { 1128 if (sock_net(sk)->ipv4.sysctl_ip_dynaddr > 1) {
1131 pr_info("%s(): shifting inet->saddr from %pI4 to %pI4\n", 1129 pr_info("%s(): shifting inet->saddr from %pI4 to %pI4\n",
1132 __func__, &old_saddr, &new_saddr); 1130 __func__, &old_saddr, &new_saddr);
1133 } 1131 }
@@ -1142,8 +1140,7 @@ static int inet_sk_reselect_saddr(struct sock *sk)
1142 * Besides that, it does not check for connection 1140 * Besides that, it does not check for connection
1143 * uniqueness. Wait for troubles. 1141 * uniqueness. Wait for troubles.
1144 */ 1142 */
1145 __sk_prot_rehash(sk); 1143 return __sk_prot_rehash(sk);
1146 return 0;
1147} 1144}
1148 1145
1149int inet_sk_rebuild_header(struct sock *sk) 1146int inet_sk_rebuild_header(struct sock *sk)
@@ -1183,7 +1180,7 @@ int inet_sk_rebuild_header(struct sock *sk)
1183 * Other protocols have to map its equivalent state to TCP_SYN_SENT. 1180 * Other protocols have to map its equivalent state to TCP_SYN_SENT.
1184 * DCCP maps its DCCP_REQUESTING state to TCP_SYN_SENT. -acme 1181 * DCCP maps its DCCP_REQUESTING state to TCP_SYN_SENT. -acme
1185 */ 1182 */
1186 if (!sysctl_ip_dynaddr || 1183 if (!sock_net(sk)->ipv4.sysctl_ip_dynaddr ||
1187 sk->sk_state != TCP_SYN_SENT || 1184 sk->sk_state != TCP_SYN_SENT ||
1188 (sk->sk_userlocks & SOCK_BINDADDR_LOCK) || 1185 (sk->sk_userlocks & SOCK_BINDADDR_LOCK) ||
1189 (err = inet_sk_reselect_saddr(sk)) != 0) 1186 (err = inet_sk_reselect_saddr(sk)) != 0)
@@ -1383,6 +1380,45 @@ out:
1383 return pp; 1380 return pp;
1384} 1381}
1385 1382
1383static struct sk_buff **ipip_gro_receive(struct sk_buff **head,
1384 struct sk_buff *skb)
1385{
1386 if (NAPI_GRO_CB(skb)->encap_mark) {
1387 NAPI_GRO_CB(skb)->flush = 1;
1388 return NULL;
1389 }
1390
1391 NAPI_GRO_CB(skb)->encap_mark = 1;
1392
1393 return inet_gro_receive(head, skb);
1394}
1395
1396#define SECONDS_PER_DAY 86400
1397
1398/* inet_current_timestamp - Return IP network timestamp
1399 *
1400 * Return milliseconds since midnight in network byte order.
1401 */
1402__be32 inet_current_timestamp(void)
1403{
1404 u32 secs;
1405 u32 msecs;
1406 struct timespec64 ts;
1407
1408 ktime_get_real_ts64(&ts);
1409
1410 /* Get secs since midnight. */
1411 (void)div_u64_rem(ts.tv_sec, SECONDS_PER_DAY, &secs);
1412 /* Convert to msecs. */
1413 msecs = secs * MSEC_PER_SEC;
1414 /* Convert nsec to msec. */
1415 msecs += (u32)ts.tv_nsec / NSEC_PER_MSEC;
1416
1417 /* Convert to network byte order. */
1418 return htonl(msecs);
1419}
1420EXPORT_SYMBOL(inet_current_timestamp);
1421
1386int inet_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len) 1422int inet_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
1387{ 1423{
1388 if (sk->sk_family == AF_INET) 1424 if (sk->sk_family == AF_INET)
@@ -1425,6 +1461,13 @@ out_unlock:
1425 return err; 1461 return err;
1426} 1462}
1427 1463
1464static int ipip_gro_complete(struct sk_buff *skb, int nhoff)
1465{
1466 skb->encapsulation = 1;
1467 skb_shinfo(skb)->gso_type |= SKB_GSO_IPIP;
1468 return inet_gro_complete(skb, nhoff);
1469}
1470
1428int inet_ctl_sock_create(struct sock **sk, unsigned short family, 1471int inet_ctl_sock_create(struct sock **sk, unsigned short family,
1429 unsigned short type, unsigned char protocol, 1472 unsigned short type, unsigned char protocol,
1430 struct net *net) 1473 struct net *net)
@@ -1652,8 +1695,8 @@ static struct packet_offload ip_packet_offload __read_mostly = {
1652static const struct net_offload ipip_offload = { 1695static const struct net_offload ipip_offload = {
1653 .callbacks = { 1696 .callbacks = {
1654 .gso_segment = inet_gso_segment, 1697 .gso_segment = inet_gso_segment,
1655 .gro_receive = inet_gro_receive, 1698 .gro_receive = ipip_gro_receive,
1656 .gro_complete = inet_gro_complete, 1699 .gro_complete = ipip_gro_complete,
1657 }, 1700 },
1658}; 1701};
1659 1702