NewIP code problem modification

1.Add the log information about the NewIP route exception branch
2.Code specification check and rectify

Signed-off-by: liangbotong <liangbotong@huawei.com>
This commit is contained in:
liangbotong
2023-06-19 10:48:32 +08:00
parent e07521c607
commit 15037e930b
7 changed files with 47 additions and 38 deletions
+8 -8
View File
@@ -128,13 +128,13 @@ static inline int is_public_addr_flag(unsigned char first_byte)
return first_byte == ADDR_FIRST_FF ? NIP_TRUE : NIP_FALSE;
}
int is_nip_local_addr(const struct nip_addr *ad)
int is_nip_local_addr(const struct nip_addr *addr)
{
int result = 0;
if (ad->bitlen == NIP_ADDR_BIT_LEN_16) {
if (ad->nip_addr_field16[0] == nip_local_addr.nip_addr_field16[0] &&
ad->nip_addr_field16[1] == nip_local_addr.nip_addr_field16[1])
if (addr->bitlen == NIP_ADDR_BIT_LEN_16) {
if (addr->nip_addr_field16[0] == nip_local_addr.nip_addr_field16[0] &&
addr->nip_addr_field16[1] == nip_local_addr.nip_addr_field16[1])
result = 1;
}
return result;
@@ -353,13 +353,13 @@ int nip_addr_public(const struct nip_addr *addr)
}
/* judge whether the nip_addr is equal to 0xFF09 */
int nip_addr_any(const struct nip_addr *ad)
int nip_addr_any(const struct nip_addr *addr)
{
int result = 0;
if (ad->bitlen == NIP_ADDR_BIT_LEN_16) {
if (ad->nip_addr_field16[0] == nip_any_addr.nip_addr_field16[0] &&
ad->nip_addr_field16[1] == nip_any_addr.nip_addr_field16[1])
if (addr->bitlen == NIP_ADDR_BIT_LEN_16) {
if (addr->nip_addr_field16[0] == nip_any_addr.nip_addr_field16[0] &&
addr->nip_addr_field16[1] == nip_any_addr.nip_addr_field16[1])
result = 1;
}
return result;
+1 -1
View File
@@ -111,7 +111,7 @@ extern const struct nip_addr nip_broadcast_addr_arp;
int nip_addr_invalid(const struct nip_addr *addr);
int nip_addr_public(const struct nip_addr *addr);
int nip_addr_any(const struct nip_addr *ad);
int nip_addr_any(const struct nip_addr *addr);
int get_nip_addr_len(const struct nip_addr *addr);
unsigned char *build_nip_addr(const struct nip_addr *addr, unsigned char *buf);
unsigned char *decode_nip_addr(unsigned char *buf, struct nip_addr *addr);
+2 -2
View File
@@ -707,7 +707,6 @@ static struct bt_virnet *bt_table_find(struct bt_table *tbl, const char *ifa_nam
static void __bt_table_delete_all(struct bt_drv *drv)
{
int err;
dev_t number;
struct bt_virnet *vnet = NULL, *tmp_vnet = NULL;
@@ -718,7 +717,8 @@ static void __bt_table_delete_all(struct bt_drv *drv)
tmp_vnet,
&drv->devices_table->head,
virnet_entry) {
err = bt_virnet_get_cdev_number(vnet, &number);
int err = bt_virnet_get_cdev_number(vnet, &number);
if (likely(!err))
bt_clear_bit(&drv->bitmap, (u32)MINOR(number));
list_del(&vnet->virnet_entry);
+1 -1
View File
@@ -546,7 +546,7 @@ static int __ninet_ioctl_cmd(struct socket *sock, unsigned int cmd,
int ninet_ioctl_cmd(struct socket *sock, const struct iovec *iov)
{
char ioctl_flag[NINET_IOCTL_FLAG_LEN] = NINET_IOCTL_FLAG_VALUE;
const char ioctl_flag[NINET_IOCTL_FLAG_LEN] = NINET_IOCTL_FLAG_VALUE;
char ioctl_head[NINET_IOCTL_HEAD_LEN];
int i;
unsigned int cmd;
+1 -1
View File
@@ -557,7 +557,7 @@ static int nip_addrconf_notify(struct notifier_block *this, unsigned long event,
/* allocate new idev */
idev = nip_add_dev(dev);
if (IS_ERR(idev))
if (IS_ERR_OR_NULL(idev))
break;
/* device is still not ready */
+32 -22
View File
@@ -108,10 +108,31 @@ struct nip_fib_node *nip_fib_locate(struct hlist_head *nip_tb_head,
return NULL;
}
static bool is_nip_route_exist(const struct hlist_head *h, const struct nip_rt_info *rt,
u8 table_id)
{
struct nip_fib_node *fib_node;
hlist_for_each_entry(fib_node, h, fib_hlist) {
if (table_id == NIP_RT_TABLE_MAIN) {
if (nip_addr_eq(&fib_node->nip_route_info->rt_dst,
&rt->rt_dst))
return true;
} else if (table_id == NIP_RT_TABLE_LOCAL) {
if (nip_addr_and_ifindex_eq
(&fib_node->nip_route_info->rt_dst, &rt->rt_dst,
fib_node->nip_route_info->rt_idev->dev->ifindex,
rt->rt_idev->dev->ifindex))
return true;
}
}
return false;
}
/* nip_tb_lock must be taken to avoid racing */
int nip_fib_add(struct nip_fib_table *table, struct nip_rt_info *rt)
{
struct nip_fib_node *fib_node, *new_node;
struct nip_fib_node *new_node;
int err = 0;
struct hlist_head *h;
unsigned int hash;
@@ -121,22 +142,16 @@ int nip_fib_add(struct nip_fib_table *table, struct nip_rt_info *rt)
hash = ninet_route_hash(&rt->rt_dst);
h = &table->nip_tb_head[hash];
hlist_for_each_entry(fib_node, h, fib_hlist) {
if (table->nip_tb_id == NIP_RT_TABLE_MAIN) {
if (nip_addr_eq(&fib_node->nip_route_info->rt_dst,
&rt->rt_dst)) {
err = -EEXIST;
goto fail;
}
} else if (table->nip_tb_id == NIP_RT_TABLE_LOCAL) {
if (nip_addr_and_ifindex_eq
(&fib_node->nip_route_info->rt_dst, &rt->rt_dst,
fib_node->nip_route_info->rt_idev->dev->ifindex,
rt->rt_idev->dev->ifindex)) {
err = -EEXIST;
goto fail;
}
}
nip_addr_to_str(&rt->rt_dst, dst, NIP_ADDR_BIT_LEN_MAX);
nip_addr_to_str(&rt->gateway, gateway, NIP_ADDR_BIT_LEN_MAX);
nip_dbg("%s ifindex=%u (addr=%s, gateway=%s, rt_idev->refcnt=%u)",
rt->rt_idev->dev->name, rt->rt_idev->dev->ifindex,
dst, gateway, refcount_read(&rt->rt_idev->refcnt));
if (is_nip_route_exist(h, rt, table->nip_tb_id)) {
err = -EEXIST;
nip_dbg("File exists");
goto fail;
}
new_node = nip_node_alloc();
@@ -149,11 +164,6 @@ int nip_fib_add(struct nip_fib_table *table, struct nip_rt_info *rt)
rcu_assign_pointer(rt->rt_node, new_node);
atomic_inc(&rt->rt_ref);
hlist_add_tail_rcu(&new_node->fib_hlist, h);
nip_addr_to_str(&rt->rt_dst, dst, NIP_ADDR_BIT_LEN_MAX);
nip_addr_to_str(&rt->gateway, gateway, NIP_ADDR_BIT_LEN_MAX);
nip_dbg("%s ifindex=%u (addr=%s, gateway=%s, rt_idev->refcnt=%u)",
rt->rt_idev->dev->name, rt->rt_idev->dev->ifindex,
dst, gateway, refcount_read(&rt->rt_idev->refcnt));
out:
return err;
+2 -3
View File
@@ -145,10 +145,9 @@ static void tcp_nip_event_new_data_sent(struct sock *sk, struct sk_buff *skb)
/* check probe0 timer */
static void tcp_nip_check_probe_timer(struct sock *sk)
{
unsigned long when;
if (!tcp_sk(sk)->packets_out && !inet_csk(sk)->icsk_pending) {
when = tcp_probe0_base(sk);
unsigned long when = tcp_probe0_base(sk);
nip_dbg("start probe0 timer, when=%lu, RTO MAX=%u", when, TCP_RTO_MAX);
inet_csk_reset_xmit_timer(sk, ICSK_TIME_PROBE0, when, TCP_RTO_MAX);
} else if (inet_csk(sk)->icsk_pending != ICSK_TIME_PROBE0) {