Skip to content
Open
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions include/hamradio_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#ifndef _MOD_ORPHAN_COMPAT_H
#define _MOD_ORPHAN_COMPAT_H

#include <linux/version.h>
#include <linux/slab.h>
#include <linux/overflow.h>

Expand Down Expand Up @@ -35,4 +36,12 @@

#endif /* __alloc_objs */

/*
* struct sockaddr_unsized was introduced in Linux 7.0 to replace struct sockaddr
* in proto_ops .bind/.connect callbacks. Map it to struct sockaddr on older kernels.
*/
#if LINUX_VERSION_CODE < KERNEL_VERSION(7, 0, 0)
#define sockaddr_unsized sockaddr
#endif

#endif /* _MOD_ORPHAN_COMPAT_H */
2 changes: 2 additions & 0 deletions net/rose/Kbuild
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# SPDX-License-Identifier: GPL-2.0

ccflags-y += -include $(src)/../../include/hamradio_compat.h

obj-m += rose.o

rose-y := af_rose.o rose_dev.o rose_in.o rose_link.o rose_loopback.o \
Expand Down
6 changes: 6 additions & 0 deletions net/rose/rose_in.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ static int rose_state1_machine(struct sock *sk, struct sk_buff *skb, int framety
rose_write_internal(sk, ROSE_CLEAR_CONFIRMATION);
rose_disconnect(sk, ECONNREFUSED, skb->data[3], skb->data[4]);
rose_neigh_put(rose->neighbour);
rose->neighbour = NULL;
break;

default:
Expand All @@ -80,11 +81,13 @@ static int rose_state2_machine(struct sock *sk, struct sk_buff *skb, int framety
rose_write_internal(sk, ROSE_CLEAR_CONFIRMATION);
rose_disconnect(sk, 0, skb->data[3], skb->data[4]);
rose_neigh_put(rose->neighbour);
rose->neighbour = NULL;
break;

case ROSE_CLEAR_CONFIRMATION:
rose_disconnect(sk, 0, -1, -1);
rose_neigh_put(rose->neighbour);
rose->neighbour = NULL;
break;

default:
Expand Down Expand Up @@ -121,6 +124,7 @@ static int rose_state3_machine(struct sock *sk, struct sk_buff *skb, int framety
rose_write_internal(sk, ROSE_CLEAR_CONFIRMATION);
rose_disconnect(sk, 0, skb->data[3], skb->data[4]);
rose_neigh_put(rose->neighbour);
rose->neighbour = NULL;
break;

case ROSE_RR:
Expand Down Expand Up @@ -234,6 +238,7 @@ static int rose_state4_machine(struct sock *sk, struct sk_buff *skb, int framety
rose_write_internal(sk, ROSE_CLEAR_CONFIRMATION);
rose_disconnect(sk, 0, skb->data[3], skb->data[4]);
rose_neigh_put(rose->neighbour);
rose->neighbour = NULL;
break;

default:
Expand All @@ -254,6 +259,7 @@ static int rose_state5_machine(struct sock *sk, struct sk_buff *skb, int framety
rose_write_internal(sk, ROSE_CLEAR_CONFIRMATION);
rose_disconnect(sk, 0, skb->data[3], skb->data[4]);
rose_neigh_put(rose_sk(sk)->neighbour);
rose_sk(sk)->neighbour = NULL;
}

return 0;
Expand Down
53 changes: 36 additions & 17 deletions net/rose/rose_loopback.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
#include <net/rose.h>
#include <linux/init.h>

static struct sk_buff_head loopback_queue;
#define ROSE_LOOPBACK_LIMIT 1000
static struct timer_list loopback_timer;

static struct timer_list loopback_timer;
static struct sk_buff_head loopback_queue;
static void rose_set_loopback_timer(void);
static void rose_loopback_timer(struct timer_list *unused);

static atomic_t loopback_stopping = ATOMIC_INIT(0);

void rose_loopback_init(void)
{
skb_queue_head_init(&loopback_queue);
Expand Down Expand Up @@ -66,10 +68,25 @@ static void rose_loopback_timer(struct timer_list *unused)
unsigned int lci_i, lci_o;
int count;

if (atomic_read(&loopback_stopping))
return;

if (rose_loopback_neigh)
rose_neigh_hold(rose_loopback_neigh);
else
return;

for (count = 0; count < ROSE_LOOPBACK_LIMIT; count++) {
skb = skb_dequeue(&loopback_queue);
if (!skb)
return;
goto out;

if (atomic_read(&loopback_stopping)) {
kfree_skb(skb);
skb_queue_purge(&loopback_queue);
goto out;
}

if (skb->len < ROSE_MIN_LEN) {
kfree_skb(skb);
continue;
Expand All @@ -96,38 +113,40 @@ static void rose_loopback_timer(struct timer_list *unused)
}

if (frametype == ROSE_CALL_REQUEST) {
if (!rose_loopback_neigh->dev &&
!rose_loopback_neigh->loopback) {
kfree_skb(skb);
continue;
}

dev = rose_dev_get(dest);
if (!dev) {
kfree_skb(skb);
continue;
}

if (rose_rx_call_request(skb, dev, rose_loopback_neigh, lci_o) == 0) {
dev_put(dev);
if (rose_rx_call_request(skb, dev, rose_loopback_neigh, lci_o) == 0)
kfree_skb(skb);
}
dev_put(dev);
} else {
kfree_skb(skb);
}
}
if (!skb_queue_empty(&loopback_queue))

out:
rose_neigh_put(rose_loopback_neigh);

if (!atomic_read(&loopback_stopping) && !skb_queue_empty(&loopback_queue))
mod_timer(&loopback_timer, jiffies + 1);
}

void __exit rose_loopback_clear(void)
{
struct sk_buff *skb;

timer_delete(&loopback_timer);
atomic_set(&loopback_stopping, 1);
/* Pairs with atomic_read() in rose_loopback_timer(): ensure the
* stopping flag is visible before we cancel, so a concurrent
* callback aborts its loop early rather than re-arming the timer.
*/
smp_mb();

while ((skb = skb_dequeue(&loopback_queue)) != NULL) {
skb->sk = NULL;
timer_delete_sync(&loopback_timer);

while ((skb = skb_dequeue(&loopback_queue)) != NULL)
kfree_skb(skb);
}
}
5 changes: 4 additions & 1 deletion net/rose/rose_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ static void rose_timer_expiry(struct timer_list *t)
break;

case ROSE_STATE_2: /* T3 */
rose_neigh_put(rose->neighbour);
if (rose->neighbour) {
rose_neigh_put(rose->neighbour);
rose->neighbour = NULL;
}
rose_disconnect(sk, ETIMEDOUT, -1, -1);
break;

Expand Down