NewIP code rectification

1. The header comment contains the copyright license, feature description, author, and creation date
2. Rectification of code specification problems

Signed-off-by: liangbotong <liangbotong@huawei.com>
This commit is contained in:
liangbotong
2023-05-23 11:12:58 +08:00
parent 924323cbcc
commit 2717358eda
41 changed files with 319 additions and 106 deletions
+11 -3
View File
@@ -1,12 +1,17 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* Description: check NewIP enable.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-09-06
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
#define NIP_DISABLE_PATH ("/sys/module/newip/parameters/disable")
#define NIP_DISABLE_LENTH (5)
@@ -30,11 +35,14 @@ void _check_nip_enable(void)
return;
}
fclose(fn);
if (fclose(fn) == EOF) {
printf("fclose failed\n");
return;
}
g_nip_enable = atoi(tmp) ? 0 : 1;
}
int check_nip_enable(void)
bool check_nip_enable(void)
{
if (g_nip_enable == NIP_ENABLE_INVALID) {
_check_nip_enable();
+10 -2
View File
@@ -1,12 +1,17 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* Description: get af ninet.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-09-06
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
#define AF_NINET_PATH ("/sys/module/newip/parameters/af_ninet")
#define AF_NINET_LENTH (5)
@@ -29,7 +34,10 @@ void _get_af_ninet(void)
return;
}
fclose(fn);
if (fclose(fn) == EOF) {
printf("fclose failed\n");
return;
}
g_af_ninet = atoi(tmp);
}
+7
View File
@@ -1,6 +1,13 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* Description: Definitions for the structure
* associated with NewIP route.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-09-06
*/
#ifndef _NEWIP_ROUTE_H
#define _NEWIP_ROUTE_H
+7
View File
@@ -1,6 +1,13 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* Description: Definitions for the structure
* associated with NewIP address.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-09-06
*/
#ifndef _NIP_H
#define _NIP_H
+6 -1
View File
@@ -1,6 +1,12 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* Description: Demo example of configuring NewIP address.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-09-06
*/
#include <sys/socket.h>
#include <sys/ioctl.h>
@@ -8,7 +14,6 @@
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
#include "nip_uapi.h"
#include "nip_lib.h"
+7 -2
View File
@@ -1,6 +1,12 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* Description: Demo example of configuring NewIP address.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-07-18
*/
#include <sys/socket.h>
#include <sys/ioctl.h>
@@ -8,7 +14,6 @@
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
#include "nip_uapi.h"
#include "nip_lib.h"
@@ -29,7 +34,7 @@ int nip_add_addr(int ifindex, const unsigned char *addr, unsigned char addr_len)
return -1;
memset(&ifrn, 0, sizeof(ifrn));
ifrn.ifrn_addr.bitlen = addr_len * 8; // Byte length is converted to bit length
ifrn.ifrn_addr.bitlen = addr_len * BITS_PER_BYTE; // Byte length is converted to bit length
memcpy(ifrn.ifrn_addr.nip_addr_field8, addr, addr_len);
ifrn.ifrn_ifindex = ifindex;
+6 -1
View File
@@ -1,13 +1,18 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* Description: Provide NewIP universal library.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-07-18
*/
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
#include <linux/if.h> /* struct ifreq depend */
#include "nip_uapi.h"
+8
View File
@@ -1,6 +1,12 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* Description: Provide NewIP universal library.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-07-18
*/
#ifndef _NIP_LIB_H
#define _NIP_LIB_H
@@ -27,6 +33,8 @@
#define SELECT_TIME 600
#define TCP_SERVER_PORT 5556 /* TCP Server Port */
#define UDP_SERVER_PORT 9090 /* UDP Server Port */
#define TIMEOUT_SEC 2
#define BITS_PER_BYTE 8
#define ARRAY_LEN 255
+6 -1
View File
@@ -1,13 +1,18 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* Description: Demo example of configuring NewIP route.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-09-06
*/
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <linux/route.h>
+9 -3
View File
@@ -1,6 +1,12 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* Description: Demo example of configuring NewIP route.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-09-06
*/
#include <sys/socket.h>
#include <sys/ioctl.h>
@@ -34,11 +40,11 @@ int nip_route_add(int ifindex, const unsigned char *dst_addr, uint8_t dst_addr_l
memset(&rt, 0, sizeof(rt));
rt.rtmsg_ifindex = ifindex;
rt.rtmsg_flags = RTF_UP;
rt.rtmsg_dst.bitlen = dst_addr_len * 8;
rt.rtmsg_dst.bitlen = dst_addr_len * BITS_PER_BYTE;
memcpy(rt.rtmsg_dst.nip_addr_field8, dst_addr, dst_addr_len);
if (gateway_addr) {
rt.rtmsg_gateway.bitlen = gateway_addr_len * 8;
rt.rtmsg_gateway.bitlen = gateway_addr_len * BITS_PER_BYTE;
memcpy(rt.rtmsg_gateway.nip_addr_field8, gateway_addr, gateway_addr_len);
rt.rtmsg_flags |= RTF_GATEWAY;
}
@@ -71,7 +77,7 @@ int main(int argc, char **argv)
printf("client cfg route, dst-addr=0x%02x%02x\n",
server_addr[INDEX_0], server_addr[INDEX_1]);
dst_addr = server_addr;
dst_addr_len = 2;
dst_addr_len = INDEX_2;
} else {
printf("invalid route cfg input\n");
return -1;
+13 -5
View File
@@ -1,6 +1,12 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* Description: Demo example of NewIP tcp client.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-09-06
*/
#include <stdio.h>
#include <unistd.h>
@@ -8,9 +14,7 @@
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <errno.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include "nip_uapi.h"
#include "nip_lib.h"
@@ -24,10 +28,14 @@ int _send(int cfd, int pkt_num)
{
char buf[BUFLEN] = {0};
struct timeval sys_time;
int ret;
gettimeofday(&sys_time, NULL);
sprintf(buf, "%ld %6ld NIP_TCP # %6d", sys_time.tv_sec, sys_time.tv_usec, pkt_num);
ret = sprintf(buf, "%ld %6ld NIP_TCP # %6d", sys_time.tv_sec, sys_time.tv_usec, pkt_num);
if (ret < 0) {
printf("sprintf failed\n");
return -1;
}
if (send(cfd, buf, PKTLEN, 0) < 0) {
perror("sendto");
return -1;
@@ -45,7 +53,7 @@ int _recv(int cfd, int pkt_num, int *success)
FD_ZERO(&readfds);
FD_SET(cfd, &readfds);
tv.tv_sec = 2;
tv.tv_sec = TIMEOUT_SEC;
tv.tv_usec = 0;
if (select(cfd + 1, &readfds, NULL, NULL, &tv) < 0) {
perror("select");
+6
View File
@@ -1,6 +1,12 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* Description: Demo example of NewIP tcp server.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-09-06
*/
#include <stdio.h>
#include <unistd.h>
+7
View File
@@ -1,6 +1,13 @@
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* Description: Definitions for the structure
* associated with NewIP.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-09-06
*/
#ifndef _NIP_UAPI_H
#define _NIP_UAPI_H
+13 -4
View File
@@ -1,6 +1,12 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* Description: Demo example of NewIP udp client.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-09-06
*/
#include <stdio.h>
#include <unistd.h>
@@ -8,7 +14,6 @@
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <errno.h>
#define __USE_GNU
#include <sched.h>
@@ -23,10 +28,14 @@ int _sendto(int cfd, struct sockaddr_nin *si_server, int pkt_num)
char buf[BUFLEN] = {0};
struct timeval sys_time;
socklen_t slen = sizeof(struct sockaddr_nin);
int ret;
gettimeofday(&sys_time, NULL);
sprintf(buf, "%ld %6ld NIP_UDP # %6d", sys_time.tv_sec, sys_time.tv_usec, pkt_num);
ret = sprintf(buf, "%ld %6ld NIP_UDP # %6d", sys_time.tv_sec, sys_time.tv_usec, pkt_num);
if (ret < 0) {
printf("sprintf failed");
return -1;
}
if (sendto(cfd, buf, BUFLEN, 0, (struct sockaddr *)si_server, slen) < 0) {
printf("client sendto fail, pkt_num=%d", pkt_num);
return -1;
@@ -45,7 +54,7 @@ int _recvfrom(int cfd, struct sockaddr_nin *si_server, int pkt_num, int *success
FD_ZERO(&readfds);
FD_SET(cfd, &readfds);
tv.tv_sec = 2;
tv.tv_sec = TIMEOUT_SEC;
tv.tv_usec = 0;
if (select(cfd + 1, &readfds, NULL, NULL, &tv) < 0) {
printf("client select fail, pkt_num=%d", pkt_num);
+6
View File
@@ -1,6 +1,12 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* Description: Demo example of NewIP udp server.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-09-06
*/
#include <stdio.h>
#include <stdlib.h>
+7
View File
@@ -1,6 +1,13 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* Description: Provide operations and conversions
* related to NewIP address.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-07-18
*/
#include "nip_addr.h"
+7
View File
@@ -1,6 +1,13 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* Description: Provide operations and conversions
* related to NewIP address.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-07-18
*/
#ifndef _UAPI_NEWIP_ADDR_H
#define _UAPI_NEWIP_ADDR_H
+7
View File
@@ -1,6 +1,13 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* Description: Provides some functionalities for
* checksum calculation in the NewIP protocol.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-07-18
*/
#include "nip_hdr.h"
#include "nip_checksum.h"
+7
View File
@@ -1,6 +1,13 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* Description: Provides some functionalities for
* checksum calculation in the NewIP protocol.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-07-18
*/
#ifndef _NIP_CHECKSUM_H
#define _NIP_CHECKSUM_H
+8
View File
@@ -1,6 +1,14 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* Description: Constructs and functions are provided
* to handle encapsulation and parsing of the NewIP
* network layer protocol header.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-07-18
*/
#ifndef _NEWIP_HDR_H
#define _NEWIP_HDR_H
+7
View File
@@ -1,6 +1,13 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* Description: This file implements the function
* of decapsulating the NewIP protocol header.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-07-18
*/
#include "nip_hdr.h"
+7
View File
@@ -1,6 +1,13 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* Description: This file implements the function
* of encapsulating the NewIP protocol header.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-07-18
*/
#include "nip_hdr.h"
+31 -20
View File
@@ -727,26 +727,26 @@ static void __bt_table_delete_all(struct bt_drv *drv)
drv->devices_table->num = 0;
}
static int bt_table_delete_all(struct bt_drv *bt_drv)
static int bt_table_delete_all(struct bt_drv *drv)
{
if (unlikely(!bt_drv->devices_table))
if (unlikely(!drv->devices_table))
return -EINVAL;
mutex_lock(&bt_drv->bitmap_lock);
mutex_lock(&bt_drv->devices_table->tbl_lock);
mutex_lock(&drv->bitmap_lock);
mutex_lock(&drv->devices_table->tbl_lock);
__bt_table_delete_all(bt_drv);
__bt_table_delete_all(drv);
mutex_unlock(&bt_drv->devices_table->tbl_lock);
mutex_unlock(&bt_drv->bitmap_lock);
mutex_unlock(&drv->devices_table->tbl_lock);
mutex_unlock(&drv->bitmap_lock);
return OK;
}
static void bt_table_destroy(struct bt_drv *bt_drv)
static void bt_table_destroy(struct bt_drv *drv)
{
__bt_table_delete_all(bt_drv);
kfree(bt_drv->devices_table);
bt_drv->devices_table = NULL;
__bt_table_delete_all(drv);
kfree(drv->devices_table);
drv->devices_table = NULL;
}
static struct bt_ring *__bt_ring_create(int size)
@@ -875,19 +875,25 @@ static void bt_dev_class_destroy(struct class *cls)
class_destroy(cls);
}
static void bt_cdev_device_destroy(struct bt_cdev *dev)
{
device_destroy(dev->bt_class, dev->cdev->dev);
}
static int bt_cdev_device_create(struct bt_cdev *dev,
struct class *cls,
u32 id)
{
struct device *device = NULL;
dev_t devno = MKDEV(BT_DEV_MAJOR, id);
int ret;
if (unlikely(!cls)) {
pr_err("not a valid cls");
return -EINVAL;
}
pr_devel("bt cdev_device_create: id=%d", id);
pr_devel("bt cdev device create: id=%d", id);
dev->bt_class = cls;
@@ -896,15 +902,16 @@ static int bt_cdev_device_create(struct bt_cdev *dev,
pr_err("create device failed");
return -EIO;
}
snprintf(dev->dev_filename, sizeof(dev->dev_filename), "%s%u", BT_DEV_PATH_PREFIX, id);
ret = snprintf(dev->dev_filename, sizeof(dev->dev_filename),
"%s%u", BT_DEV_PATH_PREFIX, id);
if (ret < 0) {
pr_devel("bt cdev device create: snprintf failed\n");
bt_cdev_device_destroy(dev);
return -EFAULT;
}
return OK;
}
static void bt_cdev_device_destroy(struct bt_cdev *dev)
{
device_destroy(dev->bt_class, dev->cdev->dev);
}
static struct bt_cdev *bt_cdev_create(const struct file_operations *ops,
u32 id)
{
@@ -943,9 +950,9 @@ static struct bt_cdev *bt_cdev_create(const struct file_operations *ops,
return dev;
cdev_device_create_failed:
cdev_add_failed:
cdev_del(chrdev);
cdev_add_failed:
cdev_alloc_failed:
kfree(dev);
@@ -1085,7 +1092,11 @@ static struct net_device *bt_net_device_create(u32 id)
pr_err("bt net device create: invalid id");
return NULL;
}
snprintf(ifa_name, sizeof(ifa_name), "%s%d", BT_VIRNET_NAME_PREFIX, id);
err = snprintf(ifa_name, sizeof(ifa_name), "%s%d", BT_VIRNET_NAME_PREFIX, id);
if (err < 0) {
pr_err("bt net device create: snprintf failed");
return NULL;
}
ndev = alloc_netdev(0, ifa_name, NET_NAME_UNKNOWN, ether_setup);
if (unlikely(!ndev)) {
pr_err("alloc_netdev failed");
+5 -5
View File
@@ -225,12 +225,12 @@ static inline const char *bt_virnet_get_state_rep(const struct bt_virnet *vn)
return bt_virnet_state_rep[vn->state];
}
static inline int bt_get_total_device(const struct bt_drv *bt_drv)
static inline int bt_get_total_device(const struct bt_drv *drv)
{
if (unlikely(!bt_drv->devices_table))
if (unlikely(!drv->devices_table))
return -EINVAL;
return bt_drv->devices_table->num;
return drv->devices_table->num;
}
static inline int bt_virnet_get_ring_packets(const struct bt_virnet *vn)
@@ -251,9 +251,9 @@ static inline int bt_virnet_get_ring_packets(const struct bt_virnet *vn)
static struct bt_table *bt_table_init(void);
static int bt_table_add_device(struct bt_table *tbl, struct bt_virnet *vn);
static void bt_table_remove_device(struct bt_table *tbl, struct bt_virnet *vn);
static int bt_table_delete_all(struct bt_drv *bt_drv);
static int bt_table_delete_all(struct bt_drv *drv);
static struct bt_virnet *bt_table_find(struct bt_table *tbl, const char *ifa_name);
static void bt_table_destroy(struct bt_drv *bt_drv);
static void bt_table_destroy(struct bt_drv *drv);
static void bt_delete_io_files(struct bt_drv *bt_mng);
static struct bt_io_file **bt_create_io_files(void);
@@ -2,7 +2,12 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* Definitions for the NewIP Hooks Register module.
* Description: Definitions for the NewIP Hooks
* Register module.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-09-20
*/
#ifdef CONFIG_NEWIP_HOOKS
#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__
@@ -19,7 +24,7 @@ void vendor_ninet_ehashfn(void *data, const struct sock *sk, u32 *ret)
}
void vendor_ninet_gifconf(void *data, struct net_device *dev,
char __user *buf, int len, int size, int *ret)
char __user *buf, int len, int size, int *ret)
{
if (*ret >= 0) {
int done = ninet_gifconf(dev, buf + *ret, len - *ret, size);
@@ -2,7 +2,12 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* Definitions for the NewIP Hooks Register module.
* Description: Definitions for the NewIP Hooks
* Register module.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-09-20
*/
#ifndef _NIP_HOOKS_REGISTER_H
#define _NIP_HOOKS_REGISTER_H
@@ -7,7 +7,11 @@
* operating system. NewIP INET is implemented using the BSD Socket
* interface as the means of communication with the user level.
*
* Definitions for the NewIP parameter module.
* Description: Definitions for the NewIP parameter module.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-07-25
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__
@@ -7,7 +7,11 @@
* operating system. NewIP INET is implemented using the BSD Socket
* interface as the means of communication with the user level.
*
* Definitions for the NewIP parameter module.
* Description: Definitions for the NewIP parameter module.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-07-25
*/
#ifndef _TCP_NIP_PARAMETER_H
#define _TCP_NIP_PARAMETER_H
+1 -1
View File
@@ -13,8 +13,8 @@
#include <asm/byteorder.h>
#include <linux/libc-compat.h>
#include <linux/types.h>
#include "nip_addr.h"
#include <linux/if.h>
#include "nip_addr.h"
struct nip_ifreq {
struct nip_addr ifrn_addr;
+6 -6
View File
@@ -21,6 +21,12 @@
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__
#include <net/sock.h>
#include <net/nip.h>
#include <net/protocol.h>
#include <net/nip_route.h>
#include <net/nip_addrconf.h>
#include <net/nndisc.h>
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/types.h>
@@ -32,12 +38,6 @@
#include <linux/inet.h>
#include <linux/netdevice.h>
#include <linux/nip_icmp.h>
#include <net/sock.h>
#include <net/nip.h>
#include <net/protocol.h>
#include <net/nip_route.h>
#include <net/nip_addrconf.h>
#include <net/nndisc.h>
#include "nip_hdr.h"
#include "tcp_nip_parameter.h"
+3 -1
View File
@@ -41,6 +41,8 @@
#include <net/secure_seq.h>
#include "tcp_nip_parameter.h"
#define TCP_SEQ_SCALE_SHIFT 6
static siphash_key_t net_secret __read_mostly;
static __always_inline void net_secret_init(void)
@@ -60,7 +62,7 @@ static u32 seq_scale(u32 seq)
* overlaps less than one time per MSL (2 minutes).
* Choosing a clock of 64 ns period is OK. (period of 274 s)
*/
return seq + (ktime_get_real_ns() >> 6);
return seq + (ktime_get_real_ns() >> TCP_SEQ_SCALE_SHIFT);
}
#endif
+5 -1
View File
@@ -287,7 +287,7 @@ out_fib_table_hash:
return -ENOMEM;
}
static void nip_fib_net_exit(struct net *net)
static void __net_exit nip_fib_net_exit(struct net *net)
{
nip_fib_free_table(net->newip.nip_fib_main_tbl);
nip_fib_free_table(net->newip.nip_fib_local_tbl);
@@ -323,6 +323,10 @@ out_kmem_cache_create:
goto out;
}
/* When adding the __exit tag to a function, it is important to
* ensure that the function is only called during the exit phase
* to avoid unnecessary warnings and errors.
*/
void nip_fib_gc_cleanup(void)
{
unregister_pernet_subsys(&nip_fib_net_ops);
+1
View File
@@ -434,6 +434,7 @@ out:
return err;
out_err_release:
rcu_read_unlock();
dst_release(dst);
dst = NULL;
sk->sk_err_soft = -err;
+9 -7
View File
@@ -18,17 +18,17 @@
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__
#include <net/sock.h>
#include <net/nip.h>
#include <net/nip_udp.h>
#include <net/route.h>
#include <net/nip_fib.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/skbuff.h>
#include <linux/nip.h>
#include <linux/inetdevice.h>
#include <linux/netdevice.h>
#include <net/sock.h>
#include <net/nip.h>
#include <net/nip_udp.h>
#include <net/route.h>
#include <net/nip_fib.h>
#include "tcp_nip_parameter.h"
#define NIP_OPTNAME_MAX 255
@@ -44,8 +44,9 @@ static bool nip_setsockopt_needs_rtnl(int optname)
switch (optname) {
case IP_MSFILTER:
return true;
default:
return false;
}
return false;
}
static bool nip_getsockopt_needs_rtnl(int optname)
@@ -53,8 +54,9 @@ static bool nip_getsockopt_needs_rtnl(int optname)
switch (optname) {
case IP_MSFILTER:
return true;
default:
return false;
}
return false;
}
static int do_nip_setsockopt(struct sock *sk, int level, int optname,
+12 -12
View File
@@ -23,6 +23,18 @@
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__
#include <net/sock.h>
#include <net/nip.h>
#include <net/nip_udp.h>
#include <net/protocol.h>
#include <net/nndisc.h>
#include <net/nip_route.h>
#include <net/addrconf.h>
#include <net/nip_fib.h>
#include <net/netlink.h>
#include <net/flow.h>
#include <net/inet_common.h>
#include <net/nip_addrconf.h>
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/types.h>
@@ -35,19 +47,7 @@
#include <linux/nip.h>
#include <linux/nip_icmp.h>
#include <linux/jhash.h>
#include <net/sock.h>
#include <net/nip.h>
#include <net/nip_udp.h>
#include <net/protocol.h>
#include <net/nndisc.h>
#include <net/nip_route.h>
#include <net/addrconf.h>
#include <net/nip_fib.h>
#include <net/netlink.h>
#include <linux/rtnetlink.h>
#include <net/flow.h>
#include <net/inet_common.h>
#include <net/nip_addrconf.h>
#include <linux/newip_route.h>
#include <linux/netfilter.h>
#include "nip_hdr.h"
+4 -4
View File
@@ -16,7 +16,7 @@
* Alan Cox : Added BSD route gw semantics
* Alan Cox : Super /proc >4K
* Alan Cox : MTU in route table
* Alan Cox : MSS actually. Also added the window
* Alan Cox : MSS actually. Also added the window
* clamper.
* Sam Lantinga : Fixed route matching in rt_del()
* Alan Cox : Routing cache support.
@@ -36,7 +36,7 @@
* Olaf Erb : irtt wasn't being copied right.
* Bjorn Ekwall : Kerneld route support.
* Alan Cox : Multicast fixed (I hope)
* Pavel Krauz : Limited broadcast fixed
* Pavel Krauz : Limited broadcast fixed
* Mike McLagan : Routing by source
* Alexey Kuznetsov : End of old history. Split to fib.c and
* route.c and rewritten from scratch.
@@ -49,8 +49,8 @@
* Robert Olsson : Added rt_cache statistics
* Arnaldo C. Melo : Convert proc stuff to seq_file
* Eric Dumazet : hashed spinlocks and rt_check_expire() fixes.
* Ilia Sotnikov : Ignore TOS on PMTUD and Redirect
* Ilia Sotnikov : Removed TOS from hash calculations
* Ilia Sotnikov : Ignore TOS on PMTUD and Redirect
* Ilia Sotnikov : Removed TOS from hash calculations
*
* Based on net/ipv6/route.c
* Authors:
+22 -11
View File
@@ -41,7 +41,7 @@
* escape still
* Alan Cox : Fixed another acking RST frame bug.
* Should stop LAN workplace lockups.
* Alan Cox : Some tidyups using the new skb list
* Alan Cox : Some tidyups using the new skb list
* facilities
* Alan Cox : sk->keepopen now seems to work
* Alan Cox : Pulls options out correctly on accepts
@@ -195,7 +195,7 @@
* tcp_do_sendmsg to avoid burstiness.
* Eric Schenk : Fix fast close down bug with
* shutdown() followed by close().
* Andi Kleen : Make poll agree with SIGIO
* Andi Kleen : Make poll agree with SIGIO
* Salvatore Sanfilippo : Support SO_LINGER with linger == 1 and
* lingertime == 0 (RFC 793 ABORT Call)
* Hirokazu Takahashi : Use copy_from_user() instead of
@@ -215,7 +215,7 @@
* the TCP layer, missed a check for an
* ACK bit.
* Andi Kleen : Implemented fast path mtu discovery.
* Fixed many serious bugs in the
* Fixed many serious bugs in the
* request_sock handling and moved
* most of it into the af independent code.
* Added tail drop and some other bugfixes.
@@ -321,7 +321,7 @@
* Andi Kleen: Process packets with PSH set in the
* fast path.
* J Hadi Salim: ECN support
* Andrei Gurtov,
* Andrei Gurtov,
* Pasi Sarolahti,
* Panu Kuhlberg: Experimental audit of TCP (re)transmission
* engine. Lots of bugs are found.
@@ -402,6 +402,12 @@
#include "nip_checksum.h"
#include "tcp_nip_parameter.h"
#define TCP_HEADER_LENGTH(th) ((th)->doff << 2)
#define TCP_ACK_NUM_MULTIPLIER 20
#define TCP_WINDOW_RAISE_THRESHOLD 2
#define TCP_BACKLOG_HEADROOM (64 * 1024)
#define BYTES_PER_TCP_HEADER 4
static const struct inet_connection_sock_af_ops newip_specific;
static void tcp_nip_push(struct sock *sk, int flags, int mss_now,
@@ -740,7 +746,7 @@ static void tcp_nip_send_reset(struct sock *sk, struct sk_buff *skb)
seq = ntohl(th->ack_seq);
else
ack_seq = ntohl(th->seq) + th->syn + th->fin + skb->len -
(th->doff << 2);
TCP_HEADER_LENGTH(th);
tcp_nip_actual_send_reset(sk, skb, seq, ack_seq, 0, 1, priority);
}
@@ -1202,7 +1208,7 @@ static unsigned int tcp_xmit_size_goal(struct sock *sk, u32 mss_now,
struct tcp_sock *tp = tcp_sk(sk);
u32 new_size_goal, size_goal;
if (!large_allowed)
if (!large_allowed || !mss_now)
return mss_now;
/* Note : tcp_tso_autosize() will eventually split this later */
@@ -1382,7 +1388,8 @@ void tcp_nip_cleanup_rbuf(struct sock *sk, int copied)
if (inet_csk_ack_scheduled(sk)) {
const struct inet_connection_sock *icsk = inet_csk(sk);
if (tp->rcv_nxt - tp->rcv_wup > (get_ack_num() * 20 * icsk->icsk_ack.rcv_mss) ||
if (tp->rcv_nxt - tp->rcv_wup > (get_ack_num() *
TCP_ACK_NUM_MULTIPLIER * icsk->icsk_ack.rcv_mss) ||
/* If this read emptied read buffer, we send ACK, if
* connection is not bidirectional, user drained
* receive buffer and there was a small segment
@@ -1406,7 +1413,7 @@ void tcp_nip_cleanup_rbuf(struct sock *sk, int copied)
__u32 rcv_window_now = tcp_receive_window(tp);
/* Optimize, __nip_tcp_select_window() is not cheap. */
if (2 * rcv_window_now <= tp->window_clamp) {
if (TCP_WINDOW_RAISE_THRESHOLD * rcv_window_now <= tp->window_clamp) {
__u32 new_window = __nip_tcp_select_window(sk);
/* Send ACK now, if this read freed lots of space
@@ -1414,7 +1421,7 @@ void tcp_nip_cleanup_rbuf(struct sock *sk, int copied)
* We can advertise it now, if it is not less than current one.
* "Lots" means "at least twice" here.
*/
if (new_window && new_window >= 2 * rcv_window_now)
if (new_window && new_window >= TCP_WINDOW_RAISE_THRESHOLD * rcv_window_now)
time_to_ack = true;
}
}
@@ -1675,7 +1682,7 @@ static bool tcp_nip_add_backlog(struct sock *sk, struct sk_buff *skb)
* to reduce memory overhead, so add a little headroom here.
* Few sockets backlog are possibly concurrently non empty.
*/
limit += 64 * 1024;
limit += TCP_BACKLOG_HEADROOM;
/* In case all data was pulled from skb frags (in __pskb_pull_tail()),
* we can fix skb->truesize to its real value to avoid future drops.
@@ -1829,7 +1836,7 @@ static void tcp_nip_early_demux(struct sk_buff *skb)
return;
th = tcp_hdr(skb);
if (th->doff < sizeof(struct tcphdr) / 4)
if (th->doff < sizeof(struct tcphdr) / BYTES_PER_TCP_HEADER)
return;
sk = __ninet_lookup_established(dev_net(skb->dev), &tcp_hashinfo,
@@ -2060,6 +2067,10 @@ out_nip_tcp_protocol:
goto out;
}
/* When adding the __exit tag to a function, it is important to
* ensure that the function is only called during the exit phase
* to avoid unnecessary warnings and errors.
*/
void tcp_nip_exit(void)
{
ninet_unregister_protosw(&tcp_nip_protosw);
+7 -2
View File
@@ -48,7 +48,7 @@
* Andi Kleen: Process packets with PSH set in the
* fast path.
* J Hadi Salim: ECN support
* Andrei Gurtov,
* Andrei Gurtov,
* Pasi Sarolahti,
* Panu Kuhlberg: Experimental audit of TCP (re)transmission
* engine. Lots of bugs are found.
@@ -506,6 +506,11 @@ static void tcp_nip_data_queue(struct sock *sk, struct sk_buff *skb)
u32 cur_win = tcp_receive_window(tp);
u32 seq_max = tp->rcv_nxt + cur_win;
if (mss <= 0) {
nip_dbg("invalid parameter, mss=%u", mss);
__kfree_skb(skb);
return;
}
/* Newip Urg_ptr is disabled. Urg_ptr is used to carry the number of discarded packets */
tp->snd_up = (TCP_SKB_CB(skb)->seq - tcp_sk(sk)->rcv_nxt) / mss;
tp->snd_up = tp->snd_up > PKT_DISCARD_MAX ? 0 : tp->snd_up;
@@ -1044,7 +1049,7 @@ void tcp_nip_openreq_init_rwin(struct request_sock *req,
req->rsk_window_clamp = window_clamp ? : dst_metric(dst, RTAX_WINDOW);
/* limit the window selection if the user enforce a smaller rx buffer */
if (sk_listener->sk_userlocks & SOCK_RCVBUF_LOCK &&
if ((sk_listener->sk_userlocks & SOCK_RCVBUF_LOCK) &&
(req->rsk_window_clamp > full_space || req->rsk_window_clamp == 0))
req->rsk_window_clamp = full_space;
+11 -3
View File
@@ -26,7 +26,7 @@
* Cacophonix Gaul : draft-minshall-nagle-01
* J Hadi Salim : ECN support
*
* Based on net/ipv4/tcp_minisocks.c
* Based on net/ipv4/tcp_minisocks.c
* Authors: Ross Biro
* Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
* Mark Evans, <evansmp@uhura.aston.ac.uk>
@@ -64,6 +64,7 @@
#define OPTION_MD5 BIT(2)
#define OPTION_WSCALE BIT(3)
#define OPTION_FAST_OPEN_COOKIE BIT(8)
#define TCP_NIP_SND_NUM_MAX (~0U)
/* Store the options contained in TCP when sending TCP packets */
struct tcp_nip_out_options {
@@ -385,7 +386,7 @@ static __u16 tcp_nip_advertise_mss(struct sock *sk)
int nip_mss;
unsigned int metric = dst_metric_advmss(dst);
if (metric < mss) {
if (metric < (unsigned int)mss) {
mss = metric;
tp->advmss = mss;
}
@@ -1079,11 +1080,18 @@ static bool tcp_nip_write_xmit(struct sock *sk, unsigned int mss_now, int nonagl
struct tcp_sock *tp = tcp_sk(sk);
struct tcp_nip_common *ntp = &tcp_nip_sk(sk)->common;
struct sk_buff *skb;
u32 snd_num = get_nip_tcp_snd_win_enable() ? (ntp->nip_ssthresh / mss_now) : 0xFFFFFFFF;
u32 snd_num;
u32 last_nip_ssthresh = ntp->nip_ssthresh;
static const char * const str[] = {"can`t send pkt because no window",
"have window to send pkt"};
if (!mss_now) {
nip_dbg("invalid parameter, mss_now=%u", mss_now);
return false;
}
snd_num = get_nip_tcp_snd_win_enable() ? (ntp->nip_ssthresh / mss_now) :
TCP_NIP_SND_NUM_MAX;
tcp_nip_keepalive_enable(sk);
ntp->idle_ka_probes_out = 0;
+2 -1
View File
@@ -26,6 +26,7 @@
#include <linux/module.h>
#include "tcp_nip_parameter.h"
#define TCP_ORPHAN_RETRIES 8
/**
* tcp_nip_orphan_retries() - Returns maximal number of retries on an orphaned socket
* @sk: Pointer to the current socket.
@@ -44,7 +45,7 @@ static int tcp_nip_orphan_retries(struct sock *sk, bool alive)
* RTO of 200msec.
*/
if (retries == 0 && alive)
retries = 8;
retries = TCP_ORPHAN_RETRIES;
return retries;
}
+5 -5
View File
@@ -9,11 +9,11 @@
*
* Fixes:
* Alan Cox : verify_area() calls
* Alan Cox : stopped close while in use off icmp
* Alan Cox : stopped close while in use off icmp
* messages. Not a fix but a botch that
* for udp at least is 'valid'.
* Alan Cox : Fixed icmp handling properly
* Alan Cox : Correct error for oversized datagrams
* Alan Cox : Correct error for oversized datagrams
* Alan Cox : Tidied select() semantics.
* Alan Cox : udp_err() fixed properly, also now
* select and read wake correctly on errors
@@ -25,7 +25,7 @@
* Alan Cox : Switched to new sk_buff handlers. No more backlog!
* Alan Cox : Using generic datagram code. Even smaller and the PEEK
* bug no longer crashes it.
* Fred Van Kempen : Net2e support for sk->broadcast.
* Fred Van Kempen : Net2e support for sk->broadcast.
* Alan Cox : Uses skb_free_datagram
* Alan Cox : Added get/set sockopt support.
* Alan Cox : Broadcasting without option set returns EACCES.
@@ -37,7 +37,7 @@
* Alan Cox : Smarter af_inet used properly.
* Alan Cox : Use new kernel side addressing.
* Alan Cox : Incorrect return on truncated datagram receive.
* Arnt Gulbrandsen : New udp_send and stuff
* Arnt Gulbrandsen : New udp_send and stuff
* Alan Cox : Cache last socket
* Alan Cox : Route cache
* Jon Peatfield : Minor efficiency fix to sendto().
@@ -66,7 +66,7 @@
* Derek Atkins <derek@ihtfp.com>: Add Encapulation Support
* James Chapman : Add L2TP encapsulation type.
*
* Based on net/ipv6/udp.c
* Based on net/ipv6/udp.c
* Authors:
* Pedro Roque <roque@di.fc.ul.pt>
*