diff --git a/newip/third_party/linux-5.10/include/net/nip.h b/newip/third_party/linux-5.10/include/net/nip.h index 3b6777b..236ba3a 100644 --- a/newip/third_party/linux-5.10/include/net/nip.h +++ b/newip/third_party/linux-5.10/include/net/nip.h @@ -133,6 +133,10 @@ int nip_setsockopt(struct sock *sk, int level, int optname, sockptr_t optval, unsigned int optlen); int nip_getsockopt(struct sock *sk, int level, int optname, char __user *optval, int __user *optlen); +void nip_sock_debug(const struct sock *sk, const char *name, int state); +void nip_sock_debug_output(const struct nip_addr *nip_daddr, const struct nip_addr *nip_saddr, + __be16 dport, __be16 sport, + const char *name, int state); /* functions defined in nip_addrconf.c */ int nip_addrconf_get_ifaddr(struct net *net, unsigned int cmd, void __user *arg); diff --git a/newip/third_party/linux-5.10/net/newip/nip_sockglue.c b/newip/third_party/linux-5.10/net/newip/nip_sockglue.c index 390c85b..f3f7ac9 100644 --- a/newip/third_party/linux-5.10/net/newip/nip_sockglue.c +++ b/newip/third_party/linux-5.10/net/newip/nip_sockglue.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -177,3 +178,31 @@ int nip_getsockopt(struct sock *sk, int level, return do_nip_getsockopt(sk, level, optname, optval, optlen); } +void nip_sock_debug_output(const struct nip_addr *nip_daddr, const struct nip_addr *nip_saddr, + __be16 dport, __be16 sport, + const char *name, int state) +{ + if (get_nip_debug()) { + char saddr[NIP_ADDR_BIT_LEN_MAX] = {0}; + char daddr[NIP_ADDR_BIT_LEN_MAX] = {0}; + + nip_addr_to_str(nip_daddr, daddr, NIP_ADDR_BIT_LEN_MAX); + nip_addr_to_str(nip_saddr, saddr, NIP_ADDR_BIT_LEN_MAX); + + nip_dbg("%s :%s (saddr=%s, daddr=%s, sport=%u, dport=%u)", + name, state ? "success" : "failed", saddr, daddr, + ntohs(sport), ntohs(dport)); + } +} + +void nip_sock_debug(const struct sock *sk, const char *name, int state) +{ + if (sk) { + struct inet_sock *inet = inet_sk(sk); + + nip_sock_debug_output(&sk->SK_NIP_DADDR, &sk->SK_NIP_RCV_SADDR, + inet->inet_dport, inet->inet_sport, + name, state); + } +} + diff --git a/newip/third_party/linux-5.10/net/newip/tcp_nip.c b/newip/third_party/linux-5.10/net/newip/tcp_nip.c index 63e2ff5..f01eac4 100644 --- a/newip/third_party/linux-5.10/net/newip/tcp_nip.c +++ b/newip/third_party/linux-5.10/net/newip/tcp_nip.c @@ -407,6 +407,8 @@ #define TCP_WINDOW_RAISE_THRESHOLD 2 #define TCP_BACKLOG_HEADROOM (64 * 1024) #define BYTES_PER_TCP_HEADER 4 +#define TRUE 1 +#define FALSE 0 static const struct inet_connection_sock_af_ops newip_specific; @@ -523,6 +525,7 @@ void tcp_nip_close(struct sock *sk, long timeout) if (data_was_unread) { tcp_set_state(sk, TCP_CLOSE); + nip_sock_debug(sk, __func__, TRUE); tcp_nip_send_active_reset(sk, sk->sk_allocation); } else if (tcp_nip_close_state(sk)) { /* RED-PEN. Formally speaking, we have broken TCP state @@ -533,6 +536,7 @@ void tcp_nip_close(struct sock *sk, long timeout) * TCP_CLOSE_WAIT -> TCP_LAST_ACK */ nip_dbg("ready to send fin, sk_state=%d", sk->sk_state); + nip_sock_debug(sk, __func__, TRUE); tcp_nip_send_fin(sk); } @@ -718,13 +722,16 @@ static int tcp_nip_connect(struct sock *sk, struct sockaddr *uaddr, err = __tcp_nip_connect(sk); if (err) goto late_failure; - + nip_sock_debug(sk, __func__, TRUE); return 0; /* failure after tcp_set_state(sk, TCP_SYN_SENT) */ late_failure: tcp_set_state(sk, TCP_CLOSE); failure: + nip_sock_debug_output(&usin->sin_addr, &sk->SK_NIP_RCV_SADDR, + usin->sin_port, inet->inet_sport, + __func__, FALSE); sk->sk_route_caps = 0; inet->inet_dport = 0; return err; @@ -1713,7 +1720,7 @@ static int tcp_nip_rcv(struct sk_buff *skb) { const struct tcphdr *th; bool refcounted; - struct sock *sk; + struct sock *sk = NULL; int ret; int dif = skb->skb_iif; @@ -1814,13 +1821,15 @@ put_and_return: no_tcp_socket: tcp_nip_send_reset(NULL, skb); - goto discard_it; + discard_it: kfree_skb(skb); + nip_sock_debug(sk, __func__, FALSE); return 0; discard_and_relse: sk_drops_add(sk, skb); + nip_sock_debug(sk, __func__, FALSE); if (refcounted) sock_put(sk); goto discard_it;