Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* drivers/atm/atmtcp.c - ATM over TCP "device" driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) /* Written 1997-2000 by Werner Almesberger, EPFL LRC/ICA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/atmdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/atm_tcp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) extern int atm_init_aal5(struct atm_vcc *vcc); /* "raw" AAL5 transport */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define PRIV(dev) ((struct atmtcp_dev_data *) ((dev)->dev_data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) struct atmtcp_dev_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	struct atm_vcc *vcc;	/* control VCC; NULL if detached */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	int persist;		/* non-zero if persistent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define DEV_LABEL    "atmtcp"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define MAX_VPI_BITS  8	/* simplifies life */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define MAX_VCI_BITS 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * Hairy code ahead: the control VCC may be closed while we're still
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * waiting for an answer, so we need to re-validate out_vcc every once
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * in a while.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static int atmtcp_send_control(struct atm_vcc *vcc,int type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)     const struct atmtcp_control *msg,int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	DECLARE_WAITQUEUE(wait,current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	struct atm_vcc *out_vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	struct atmtcp_control *new_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	int old_test;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	out_vcc = PRIV(vcc->dev) ? PRIV(vcc->dev)->vcc : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (!out_vcc) return -EUNATCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	skb = alloc_skb(sizeof(*msg),GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (!skb) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	out_vcc = PRIV(vcc->dev) ? PRIV(vcc->dev)->vcc : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	if (!out_vcc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		return -EUNATCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	atm_force_charge(out_vcc,skb->truesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	new_msg = skb_put(skb, sizeof(*new_msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	*new_msg = *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	new_msg->hdr.length = ATMTCP_HDR_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	new_msg->type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	memset(&new_msg->vcc,0,sizeof(atm_kptr_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	*(struct atm_vcc **) &new_msg->vcc = vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	old_test = test_bit(flag,&vcc->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	out_vcc->push(out_vcc,skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	add_wait_queue(sk_sleep(sk_atm(vcc)), &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	while (test_bit(flag,&vcc->flags) == old_test) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		out_vcc = PRIV(vcc->dev) ? PRIV(vcc->dev)->vcc : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		if (!out_vcc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			error = -EUNATCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		set_current_state(TASK_UNINTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	set_current_state(TASK_RUNNING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	remove_wait_queue(sk_sleep(sk_atm(vcc)), &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static int atmtcp_recv_control(const struct atmtcp_control *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	struct atm_vcc *vcc = *(struct atm_vcc **) &msg->vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	vcc->vpi = msg->addr.sap_addr.vpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	vcc->vci = msg->addr.sap_addr.vci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	vcc->qos = msg->qos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	sk_atm(vcc)->sk_err = -msg->result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	switch (msg->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	    case ATMTCP_CTRL_OPEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		change_bit(ATM_VF_READY,&vcc->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	    case ATMTCP_CTRL_CLOSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		change_bit(ATM_VF_ADDR,&vcc->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	    default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		printk(KERN_ERR "atmtcp_recv_control: unknown type %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		    msg->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	wake_up(sk_sleep(sk_atm(vcc)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static void atmtcp_v_dev_close(struct atm_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	/* Nothing.... Isn't this simple :-)  -- REW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static int atmtcp_v_open(struct atm_vcc *vcc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	struct atmtcp_control msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	short vpi = vcc->vpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	int vci = vcc->vci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	memset(&msg,0,sizeof(msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	msg.addr.sap_family = AF_ATMPVC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	msg.hdr.vpi = htons(vpi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	msg.addr.sap_addr.vpi = vpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	msg.hdr.vci = htons(vci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	msg.addr.sap_addr.vci = vci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	if (vpi == ATM_VPI_UNSPEC || vci == ATM_VCI_UNSPEC) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	msg.type = ATMTCP_CTRL_OPEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	msg.qos = vcc->qos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	set_bit(ATM_VF_ADDR,&vcc->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	clear_bit(ATM_VF_READY,&vcc->flags); /* just in case ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	error = atmtcp_send_control(vcc,ATMTCP_CTRL_OPEN,&msg,ATM_VF_READY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	if (error) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	return -sk_atm(vcc)->sk_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static void atmtcp_v_close(struct atm_vcc *vcc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	struct atmtcp_control msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	memset(&msg,0,sizeof(msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	msg.addr.sap_family = AF_ATMPVC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	msg.addr.sap_addr.vpi = vcc->vpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	msg.addr.sap_addr.vci = vcc->vci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	clear_bit(ATM_VF_READY,&vcc->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	(void) atmtcp_send_control(vcc,ATMTCP_CTRL_CLOSE,&msg,ATM_VF_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static int atmtcp_v_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	struct atm_cirange ci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	struct atm_vcc *vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	struct sock *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	if (cmd != ATM_SETCIRANGE) return -ENOIOCTLCMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	if (copy_from_user(&ci, arg,sizeof(ci))) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (ci.vpi_bits == ATM_CI_MAX) ci.vpi_bits = MAX_VPI_BITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	if (ci.vci_bits == ATM_CI_MAX) ci.vci_bits = MAX_VCI_BITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (ci.vpi_bits > MAX_VPI_BITS || ci.vpi_bits < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	    ci.vci_bits > MAX_VCI_BITS || ci.vci_bits < 0) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	read_lock(&vcc_sklist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	for(i = 0; i < VCC_HTABLE_SIZE; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		struct hlist_head *head = &vcc_hash[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		sk_for_each(s, head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 			vcc = atm_sk(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 			if (vcc->dev != dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 			if ((vcc->vpi >> ci.vpi_bits) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			    (vcc->vci >> ci.vci_bits)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 				read_unlock(&vcc_sklist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 				return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	read_unlock(&vcc_sklist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	dev->ci_range = ci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	struct atmtcp_dev_data *dev_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	struct atm_vcc *out_vcc=NULL; /* Initializer quietens GCC warning */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	struct sk_buff *new_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	struct atmtcp_hdr *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	if (vcc->qos.txtp.traffic_class == ATM_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		if (vcc->pop) vcc->pop(vcc,skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		else dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	dev_data = PRIV(vcc->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	if (dev_data) out_vcc = dev_data->vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	if (!dev_data || !out_vcc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		if (vcc->pop) vcc->pop(vcc,skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		else dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		if (dev_data) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		atomic_inc(&vcc->stats->tx_err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		return -ENOLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	size = skb->len+sizeof(struct atmtcp_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	new_skb = atm_alloc_charge(out_vcc,size,GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	if (!new_skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		if (vcc->pop) vcc->pop(vcc,skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		else dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		atomic_inc(&vcc->stats->tx_err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	hdr = skb_put(new_skb, sizeof(struct atmtcp_hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	hdr->vpi = htons(vcc->vpi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	hdr->vci = htons(vcc->vci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	hdr->length = htonl(skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	if (vcc->pop) vcc->pop(vcc,skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	else dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	out_vcc->push(out_vcc,new_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	atomic_inc(&vcc->stats->tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	atomic_inc(&out_vcc->stats->rx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static int atmtcp_v_proc(struct atm_dev *dev,loff_t *pos,char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	struct atmtcp_dev_data *dev_data = PRIV(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	if (*pos) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	if (!dev_data->persist) return sprintf(page,"ephemeral\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	return sprintf(page,"persistent, %sconnected\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	    dev_data->vcc ? "" : "dis");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static void atmtcp_c_close(struct atm_vcc *vcc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	struct atm_dev *atmtcp_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	struct atmtcp_dev_data *dev_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	atmtcp_dev = (struct atm_dev *) vcc->dev_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	dev_data = PRIV(atmtcp_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	dev_data->vcc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	if (dev_data->persist) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	atmtcp_dev->dev_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	kfree(dev_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	atm_dev_deregister(atmtcp_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	vcc->dev_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	module_put(THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static struct atm_vcc *find_vcc(struct atm_dev *dev, short vpi, int vci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)         struct hlist_head *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)         struct atm_vcc *vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)         struct sock *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)         head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	sk_for_each(s, head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)                 vcc = atm_sk(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)                 if (vcc->dev == dev &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)                     vcc->vci == vci && vcc->vpi == vpi &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)                     vcc->qos.rxtp.traffic_class != ATM_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)                                 return vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)                 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)         return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	struct atm_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	struct atmtcp_hdr *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	struct atm_vcc *out_vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	struct sk_buff *new_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	int result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	if (!skb->len) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	dev = vcc->dev_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	hdr = (struct atmtcp_hdr *) skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	if (hdr->length == ATMTCP_HDR_MAGIC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		result = atmtcp_recv_control(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		    (struct atmtcp_control *) skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	read_lock(&vcc_sklist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	read_unlock(&vcc_sklist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	if (!out_vcc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		result = -EUNATCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		atomic_inc(&vcc->stats->tx_err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	skb_pull(skb,sizeof(struct atmtcp_hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	new_skb = atm_alloc_charge(out_vcc,skb->len,GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	if (!new_skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		result = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	__net_timestamp(new_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	out_vcc->push(out_vcc,new_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	atomic_inc(&vcc->stats->tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	atomic_inc(&out_vcc->stats->rx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	if (vcc->pop) vcc->pop(vcc,skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	else dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)  * Device operations for the virtual ATM devices created by ATMTCP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) static const struct atmdev_ops atmtcp_v_dev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	.dev_close	= atmtcp_v_dev_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	.open		= atmtcp_v_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	.close		= atmtcp_v_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	.ioctl		= atmtcp_v_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	.send		= atmtcp_v_send,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	.proc_read	= atmtcp_v_proc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	.owner		= THIS_MODULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)  * Device operations for the ATMTCP control device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) static const struct atmdev_ops atmtcp_c_dev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	.close		= atmtcp_c_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	.send		= atmtcp_c_send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) static struct atm_dev atmtcp_control_dev = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	.ops		= &atmtcp_c_dev_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	.type		= "atmtcp",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	.number		= 999,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	.lock		= __SPIN_LOCK_UNLOCKED(atmtcp_control_dev.lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) static int atmtcp_create(int itf,int persist,struct atm_dev **result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	struct atmtcp_dev_data *dev_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	struct atm_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	dev_data = kmalloc(sizeof(*dev_data),GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	if (!dev_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	dev = atm_dev_register(DEV_LABEL,NULL,&atmtcp_v_dev_ops,itf,NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	if (!dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		kfree(dev_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		return itf == -1 ? -ENOMEM : -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	dev->ci_range.vpi_bits = MAX_VPI_BITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	dev->ci_range.vci_bits = MAX_VCI_BITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	dev->dev_data = dev_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	PRIV(dev)->vcc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	PRIV(dev)->persist = persist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	if (result) *result = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) static int atmtcp_attach(struct atm_vcc *vcc,int itf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	struct atm_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	if (itf != -1) dev = atm_dev_lookup(itf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	if (dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		if (dev->ops != &atmtcp_v_dev_ops) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 			atm_dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 			return -EMEDIUMTYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		if (PRIV(dev)->vcc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 			atm_dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 			return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		error = atmtcp_create(itf,0,&dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		if (error) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	PRIV(dev)->vcc = vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	vcc->dev = &atmtcp_control_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	vcc_insert_socket(sk_atm(vcc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	set_bit(ATM_VF_META,&vcc->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	set_bit(ATM_VF_READY,&vcc->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	vcc->dev_data = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	(void) atm_init_aal5(vcc); /* @@@ losing AAL in transit ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	vcc->stats = &atmtcp_control_dev.stats.aal5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	return dev->number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) static int atmtcp_create_persistent(int itf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	return atmtcp_create(itf,1,NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) static int atmtcp_remove_persistent(int itf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	struct atm_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	struct atmtcp_dev_data *dev_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	dev = atm_dev_lookup(itf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	if (!dev) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	if (dev->ops != &atmtcp_v_dev_ops) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		atm_dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 		return -EMEDIUMTYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	dev_data = PRIV(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	if (!dev_data->persist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		atm_dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	dev_data->persist = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	if (PRIV(dev)->vcc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		atm_dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	kfree(dev_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	atm_dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	atm_dev_deregister(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) static int atmtcp_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	struct atm_vcc *vcc = ATM_SD(sock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	if (cmd != SIOCSIFATMTCP && cmd != ATMTCP_CREATE && cmd != ATMTCP_REMOVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		return -ENOIOCTLCMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	if (!capable(CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		case SIOCSIFATMTCP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 			err = atmtcp_attach(vcc, (int) arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 			if (err >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 				sock->state = SS_CONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 				__module_get(THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		case ATMTCP_CREATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 			err = atmtcp_create_persistent((int) arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		case ATMTCP_REMOVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 			err = atmtcp_remove_persistent((int) arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) static struct atm_ioctl atmtcp_ioctl_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	.owner 	= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	.ioctl	= atmtcp_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) static __init int atmtcp_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	register_atm_ioctl(&atmtcp_ioctl_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) static void __exit atmtcp_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	deregister_atm_ioctl(&atmtcp_ioctl_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) module_init(atmtcp_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) module_exit(atmtcp_exit);