Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

兼容 4.17 以上内核 #3

Merged
merged 1 commit into from
Feb 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/toa.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,15 @@ static void *get_toa_data(struct sk_buff *skb)
* try to get local address
* @return return what the original inet_getname() returns.
*/
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,17,0)
static int
inet_getname_toa(struct socket *sock, struct sockaddr *uaddr,
int peer)
#else
static int
inet_getname_toa(struct socket *sock, struct sockaddr *uaddr,
int *uaddr_len, int peer)
#endif
{
int retval = 0;
struct sock *sk = sock->sk;
Expand All @@ -111,10 +117,18 @@ inet_getname_toa(struct socket *sock, struct sockaddr *uaddr,
sk->sk_user_data);

/* call orginal one */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,17,0)
retval = inet_getname(sock, uaddr, peer);
#else
retval = inet_getname(sock, uaddr, uaddr_len, peer);
#endif

/* set our value if need */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,17,0)
if (retval > 0 && NULL != sk->sk_user_data && peer) {
#else
if (retval == 0 && NULL != sk->sk_user_data && peer) {
#endif
if (sk_data_ready_addr == (unsigned long) sk->sk_data_ready) {
memcpy(&tdata, &sk->sk_user_data, sizeof(tdata));
if (TCPOPT_TOA == tdata.opcode &&
Expand Down Expand Up @@ -148,9 +162,15 @@ inet_getname_toa(struct socket *sock, struct sockaddr *uaddr,
}

#ifdef CONFIG_IP_VS_TOA_IPV6
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,17,0)
static int
inet6_getname_toa(struct socket *sock, struct sockaddr *uaddr,
int peer)
#else
static int
inet6_getname_toa(struct socket *sock, struct sockaddr *uaddr,
int *uaddr_len, int peer)
#endif
{
int retval = 0;
struct sock *sk = sock->sk;
Expand All @@ -161,10 +181,18 @@ inet6_getname_toa(struct socket *sock, struct sockaddr *uaddr,
sk->sk_user_data);

/* call orginal one */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,17,0)
retval = inet6_getname(sock, uaddr, peer);
#else
retval = inet6_getname(sock, uaddr, uaddr_len, peer);
#endif

/* set our value if need */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,17,0)
if (retval > 0 && NULL != sk->sk_user_data && peer) {
#else
if (retval == 0 && NULL != sk->sk_user_data && peer) {
#endif
if (sk_data_ready_addr == (unsigned long) sk->sk_data_ready) {
memcpy(&tdata, &sk->sk_user_data, sizeof(tdata));
if (TCPOPT_TOA == tdata.opcode &&
Expand Down