Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * X.25 Packet Layer release 002 |
| 3 | * |
| 4 | * This is ALPHA test software. This code may break your machine, |
| 5 | * randomly fail to work with new releases, misbehave and/or generally |
YOSHIFUJI Hideaki | f8e1d201 | 2007-02-09 23:25:27 +0900 | [diff] [blame] | 6 | * screw up. It might even work. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * This code REQUIRES 2.1.15 or higher |
| 9 | * |
| 10 | * This module: |
| 11 | * This module is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License |
| 13 | * as published by the Free Software Foundation; either version |
| 14 | * 2 of the License, or (at your option) any later version. |
| 15 | * |
| 16 | * History |
| 17 | * X.25 001 Jonathan Naylor Started coding. |
| 18 | * X.25 002 Jonathan Naylor Centralised disconnect handling. |
| 19 | * New timer architecture. |
| 20 | * 2000-03-11 Henner Eisen MSG_EOR handling more POSIX compliant. |
YOSHIFUJI Hideaki | f8e1d201 | 2007-02-09 23:25:27 +0900 | [diff] [blame] | 21 | * 2000-03-22 Daniela Squassoni Allowed disabling/enabling of |
| 22 | * facilities negotiation and increased |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | * the throughput upper limit. |
| 24 | * 2000-08-27 Arnaldo C. Melo s/suser/capable/ + micro cleanups |
YOSHIFUJI Hideaki | f8e1d201 | 2007-02-09 23:25:27 +0900 | [diff] [blame] | 25 | * 2000-09-04 Henner Eisen Set sock->state in x25_accept(). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | * Fixed x25_output() related skb leakage. |
| 27 | * 2000-10-02 Henner Eisen Made x25_kick() single threaded per socket. |
| 28 | * 2000-10-27 Henner Eisen MSG_DONTWAIT for fragment allocation. |
| 29 | * 2000-11-14 Henner Eisen Closing datalink from NETDEV_GOING_DOWN |
| 30 | * 2002-10-06 Arnaldo C. Melo Get rid of cli/sti, move proc stuff to |
| 31 | * x25_proc.c, using seq_file |
Shaun Pereira | cb65d50 | 2005-06-22 22:15:01 -0700 | [diff] [blame] | 32 | * 2005-04-02 Shaun Pereira Selective sub address matching |
| 33 | * with call user data |
Shaun Pereira | ebc3f64 | 2005-06-22 22:16:17 -0700 | [diff] [blame] | 34 | * 2005-04-15 Shaun Pereira Fast select with no restriction on |
| 35 | * response |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | */ |
| 37 | |
wangweidong | b73e9e3 | 2013-12-06 19:24:33 +0800 | [diff] [blame] | 38 | #define pr_fmt(fmt) "X25: " fmt |
| 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <linux/module.h> |
Randy Dunlap | 4fc268d | 2006-01-11 12:17:47 -0800 | [diff] [blame] | 41 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/errno.h> |
| 43 | #include <linux/kernel.h> |
| 44 | #include <linux/sched.h> |
| 45 | #include <linux/timer.h> |
| 46 | #include <linux/string.h> |
| 47 | #include <linux/net.h> |
| 48 | #include <linux/netdevice.h> |
| 49 | #include <linux/if_arp.h> |
| 50 | #include <linux/skbuff.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 51 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <net/sock.h> |
Arnaldo Carvalho de Melo | c752f07 | 2005-08-09 20:08:28 -0700 | [diff] [blame] | 53 | #include <net/tcp_states.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #include <asm/uaccess.h> |
| 55 | #include <linux/fcntl.h> |
| 56 | #include <linux/termios.h> /* For TIOCINQ/OUTQ */ |
| 57 | #include <linux/notifier.h> |
| 58 | #include <linux/init.h> |
Shaun Pereira | 1b06e6b | 2006-03-22 00:00:12 -0800 | [diff] [blame] | 59 | #include <linux/compat.h> |
andrew hendry | a928852 | 2010-02-14 02:00:45 +0000 | [diff] [blame] | 60 | #include <linux/ctype.h> |
Shaun Pereira | 1b06e6b | 2006-03-22 00:00:12 -0800 | [diff] [blame] | 61 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #include <net/x25.h> |
Shaun Pereira | 1b06e6b | 2006-03-22 00:00:12 -0800 | [diff] [blame] | 63 | #include <net/compat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
| 65 | int sysctl_x25_restart_request_timeout = X25_DEFAULT_T20; |
| 66 | int sysctl_x25_call_request_timeout = X25_DEFAULT_T21; |
| 67 | int sysctl_x25_reset_request_timeout = X25_DEFAULT_T22; |
| 68 | int sysctl_x25_clear_request_timeout = X25_DEFAULT_T23; |
| 69 | int sysctl_x25_ack_holdback_timeout = X25_DEFAULT_T2; |
Andrew Hendry | 39e21c0 | 2007-02-08 13:34:36 -0800 | [diff] [blame] | 70 | int sysctl_x25_forward = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
| 72 | HLIST_HEAD(x25_list); |
| 73 | DEFINE_RWLOCK(x25_list_lock); |
| 74 | |
Eric Dumazet | 90ddc4f | 2005-12-22 12:49:22 -0800 | [diff] [blame] | 75 | static const struct proto_ops x25_proto_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | static struct x25_address null_x25_address = {" "}; |
| 78 | |
Shaun Pereira | 1b06e6b | 2006-03-22 00:00:12 -0800 | [diff] [blame] | 79 | #ifdef CONFIG_COMPAT |
| 80 | struct compat_x25_subscrip_struct { |
| 81 | char device[200-sizeof(compat_ulong_t)]; |
| 82 | compat_ulong_t global_facil_mask; |
| 83 | compat_uint_t extended; |
| 84 | }; |
| 85 | #endif |
| 86 | |
John Hughes | f5eb917 | 2010-04-07 21:29:25 -0700 | [diff] [blame] | 87 | |
| 88 | int x25_parse_address_block(struct sk_buff *skb, |
| 89 | struct x25_address *called_addr, |
| 90 | struct x25_address *calling_addr) |
| 91 | { |
| 92 | unsigned char len; |
| 93 | int needed; |
| 94 | int rc; |
| 95 | |
Matthew Daley | cb101ed | 2011-10-14 18:45:04 +0000 | [diff] [blame] | 96 | if (!pskb_may_pull(skb, 1)) { |
John Hughes | f5eb917 | 2010-04-07 21:29:25 -0700 | [diff] [blame] | 97 | /* packet has no address block */ |
| 98 | rc = 0; |
| 99 | goto empty; |
| 100 | } |
| 101 | |
| 102 | len = *skb->data; |
Martin Schiller | ad4c756 | 2018-11-27 09:50:27 +0100 | [diff] [blame] | 103 | needed = 1 + ((len >> 4) + (len & 0x0f) + 1) / 2; |
John Hughes | f5eb917 | 2010-04-07 21:29:25 -0700 | [diff] [blame] | 104 | |
Matthew Daley | cb101ed | 2011-10-14 18:45:04 +0000 | [diff] [blame] | 105 | if (!pskb_may_pull(skb, needed)) { |
John Hughes | f5eb917 | 2010-04-07 21:29:25 -0700 | [diff] [blame] | 106 | /* packet is too short to hold the addresses it claims |
| 107 | to hold */ |
| 108 | rc = -1; |
| 109 | goto empty; |
| 110 | } |
| 111 | |
| 112 | return x25_addr_ntoa(skb->data, called_addr, calling_addr); |
| 113 | |
| 114 | empty: |
| 115 | *called_addr->x25_addr = 0; |
| 116 | *calling_addr->x25_addr = 0; |
| 117 | |
| 118 | return rc; |
| 119 | } |
| 120 | |
| 121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | int x25_addr_ntoa(unsigned char *p, struct x25_address *called_addr, |
| 123 | struct x25_address *calling_addr) |
| 124 | { |
Eric Dumazet | 6bf1574 | 2008-01-13 22:27:52 -0800 | [diff] [blame] | 125 | unsigned int called_len, calling_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | char *called, *calling; |
Eric Dumazet | 6bf1574 | 2008-01-13 22:27:52 -0800 | [diff] [blame] | 127 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
| 129 | called_len = (*p >> 0) & 0x0F; |
| 130 | calling_len = (*p >> 4) & 0x0F; |
| 131 | |
| 132 | called = called_addr->x25_addr; |
| 133 | calling = calling_addr->x25_addr; |
| 134 | p++; |
| 135 | |
| 136 | for (i = 0; i < (called_len + calling_len); i++) { |
| 137 | if (i < called_len) { |
| 138 | if (i % 2 != 0) { |
| 139 | *called++ = ((*p >> 0) & 0x0F) + '0'; |
| 140 | p++; |
| 141 | } else { |
| 142 | *called++ = ((*p >> 4) & 0x0F) + '0'; |
| 143 | } |
| 144 | } else { |
| 145 | if (i % 2 != 0) { |
| 146 | *calling++ = ((*p >> 0) & 0x0F) + '0'; |
| 147 | p++; |
| 148 | } else { |
| 149 | *calling++ = ((*p >> 4) & 0x0F) + '0'; |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | *called = *calling = '\0'; |
| 155 | |
| 156 | return 1 + (called_len + calling_len + 1) / 2; |
| 157 | } |
| 158 | |
| 159 | int x25_addr_aton(unsigned char *p, struct x25_address *called_addr, |
| 160 | struct x25_address *calling_addr) |
| 161 | { |
| 162 | unsigned int called_len, calling_len; |
| 163 | char *called, *calling; |
| 164 | int i; |
| 165 | |
| 166 | called = called_addr->x25_addr; |
| 167 | calling = calling_addr->x25_addr; |
| 168 | |
| 169 | called_len = strlen(called); |
| 170 | calling_len = strlen(calling); |
| 171 | |
| 172 | *p++ = (calling_len << 4) | (called_len << 0); |
| 173 | |
| 174 | for (i = 0; i < (called_len + calling_len); i++) { |
| 175 | if (i < called_len) { |
| 176 | if (i % 2 != 0) { |
| 177 | *p |= (*called++ - '0') << 0; |
| 178 | p++; |
| 179 | } else { |
| 180 | *p = 0x00; |
| 181 | *p |= (*called++ - '0') << 4; |
| 182 | } |
| 183 | } else { |
| 184 | if (i % 2 != 0) { |
| 185 | *p |= (*calling++ - '0') << 0; |
| 186 | p++; |
| 187 | } else { |
| 188 | *p = 0x00; |
| 189 | *p |= (*calling++ - '0') << 4; |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | return 1 + (called_len + calling_len + 1) / 2; |
| 195 | } |
| 196 | |
| 197 | /* |
| 198 | * Socket removal during an interrupt is now safe. |
| 199 | */ |
| 200 | static void x25_remove_socket(struct sock *sk) |
| 201 | { |
| 202 | write_lock_bh(&x25_list_lock); |
| 203 | sk_del_node_init(sk); |
| 204 | write_unlock_bh(&x25_list_lock); |
| 205 | } |
| 206 | |
| 207 | /* |
| 208 | * Kill all bound sockets on a dropped device. |
| 209 | */ |
| 210 | static void x25_kill_by_device(struct net_device *dev) |
| 211 | { |
| 212 | struct sock *s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
| 214 | write_lock_bh(&x25_list_lock); |
| 215 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 216 | sk_for_each(s, &x25_list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | if (x25_sk(s)->neighbour && x25_sk(s)->neighbour->dev == dev) |
| 218 | x25_disconnect(s, ENETUNREACH, 0, 0); |
| 219 | |
| 220 | write_unlock_bh(&x25_list_lock); |
| 221 | } |
| 222 | |
| 223 | /* |
| 224 | * Handle device status changes. |
| 225 | */ |
| 226 | static int x25_device_event(struct notifier_block *this, unsigned long event, |
| 227 | void *ptr) |
| 228 | { |
Jiri Pirko | 351638e | 2013-05-28 01:30:21 +0000 | [diff] [blame] | 229 | struct net_device *dev = netdev_notifier_info_to_dev(ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | struct x25_neigh *nb; |
| 231 | |
YOSHIFUJI Hideaki | 721499e | 2008-07-19 22:34:43 -0700 | [diff] [blame] | 232 | if (!net_eq(dev_net(dev), &init_net)) |
Eric W. Biederman | e9dc865 | 2007-09-12 13:02:17 +0200 | [diff] [blame] | 233 | return NOTIFY_DONE; |
| 234 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | if (dev->type == ARPHRD_X25 |
Igor Maravić | 29c3626 | 2011-12-12 02:58:23 +0000 | [diff] [blame] | 236 | #if IS_ENABLED(CONFIG_LLC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | || dev->type == ARPHRD_ETHER |
| 238 | #endif |
| 239 | ) { |
| 240 | switch (event) { |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 241 | case NETDEV_UP: |
| 242 | x25_link_device_up(dev); |
| 243 | break; |
| 244 | case NETDEV_GOING_DOWN: |
| 245 | nb = x25_get_neigh(dev); |
| 246 | if (nb) { |
| 247 | x25_terminate_link(nb); |
| 248 | x25_neigh_put(nb); |
| 249 | } |
| 250 | break; |
| 251 | case NETDEV_DOWN: |
| 252 | x25_kill_by_device(dev); |
| 253 | x25_route_device_down(dev); |
| 254 | x25_link_device_down(dev); |
| 255 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | } |
| 257 | } |
| 258 | |
| 259 | return NOTIFY_DONE; |
| 260 | } |
| 261 | |
| 262 | /* |
| 263 | * Add a socket to the bound sockets list. |
| 264 | */ |
| 265 | static void x25_insert_socket(struct sock *sk) |
| 266 | { |
| 267 | write_lock_bh(&x25_list_lock); |
| 268 | sk_add_node(sk, &x25_list); |
| 269 | write_unlock_bh(&x25_list_lock); |
| 270 | } |
| 271 | |
| 272 | /* |
| 273 | * Find a socket that wants to accept the Call Request we just |
| 274 | * received. Check the full list for an address/cud match. |
| 275 | * If no cuds match return the next_best thing, an address match. |
| 276 | * Note: if a listening socket has cud set it must only get calls |
| 277 | * with matching cud. |
| 278 | */ |
Shaun Pereira | cb65d50 | 2005-06-22 22:15:01 -0700 | [diff] [blame] | 279 | static struct sock *x25_find_listener(struct x25_address *addr, |
| 280 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | { |
| 282 | struct sock *s; |
| 283 | struct sock *next_best; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
| 285 | read_lock_bh(&x25_list_lock); |
| 286 | next_best = NULL; |
| 287 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 288 | sk_for_each(s, &x25_list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | if ((!strcmp(addr->x25_addr, |
Shaun Pereira | cb65d50 | 2005-06-22 22:15:01 -0700 | [diff] [blame] | 290 | x25_sk(s)->source_addr.x25_addr) || |
Martin Schiller | 3f55d0e | 2018-11-27 09:50:28 +0100 | [diff] [blame] | 291 | !strcmp(x25_sk(s)->source_addr.x25_addr, |
Shaun Pereira | cb65d50 | 2005-06-22 22:15:01 -0700 | [diff] [blame] | 292 | null_x25_address.x25_addr)) && |
| 293 | s->sk_state == TCP_LISTEN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | /* |
| 295 | * Found a listening socket, now check the incoming |
| 296 | * call user data vs this sockets call user data |
| 297 | */ |
Matthew Daley | 7f81e25 | 2011-10-14 18:45:05 +0000 | [diff] [blame] | 298 | if (x25_sk(s)->cudmatchlength > 0 && |
| 299 | skb->len >= x25_sk(s)->cudmatchlength) { |
YOSHIFUJI Hideaki | f8e1d201 | 2007-02-09 23:25:27 +0900 | [diff] [blame] | 300 | if((memcmp(x25_sk(s)->calluserdata.cuddata, |
| 301 | skb->data, |
Shaun Pereira | cb65d50 | 2005-06-22 22:15:01 -0700 | [diff] [blame] | 302 | x25_sk(s)->cudmatchlength)) == 0) { |
| 303 | sock_hold(s); |
| 304 | goto found; |
| 305 | } |
| 306 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | next_best = s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | } |
| 309 | if (next_best) { |
| 310 | s = next_best; |
| 311 | sock_hold(s); |
| 312 | goto found; |
| 313 | } |
| 314 | s = NULL; |
| 315 | found: |
| 316 | read_unlock_bh(&x25_list_lock); |
| 317 | return s; |
| 318 | } |
| 319 | |
| 320 | /* |
| 321 | * Find a connected X.25 socket given my LCI and neighbour. |
| 322 | */ |
| 323 | static struct sock *__x25_find_socket(unsigned int lci, struct x25_neigh *nb) |
| 324 | { |
| 325 | struct sock *s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 327 | sk_for_each(s, &x25_list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | if (x25_sk(s)->lci == lci && x25_sk(s)->neighbour == nb) { |
| 329 | sock_hold(s); |
| 330 | goto found; |
| 331 | } |
| 332 | s = NULL; |
| 333 | found: |
| 334 | return s; |
| 335 | } |
| 336 | |
| 337 | struct sock *x25_find_socket(unsigned int lci, struct x25_neigh *nb) |
| 338 | { |
| 339 | struct sock *s; |
| 340 | |
| 341 | read_lock_bh(&x25_list_lock); |
| 342 | s = __x25_find_socket(lci, nb); |
| 343 | read_unlock_bh(&x25_list_lock); |
| 344 | return s; |
| 345 | } |
| 346 | |
| 347 | /* |
| 348 | * Find a unique LCI for a given device. |
| 349 | */ |
| 350 | static unsigned int x25_new_lci(struct x25_neigh *nb) |
| 351 | { |
| 352 | unsigned int lci = 1; |
| 353 | struct sock *sk; |
| 354 | |
Eric Dumazet | 4833df3 | 2019-02-08 12:41:05 -0800 | [diff] [blame] | 355 | while ((sk = x25_find_socket(lci, nb)) != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | sock_put(sk); |
| 357 | if (++lci == 4096) { |
| 358 | lci = 0; |
| 359 | break; |
| 360 | } |
Eric Dumazet | 4833df3 | 2019-02-08 12:41:05 -0800 | [diff] [blame] | 361 | cond_resched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | return lci; |
| 365 | } |
| 366 | |
| 367 | /* |
| 368 | * Deferred destroy. |
| 369 | */ |
David S. Miller | 14ebaf8 | 2009-06-16 05:40:30 -0700 | [diff] [blame] | 370 | static void __x25_destroy_socket(struct sock *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
| 372 | /* |
| 373 | * handler for deferred kills. |
| 374 | */ |
| 375 | static void x25_destroy_timer(unsigned long data) |
| 376 | { |
David S. Miller | 14ebaf8 | 2009-06-16 05:40:30 -0700 | [diff] [blame] | 377 | x25_destroy_socket_from_timer((struct sock *)data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | /* |
| 381 | * This is called from user mode and the timers. Thus it protects itself |
| 382 | * against interrupt users but doesn't worry about being called during |
| 383 | * work. Once it is removed from the queue no interrupt or bottom half |
| 384 | * will touch it and we are (fairly 8-) ) safe. |
| 385 | * Not static as it's used by the timer |
| 386 | */ |
David S. Miller | 14ebaf8 | 2009-06-16 05:40:30 -0700 | [diff] [blame] | 387 | static void __x25_destroy_socket(struct sock *sk) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | { |
| 389 | struct sk_buff *skb; |
| 390 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | x25_stop_heartbeat(sk); |
| 392 | x25_stop_timer(sk); |
| 393 | |
| 394 | x25_remove_socket(sk); |
| 395 | x25_clear_queues(sk); /* Flush the queues */ |
| 396 | |
| 397 | while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) { |
| 398 | if (skb->sk != sk) { /* A pending connection */ |
| 399 | /* |
| 400 | * Queue the unaccepted socket for death |
| 401 | */ |
andrew hendry | 2cec6b0 | 2010-04-17 14:17:32 +0000 | [diff] [blame] | 402 | skb->sk->sk_state = TCP_LISTEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | sock_set_flag(skb->sk, SOCK_DEAD); |
| 404 | x25_start_heartbeat(skb->sk); |
| 405 | x25_sk(skb->sk)->state = X25_STATE_0; |
| 406 | } |
| 407 | |
| 408 | kfree_skb(skb); |
| 409 | } |
| 410 | |
Eric Dumazet | c564039 | 2009-06-16 10:12:03 +0000 | [diff] [blame] | 411 | if (sk_has_allocations(sk)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | /* Defer: outstanding buffers */ |
| 413 | sk->sk_timer.expires = jiffies + 10 * HZ; |
| 414 | sk->sk_timer.function = x25_destroy_timer; |
| 415 | sk->sk_timer.data = (unsigned long)sk; |
| 416 | add_timer(&sk->sk_timer); |
| 417 | } else { |
| 418 | /* drop last reference so sock_put will free */ |
| 419 | __sock_put(sk); |
| 420 | } |
David S. Miller | 14ebaf8 | 2009-06-16 05:40:30 -0700 | [diff] [blame] | 421 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
David S. Miller | 14ebaf8 | 2009-06-16 05:40:30 -0700 | [diff] [blame] | 423 | void x25_destroy_socket_from_timer(struct sock *sk) |
| 424 | { |
| 425 | sock_hold(sk); |
| 426 | bh_lock_sock(sk); |
| 427 | __x25_destroy_socket(sk); |
| 428 | bh_unlock_sock(sk); |
| 429 | sock_put(sk); |
| 430 | } |
| 431 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | /* |
| 433 | * Handling for system calls applied via the various interfaces to a |
| 434 | * X.25 socket object. |
| 435 | */ |
| 436 | |
| 437 | static int x25_setsockopt(struct socket *sock, int level, int optname, |
David S. Miller | b705884 | 2009-09-30 16:12:20 -0700 | [diff] [blame] | 438 | char __user *optval, unsigned int optlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | { |
| 440 | int opt; |
| 441 | struct sock *sk = sock->sk; |
| 442 | int rc = -ENOPROTOOPT; |
| 443 | |
| 444 | if (level != SOL_X25 || optname != X25_QBITINCL) |
| 445 | goto out; |
| 446 | |
| 447 | rc = -EINVAL; |
| 448 | if (optlen < sizeof(int)) |
| 449 | goto out; |
| 450 | |
| 451 | rc = -EFAULT; |
| 452 | if (get_user(opt, (int __user *)optval)) |
| 453 | goto out; |
| 454 | |
andrew hendry | cb863ff | 2010-05-16 22:59:41 +0000 | [diff] [blame] | 455 | if (opt) |
| 456 | set_bit(X25_Q_BIT_FLAG, &x25_sk(sk)->flags); |
| 457 | else |
| 458 | clear_bit(X25_Q_BIT_FLAG, &x25_sk(sk)->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | rc = 0; |
| 460 | out: |
| 461 | return rc; |
| 462 | } |
| 463 | |
| 464 | static int x25_getsockopt(struct socket *sock, int level, int optname, |
| 465 | char __user *optval, int __user *optlen) |
| 466 | { |
| 467 | struct sock *sk = sock->sk; |
| 468 | int val, len, rc = -ENOPROTOOPT; |
YOSHIFUJI Hideaki | f8e1d201 | 2007-02-09 23:25:27 +0900 | [diff] [blame] | 469 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | if (level != SOL_X25 || optname != X25_QBITINCL) |
| 471 | goto out; |
| 472 | |
| 473 | rc = -EFAULT; |
| 474 | if (get_user(len, optlen)) |
| 475 | goto out; |
| 476 | |
| 477 | len = min_t(unsigned int, len, sizeof(int)); |
| 478 | |
| 479 | rc = -EINVAL; |
| 480 | if (len < 0) |
| 481 | goto out; |
YOSHIFUJI Hideaki | f8e1d201 | 2007-02-09 23:25:27 +0900 | [diff] [blame] | 482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | rc = -EFAULT; |
| 484 | if (put_user(len, optlen)) |
| 485 | goto out; |
| 486 | |
andrew hendry | cb863ff | 2010-05-16 22:59:41 +0000 | [diff] [blame] | 487 | val = test_bit(X25_Q_BIT_FLAG, &x25_sk(sk)->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | rc = copy_to_user(optval, &val, len) ? -EFAULT : 0; |
| 489 | out: |
| 490 | return rc; |
| 491 | } |
| 492 | |
| 493 | static int x25_listen(struct socket *sock, int backlog) |
| 494 | { |
| 495 | struct sock *sk = sock->sk; |
| 496 | int rc = -EOPNOTSUPP; |
| 497 | |
andrew hendry | 25aa4ef | 2010-09-14 13:31:16 +0000 | [diff] [blame] | 498 | lock_sock(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | if (sk->sk_state != TCP_LISTEN) { |
| 500 | memset(&x25_sk(sk)->dest_addr, 0, X25_ADDR_LEN); |
| 501 | sk->sk_max_ack_backlog = backlog; |
| 502 | sk->sk_state = TCP_LISTEN; |
| 503 | rc = 0; |
| 504 | } |
andrew hendry | 25aa4ef | 2010-09-14 13:31:16 +0000 | [diff] [blame] | 505 | release_sock(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
| 507 | return rc; |
| 508 | } |
| 509 | |
| 510 | static struct proto x25_proto = { |
| 511 | .name = "X25", |
| 512 | .owner = THIS_MODULE, |
| 513 | .obj_size = sizeof(struct x25_sock), |
| 514 | }; |
| 515 | |
Eric W. Biederman | 11aa9c2 | 2015-05-08 21:09:13 -0500 | [diff] [blame] | 516 | static struct sock *x25_alloc_socket(struct net *net, int kern) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | { |
| 518 | struct x25_sock *x25; |
Eric W. Biederman | 11aa9c2 | 2015-05-08 21:09:13 -0500 | [diff] [blame] | 519 | struct sock *sk = sk_alloc(net, AF_X25, GFP_ATOMIC, &x25_proto, kern); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | |
| 521 | if (!sk) |
| 522 | goto out; |
| 523 | |
| 524 | sock_init_data(NULL, sk); |
| 525 | |
| 526 | x25 = x25_sk(sk); |
| 527 | skb_queue_head_init(&x25->ack_queue); |
| 528 | skb_queue_head_init(&x25->fragment_queue); |
| 529 | skb_queue_head_init(&x25->interrupt_in_queue); |
| 530 | skb_queue_head_init(&x25->interrupt_out_queue); |
| 531 | out: |
| 532 | return sk; |
| 533 | } |
| 534 | |
Eric Paris | 3f378b6 | 2009-11-05 22:18:14 -0800 | [diff] [blame] | 535 | static int x25_create(struct net *net, struct socket *sock, int protocol, |
| 536 | int kern) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | { |
| 538 | struct sock *sk; |
| 539 | struct x25_sock *x25; |
andrew hendry | b18e7a0 | 2010-02-14 02:00:11 +0000 | [diff] [blame] | 540 | int rc = -EAFNOSUPPORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
Octavian Purdila | 09ad9bc | 2009-11-25 15:14:13 -0800 | [diff] [blame] | 542 | if (!net_eq(net, &init_net)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | goto out; |
| 544 | |
andrew hendry | b18e7a0 | 2010-02-14 02:00:11 +0000 | [diff] [blame] | 545 | rc = -ESOCKTNOSUPPORT; |
| 546 | if (sock->type != SOCK_SEQPACKET) |
| 547 | goto out; |
| 548 | |
| 549 | rc = -EINVAL; |
| 550 | if (protocol) |
| 551 | goto out; |
| 552 | |
| 553 | rc = -ENOBUFS; |
Eric W. Biederman | 11aa9c2 | 2015-05-08 21:09:13 -0500 | [diff] [blame] | 554 | if ((sk = x25_alloc_socket(net, kern)) == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | goto out; |
| 556 | |
| 557 | x25 = x25_sk(sk); |
| 558 | |
| 559 | sock_init_data(sock, sk); |
| 560 | |
| 561 | x25_init_timers(sk); |
| 562 | |
| 563 | sock->ops = &x25_proto_ops; |
| 564 | sk->sk_protocol = protocol; |
| 565 | sk->sk_backlog_rcv = x25_backlog_rcv; |
| 566 | |
| 567 | x25->t21 = sysctl_x25_call_request_timeout; |
| 568 | x25->t22 = sysctl_x25_reset_request_timeout; |
| 569 | x25->t23 = sysctl_x25_clear_request_timeout; |
| 570 | x25->t2 = sysctl_x25_ack_holdback_timeout; |
| 571 | x25->state = X25_STATE_0; |
Shaun Pereira | cb65d50 | 2005-06-22 22:15:01 -0700 | [diff] [blame] | 572 | x25->cudmatchlength = 0; |
andrew hendry | 37cda78 | 2010-05-16 23:00:27 +0000 | [diff] [blame] | 573 | set_bit(X25_ACCPT_APPRV_FLAG, &x25->flags); /* normally no cud */ |
Shaun Pereira | ebc3f64 | 2005-06-22 22:16:17 -0700 | [diff] [blame] | 574 | /* on call accept */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | |
| 576 | x25->facilities.winsize_in = X25_DEFAULT_WINDOW_SIZE; |
| 577 | x25->facilities.winsize_out = X25_DEFAULT_WINDOW_SIZE; |
| 578 | x25->facilities.pacsize_in = X25_DEFAULT_PACKET_SIZE; |
| 579 | x25->facilities.pacsize_out = X25_DEFAULT_PACKET_SIZE; |
John Hughes | ddd0451 | 2010-04-04 06:48:10 +0000 | [diff] [blame] | 580 | x25->facilities.throughput = 0; /* by default don't negotiate |
| 581 | throughput */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | x25->facilities.reverse = X25_DEFAULT_REVERSE; |
YOSHIFUJI Hideaki | f8e1d201 | 2007-02-09 23:25:27 +0900 | [diff] [blame] | 583 | x25->dte_facilities.calling_len = 0; |
| 584 | x25->dte_facilities.called_len = 0; |
| 585 | memset(x25->dte_facilities.called_ae, '\0', |
| 586 | sizeof(x25->dte_facilities.called_ae)); |
| 587 | memset(x25->dte_facilities.calling_ae, '\0', |
| 588 | sizeof(x25->dte_facilities.calling_ae)); |
Shaun Pereira | a64b7b9 | 2006-03-22 00:01:31 -0800 | [diff] [blame] | 589 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | rc = 0; |
| 591 | out: |
| 592 | return rc; |
| 593 | } |
| 594 | |
| 595 | static struct sock *x25_make_new(struct sock *osk) |
| 596 | { |
| 597 | struct sock *sk = NULL; |
| 598 | struct x25_sock *x25, *ox25; |
| 599 | |
| 600 | if (osk->sk_type != SOCK_SEQPACKET) |
| 601 | goto out; |
| 602 | |
Eric W. Biederman | 11aa9c2 | 2015-05-08 21:09:13 -0500 | [diff] [blame] | 603 | if ((sk = x25_alloc_socket(sock_net(osk), 0)) == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | goto out; |
| 605 | |
| 606 | x25 = x25_sk(sk); |
| 607 | |
| 608 | sk->sk_type = osk->sk_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | sk->sk_priority = osk->sk_priority; |
| 610 | sk->sk_protocol = osk->sk_protocol; |
| 611 | sk->sk_rcvbuf = osk->sk_rcvbuf; |
| 612 | sk->sk_sndbuf = osk->sk_sndbuf; |
| 613 | sk->sk_state = TCP_ESTABLISHED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | sk->sk_backlog_rcv = osk->sk_backlog_rcv; |
Shaun Pereira | a20a855 | 2006-01-06 13:11:35 -0800 | [diff] [blame] | 615 | sock_copy_flags(sk, osk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | |
| 617 | ox25 = x25_sk(osk); |
| 618 | x25->t21 = ox25->t21; |
| 619 | x25->t22 = ox25->t22; |
| 620 | x25->t23 = ox25->t23; |
| 621 | x25->t2 = ox25->t2; |
andrew hendry | cb863ff | 2010-05-16 22:59:41 +0000 | [diff] [blame] | 622 | x25->flags = ox25->flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | x25->facilities = ox25->facilities; |
Shaun Pereira | a64b7b9 | 2006-03-22 00:01:31 -0800 | [diff] [blame] | 624 | x25->dte_facilities = ox25->dte_facilities; |
Shaun Pereira | cb65d50 | 2005-06-22 22:15:01 -0700 | [diff] [blame] | 625 | x25->cudmatchlength = ox25->cudmatchlength; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | |
andrew hendry | b7792e3 | 2010-05-16 23:00:02 +0000 | [diff] [blame] | 627 | clear_bit(X25_INTERRUPT_FLAG, &x25->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | x25_init_timers(sk); |
| 629 | out: |
| 630 | return sk; |
| 631 | } |
| 632 | |
| 633 | static int x25_release(struct socket *sock) |
| 634 | { |
| 635 | struct sock *sk = sock->sk; |
| 636 | struct x25_sock *x25; |
| 637 | |
| 638 | if (!sk) |
Arnd Bergmann | 77b2283 | 2011-01-22 23:44:59 +0100 | [diff] [blame] | 639 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | |
| 641 | x25 = x25_sk(sk); |
| 642 | |
Arnd Bergmann | 77b2283 | 2011-01-22 23:44:59 +0100 | [diff] [blame] | 643 | sock_hold(sk); |
| 644 | lock_sock(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | switch (x25->state) { |
| 646 | |
| 647 | case X25_STATE_0: |
| 648 | case X25_STATE_2: |
| 649 | x25_disconnect(sk, 0, 0, 0); |
Arnd Bergmann | 77b2283 | 2011-01-22 23:44:59 +0100 | [diff] [blame] | 650 | __x25_destroy_socket(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | goto out; |
| 652 | |
| 653 | case X25_STATE_1: |
| 654 | case X25_STATE_3: |
| 655 | case X25_STATE_4: |
| 656 | x25_clear_queues(sk); |
| 657 | x25_write_internal(sk, X25_CLEAR_REQUEST); |
| 658 | x25_start_t23timer(sk); |
| 659 | x25->state = X25_STATE_2; |
| 660 | sk->sk_state = TCP_CLOSE; |
| 661 | sk->sk_shutdown |= SEND_SHUTDOWN; |
| 662 | sk->sk_state_change(sk); |
| 663 | sock_set_flag(sk, SOCK_DEAD); |
| 664 | sock_set_flag(sk, SOCK_DESTROY); |
| 665 | break; |
| 666 | } |
| 667 | |
David S. Miller | c751e4f | 2008-06-17 03:05:13 -0700 | [diff] [blame] | 668 | sock_orphan(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | out: |
Arnd Bergmann | 77b2283 | 2011-01-22 23:44:59 +0100 | [diff] [blame] | 670 | release_sock(sk); |
| 671 | sock_put(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | return 0; |
| 673 | } |
| 674 | |
| 675 | static int x25_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) |
| 676 | { |
| 677 | struct sock *sk = sock->sk; |
| 678 | struct sockaddr_x25 *addr = (struct sockaddr_x25 *)uaddr; |
andrew hendry | a928852 | 2010-02-14 02:00:45 +0000 | [diff] [blame] | 679 | int len, i, rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | |
Eric Dumazet | 92382cd | 2019-02-23 13:24:59 -0800 | [diff] [blame] | 681 | if (addr_len != sizeof(struct sockaddr_x25) || |
Arnd Bergmann | 9177490 | 2009-11-05 04:37:29 +0000 | [diff] [blame] | 682 | addr->sx25_family != AF_X25) { |
| 683 | rc = -EINVAL; |
| 684 | goto out; |
| 685 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | |
Martin Schiller | 3f55d0e | 2018-11-27 09:50:28 +0100 | [diff] [blame] | 687 | /* check for the null_x25_address */ |
| 688 | if (strcmp(addr->sx25_addr.x25_addr, null_x25_address.x25_addr)) { |
| 689 | |
| 690 | len = strlen(addr->sx25_addr.x25_addr); |
| 691 | for (i = 0; i < len; i++) { |
| 692 | if (!isdigit(addr->sx25_addr.x25_addr[i])) { |
| 693 | rc = -EINVAL; |
| 694 | goto out; |
| 695 | } |
andrew hendry | a928852 | 2010-02-14 02:00:45 +0000 | [diff] [blame] | 696 | } |
| 697 | } |
| 698 | |
andrew hendry | 90c2729 | 2010-09-14 13:31:38 +0000 | [diff] [blame] | 699 | lock_sock(sk); |
Eric Dumazet | 92382cd | 2019-02-23 13:24:59 -0800 | [diff] [blame] | 700 | if (sock_flag(sk, SOCK_ZAPPED)) { |
| 701 | x25_sk(sk)->source_addr = addr->sx25_addr; |
| 702 | x25_insert_socket(sk); |
| 703 | sock_reset_flag(sk, SOCK_ZAPPED); |
| 704 | } else { |
| 705 | rc = -EINVAL; |
| 706 | } |
andrew hendry | 90c2729 | 2010-09-14 13:31:38 +0000 | [diff] [blame] | 707 | release_sock(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | SOCK_DEBUG(sk, "x25_bind: socket is bound\n"); |
Arnd Bergmann | 9177490 | 2009-11-05 04:37:29 +0000 | [diff] [blame] | 709 | out: |
Arnd Bergmann | 9177490 | 2009-11-05 04:37:29 +0000 | [diff] [blame] | 710 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | static int x25_wait_for_connection_establishment(struct sock *sk) |
| 714 | { |
| 715 | DECLARE_WAITQUEUE(wait, current); |
YOSHIFUJI Hideaki | f8e1d201 | 2007-02-09 23:25:27 +0900 | [diff] [blame] | 716 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | |
Eric Dumazet | aa39514 | 2010-04-20 13:03:51 +0000 | [diff] [blame] | 718 | add_wait_queue_exclusive(sk_sleep(sk), &wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | for (;;) { |
| 720 | __set_current_state(TASK_INTERRUPTIBLE); |
| 721 | rc = -ERESTARTSYS; |
| 722 | if (signal_pending(current)) |
| 723 | break; |
| 724 | rc = sock_error(sk); |
| 725 | if (rc) { |
| 726 | sk->sk_socket->state = SS_UNCONNECTED; |
| 727 | break; |
| 728 | } |
| 729 | rc = 0; |
| 730 | if (sk->sk_state != TCP_ESTABLISHED) { |
| 731 | release_sock(sk); |
| 732 | schedule(); |
| 733 | lock_sock(sk); |
| 734 | } else |
| 735 | break; |
| 736 | } |
| 737 | __set_current_state(TASK_RUNNING); |
Eric Dumazet | aa39514 | 2010-04-20 13:03:51 +0000 | [diff] [blame] | 738 | remove_wait_queue(sk_sleep(sk), &wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | return rc; |
| 740 | } |
| 741 | |
| 742 | static int x25_connect(struct socket *sock, struct sockaddr *uaddr, |
| 743 | int addr_len, int flags) |
| 744 | { |
| 745 | struct sock *sk = sock->sk; |
| 746 | struct x25_sock *x25 = x25_sk(sk); |
| 747 | struct sockaddr_x25 *addr = (struct sockaddr_x25 *)uaddr; |
| 748 | struct x25_route *rt; |
| 749 | int rc = 0; |
| 750 | |
| 751 | lock_sock(sk); |
| 752 | if (sk->sk_state == TCP_ESTABLISHED && sock->state == SS_CONNECTING) { |
| 753 | sock->state = SS_CONNECTED; |
| 754 | goto out; /* Connect completed during a ERESTARTSYS event */ |
| 755 | } |
| 756 | |
| 757 | rc = -ECONNREFUSED; |
| 758 | if (sk->sk_state == TCP_CLOSE && sock->state == SS_CONNECTING) { |
| 759 | sock->state = SS_UNCONNECTED; |
| 760 | goto out; |
| 761 | } |
| 762 | |
| 763 | rc = -EISCONN; /* No reconnect on a seqpacket socket */ |
| 764 | if (sk->sk_state == TCP_ESTABLISHED) |
| 765 | goto out; |
| 766 | |
Martin Schiller | c4efc61 | 2020-01-09 07:31:14 +0100 | [diff] [blame] | 767 | rc = -EALREADY; /* Do nothing if call is already in progress */ |
| 768 | if (sk->sk_state == TCP_SYN_SENT) |
| 769 | goto out; |
| 770 | |
YOSHIFUJI Hideaki | f8e1d201 | 2007-02-09 23:25:27 +0900 | [diff] [blame] | 771 | sk->sk_state = TCP_CLOSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | sock->state = SS_UNCONNECTED; |
| 773 | |
| 774 | rc = -EINVAL; |
| 775 | if (addr_len != sizeof(struct sockaddr_x25) || |
| 776 | addr->sx25_family != AF_X25) |
| 777 | goto out; |
| 778 | |
| 779 | rc = -ENETUNREACH; |
| 780 | rt = x25_get_route(&addr->sx25_addr); |
| 781 | if (!rt) |
| 782 | goto out; |
| 783 | |
| 784 | x25->neighbour = x25_get_neigh(rt->dev); |
| 785 | if (!x25->neighbour) |
| 786 | goto out_put_route; |
| 787 | |
| 788 | x25_limit_facilities(&x25->facilities, x25->neighbour); |
| 789 | |
| 790 | x25->lci = x25_new_lci(x25->neighbour); |
| 791 | if (!x25->lci) |
| 792 | goto out_put_neigh; |
| 793 | |
| 794 | rc = -EINVAL; |
| 795 | if (sock_flag(sk, SOCK_ZAPPED)) /* Must bind first - autobinding does not work */ |
| 796 | goto out_put_neigh; |
| 797 | |
| 798 | if (!strcmp(x25->source_addr.x25_addr, null_x25_address.x25_addr)) |
| 799 | memset(&x25->source_addr, '\0', X25_ADDR_LEN); |
| 800 | |
| 801 | x25->dest_addr = addr->sx25_addr; |
| 802 | |
| 803 | /* Move to connecting socket, start sending Connect Requests */ |
| 804 | sock->state = SS_CONNECTING; |
| 805 | sk->sk_state = TCP_SYN_SENT; |
| 806 | |
| 807 | x25->state = X25_STATE_1; |
| 808 | |
| 809 | x25_write_internal(sk, X25_CALL_REQUEST); |
| 810 | |
| 811 | x25_start_heartbeat(sk); |
| 812 | x25_start_t21timer(sk); |
| 813 | |
| 814 | /* Now the loop */ |
| 815 | rc = -EINPROGRESS; |
| 816 | if (sk->sk_state != TCP_ESTABLISHED && (flags & O_NONBLOCK)) |
Martin Schiller | c4efc61 | 2020-01-09 07:31:14 +0100 | [diff] [blame] | 817 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | |
| 819 | rc = x25_wait_for_connection_establishment(sk); |
| 820 | if (rc) |
| 821 | goto out_put_neigh; |
| 822 | |
| 823 | sock->state = SS_CONNECTED; |
| 824 | rc = 0; |
| 825 | out_put_neigh: |
Eric Dumazet | 3123545 | 2019-03-10 09:07:14 -0700 | [diff] [blame] | 826 | if (rc) { |
| 827 | read_lock_bh(&x25_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | x25_neigh_put(x25->neighbour); |
Eric Dumazet | 3123545 | 2019-03-10 09:07:14 -0700 | [diff] [blame] | 829 | x25->neighbour = NULL; |
| 830 | read_unlock_bh(&x25_list_lock); |
Eric Dumazet | 0651889 | 2019-03-11 13:48:44 -0700 | [diff] [blame] | 831 | x25->state = X25_STATE_0; |
Eric Dumazet | 3123545 | 2019-03-10 09:07:14 -0700 | [diff] [blame] | 832 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | out_put_route: |
| 834 | x25_route_put(rt); |
| 835 | out: |
| 836 | release_sock(sk); |
| 837 | return rc; |
| 838 | } |
| 839 | |
Shaun Pereira | bac37ec | 2006-03-22 00:00:40 -0800 | [diff] [blame] | 840 | static int x25_wait_for_data(struct sock *sk, long timeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | { |
| 842 | DECLARE_WAITQUEUE(wait, current); |
| 843 | int rc = 0; |
| 844 | |
Eric Dumazet | aa39514 | 2010-04-20 13:03:51 +0000 | [diff] [blame] | 845 | add_wait_queue_exclusive(sk_sleep(sk), &wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | for (;;) { |
| 847 | __set_current_state(TASK_INTERRUPTIBLE); |
| 848 | if (sk->sk_shutdown & RCV_SHUTDOWN) |
| 849 | break; |
| 850 | rc = -ERESTARTSYS; |
| 851 | if (signal_pending(current)) |
| 852 | break; |
| 853 | rc = -EAGAIN; |
| 854 | if (!timeout) |
| 855 | break; |
| 856 | rc = 0; |
| 857 | if (skb_queue_empty(&sk->sk_receive_queue)) { |
| 858 | release_sock(sk); |
| 859 | timeout = schedule_timeout(timeout); |
| 860 | lock_sock(sk); |
| 861 | } else |
| 862 | break; |
| 863 | } |
| 864 | __set_current_state(TASK_RUNNING); |
Eric Dumazet | aa39514 | 2010-04-20 13:03:51 +0000 | [diff] [blame] | 865 | remove_wait_queue(sk_sleep(sk), &wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | return rc; |
| 867 | } |
YOSHIFUJI Hideaki | f8e1d201 | 2007-02-09 23:25:27 +0900 | [diff] [blame] | 868 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | static int x25_accept(struct socket *sock, struct socket *newsock, int flags) |
| 870 | { |
| 871 | struct sock *sk = sock->sk; |
| 872 | struct sock *newsk; |
| 873 | struct sk_buff *skb; |
| 874 | int rc = -EINVAL; |
| 875 | |
Andrew Hendry | 141646c | 2010-09-14 20:38:54 -0700 | [diff] [blame] | 876 | if (!sk) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | goto out; |
| 878 | |
| 879 | rc = -EOPNOTSUPP; |
| 880 | if (sk->sk_type != SOCK_SEQPACKET) |
| 881 | goto out; |
| 882 | |
| 883 | lock_sock(sk); |
Andrew Hendry | 141646c | 2010-09-14 20:38:54 -0700 | [diff] [blame] | 884 | rc = -EINVAL; |
| 885 | if (sk->sk_state != TCP_LISTEN) |
| 886 | goto out2; |
| 887 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | rc = x25_wait_for_data(sk, sk->sk_rcvtimeo); |
| 889 | if (rc) |
| 890 | goto out2; |
| 891 | skb = skb_dequeue(&sk->sk_receive_queue); |
| 892 | rc = -EINVAL; |
| 893 | if (!skb->sk) |
| 894 | goto out2; |
| 895 | newsk = skb->sk; |
David S. Miller | b61d38e | 2008-06-17 02:44:35 -0700 | [diff] [blame] | 896 | sock_graft(newsk, newsock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | |
| 898 | /* Now attach up the new socket */ |
| 899 | skb->sk = NULL; |
| 900 | kfree_skb(skb); |
| 901 | sk->sk_ack_backlog--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | newsock->state = SS_CONNECTED; |
| 903 | rc = 0; |
| 904 | out2: |
| 905 | release_sock(sk); |
| 906 | out: |
| 907 | return rc; |
| 908 | } |
| 909 | |
| 910 | static int x25_getname(struct socket *sock, struct sockaddr *uaddr, |
| 911 | int *uaddr_len, int peer) |
| 912 | { |
| 913 | struct sockaddr_x25 *sx25 = (struct sockaddr_x25 *)uaddr; |
| 914 | struct sock *sk = sock->sk; |
| 915 | struct x25_sock *x25 = x25_sk(sk); |
Arnd Bergmann | 9177490 | 2009-11-05 04:37:29 +0000 | [diff] [blame] | 916 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | |
| 918 | if (peer) { |
Arnd Bergmann | 9177490 | 2009-11-05 04:37:29 +0000 | [diff] [blame] | 919 | if (sk->sk_state != TCP_ESTABLISHED) { |
| 920 | rc = -ENOTCONN; |
| 921 | goto out; |
| 922 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | sx25->sx25_addr = x25->dest_addr; |
| 924 | } else |
| 925 | sx25->sx25_addr = x25->source_addr; |
| 926 | |
| 927 | sx25->sx25_family = AF_X25; |
| 928 | *uaddr_len = sizeof(*sx25); |
| 929 | |
Arnd Bergmann | 9177490 | 2009-11-05 04:37:29 +0000 | [diff] [blame] | 930 | out: |
Arnd Bergmann | 9177490 | 2009-11-05 04:37:29 +0000 | [diff] [blame] | 931 | return rc; |
| 932 | } |
| 933 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | int x25_rx_call_request(struct sk_buff *skb, struct x25_neigh *nb, |
| 935 | unsigned int lci) |
| 936 | { |
| 937 | struct sock *sk; |
| 938 | struct sock *make; |
| 939 | struct x25_sock *makex25; |
| 940 | struct x25_address source_addr, dest_addr; |
| 941 | struct x25_facilities facilities; |
Shaun Pereira | a64b7b9 | 2006-03-22 00:01:31 -0800 | [diff] [blame] | 942 | struct x25_dte_facilities dte_facilities; |
Andrew Hendry | 95a9dc4 | 2007-02-08 13:34:02 -0800 | [diff] [blame] | 943 | int len, addr_len, rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | |
| 945 | /* |
| 946 | * Remove the LCI and frame type. |
| 947 | */ |
| 948 | skb_pull(skb, X25_STD_MIN_LEN); |
| 949 | |
| 950 | /* |
| 951 | * Extract the X.25 addresses and convert them to ASCII strings, |
| 952 | * and remove them. |
John Hughes | f5eb917 | 2010-04-07 21:29:25 -0700 | [diff] [blame] | 953 | * |
| 954 | * Address block is mandatory in call request packets |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | */ |
John Hughes | f5eb917 | 2010-04-07 21:29:25 -0700 | [diff] [blame] | 956 | addr_len = x25_parse_address_block(skb, &source_addr, &dest_addr); |
| 957 | if (addr_len <= 0) |
| 958 | goto out_clear_request; |
Andrew Hendry | 95a9dc4 | 2007-02-08 13:34:02 -0800 | [diff] [blame] | 959 | skb_pull(skb, addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | |
| 961 | /* |
| 962 | * Get the length of the facilities, skip past them for the moment |
| 963 | * get the call user data because this is needed to determine |
| 964 | * the correct listener |
John Hughes | f5eb917 | 2010-04-07 21:29:25 -0700 | [diff] [blame] | 965 | * |
| 966 | * Facilities length is mandatory in call request packets |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | */ |
Matthew Daley | cb101ed | 2011-10-14 18:45:04 +0000 | [diff] [blame] | 968 | if (!pskb_may_pull(skb, 1)) |
John Hughes | f5eb917 | 2010-04-07 21:29:25 -0700 | [diff] [blame] | 969 | goto out_clear_request; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | len = skb->data[0] + 1; |
Matthew Daley | cb101ed | 2011-10-14 18:45:04 +0000 | [diff] [blame] | 971 | if (!pskb_may_pull(skb, len)) |
John Hughes | f5eb917 | 2010-04-07 21:29:25 -0700 | [diff] [blame] | 972 | goto out_clear_request; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | skb_pull(skb,len); |
| 974 | |
| 975 | /* |
Matthew Daley | c7fd0d4 | 2011-10-14 18:45:03 +0000 | [diff] [blame] | 976 | * Ensure that the amount of call user data is valid. |
| 977 | */ |
| 978 | if (skb->len > X25_MAX_CUD_LEN) |
| 979 | goto out_clear_request; |
| 980 | |
| 981 | /* |
Matthew Daley | cb101ed | 2011-10-14 18:45:04 +0000 | [diff] [blame] | 982 | * Get all the call user data so it can be used in |
| 983 | * x25_find_listener and skb_copy_from_linear_data up ahead. |
| 984 | */ |
| 985 | if (!pskb_may_pull(skb, skb->len)) |
| 986 | goto out_clear_request; |
| 987 | |
| 988 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | * Find a listener for the particular address/cud pair. |
| 990 | */ |
Shaun Pereira | cb65d50 | 2005-06-22 22:15:01 -0700 | [diff] [blame] | 991 | sk = x25_find_listener(&source_addr,skb); |
| 992 | skb_push(skb,len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | |
Andrew Hendry | 95a9dc4 | 2007-02-08 13:34:02 -0800 | [diff] [blame] | 994 | if (sk != NULL && sk_acceptq_is_full(sk)) { |
| 995 | goto out_sock_put; |
| 996 | } |
| 997 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | /* |
Andrew Hendry | 95a9dc4 | 2007-02-08 13:34:02 -0800 | [diff] [blame] | 999 | * We dont have any listeners for this incoming call. |
| 1000 | * Try forwarding it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | */ |
Andrew Hendry | 95a9dc4 | 2007-02-08 13:34:02 -0800 | [diff] [blame] | 1002 | if (sk == NULL) { |
| 1003 | skb_push(skb, addr_len + X25_STD_MIN_LEN); |
Andrew Hendry | 39e21c0 | 2007-02-08 13:34:36 -0800 | [diff] [blame] | 1004 | if (sysctl_x25_forward && |
| 1005 | x25_forward_call(&dest_addr, nb, skb, lci) > 0) |
Andrew Hendry | 95a9dc4 | 2007-02-08 13:34:02 -0800 | [diff] [blame] | 1006 | { |
| 1007 | /* Call was forwarded, dont process it any more */ |
| 1008 | kfree_skb(skb); |
| 1009 | rc = 1; |
| 1010 | goto out; |
| 1011 | } else { |
| 1012 | /* No listeners, can't forward, clear the call */ |
| 1013 | goto out_clear_request; |
| 1014 | } |
| 1015 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | |
| 1017 | /* |
| 1018 | * Try to reach a compromise on the requested facilities. |
| 1019 | */ |
Shaun Pereira | a64b7b9 | 2006-03-22 00:01:31 -0800 | [diff] [blame] | 1020 | len = x25_negotiate_facilities(skb, sk, &facilities, &dte_facilities); |
| 1021 | if (len == -1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | goto out_sock_put; |
| 1023 | |
| 1024 | /* |
| 1025 | * current neighbour/link might impose additional limits |
| 1026 | * on certain facilties |
| 1027 | */ |
| 1028 | |
| 1029 | x25_limit_facilities(&facilities, nb); |
| 1030 | |
| 1031 | /* |
| 1032 | * Try to create a new socket. |
| 1033 | */ |
| 1034 | make = x25_make_new(sk); |
| 1035 | if (!make) |
| 1036 | goto out_sock_put; |
| 1037 | |
| 1038 | /* |
| 1039 | * Remove the facilities |
| 1040 | */ |
| 1041 | skb_pull(skb, len); |
| 1042 | |
| 1043 | skb->sk = make; |
| 1044 | make->sk_state = TCP_ESTABLISHED; |
| 1045 | |
| 1046 | makex25 = x25_sk(make); |
| 1047 | makex25->lci = lci; |
| 1048 | makex25->dest_addr = dest_addr; |
| 1049 | makex25->source_addr = source_addr; |
| 1050 | makex25->neighbour = nb; |
| 1051 | makex25->facilities = facilities; |
Shaun Pereira | a64b7b9 | 2006-03-22 00:01:31 -0800 | [diff] [blame] | 1052 | makex25->dte_facilities= dte_facilities; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | makex25->vc_facil_mask = x25_sk(sk)->vc_facil_mask; |
Shaun Pereira | cb65d50 | 2005-06-22 22:15:01 -0700 | [diff] [blame] | 1054 | /* ensure no reverse facil on accept */ |
| 1055 | makex25->vc_facil_mask &= ~X25_MASK_REVERSE; |
Shaun Pereira | a64b7b9 | 2006-03-22 00:01:31 -0800 | [diff] [blame] | 1056 | /* ensure no calling address extension on accept */ |
| 1057 | makex25->vc_facil_mask &= ~X25_MASK_CALLING_AE; |
Shaun Pereira | cb65d50 | 2005-06-22 22:15:01 -0700 | [diff] [blame] | 1058 | makex25->cudmatchlength = x25_sk(sk)->cudmatchlength; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | |
andrew hendry | 37cda78 | 2010-05-16 23:00:27 +0000 | [diff] [blame] | 1060 | /* Normally all calls are accepted immediately */ |
| 1061 | if (test_bit(X25_ACCPT_APPRV_FLAG, &makex25->flags)) { |
Shaun Pereira | ebc3f64 | 2005-06-22 22:16:17 -0700 | [diff] [blame] | 1062 | x25_write_internal(make, X25_CALL_ACCEPTED); |
| 1063 | makex25->state = X25_STATE_3; |
| 1064 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | |
Shaun Pereira | cb65d50 | 2005-06-22 22:15:01 -0700 | [diff] [blame] | 1066 | /* |
| 1067 | * Incoming Call User Data. |
| 1068 | */ |
Roel Kluin | 8db09f2 | 2009-03-13 16:04:12 -0700 | [diff] [blame] | 1069 | skb_copy_from_linear_data(skb, makex25->calluserdata.cuddata, skb->len); |
| 1070 | makex25->calluserdata.cudlength = skb->len; |
Shaun Pereira | cb65d50 | 2005-06-22 22:15:01 -0700 | [diff] [blame] | 1071 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | sk->sk_ack_backlog++; |
| 1073 | |
| 1074 | x25_insert_socket(make); |
| 1075 | |
| 1076 | skb_queue_head(&sk->sk_receive_queue, skb); |
| 1077 | |
| 1078 | x25_start_heartbeat(make); |
| 1079 | |
| 1080 | if (!sock_flag(sk, SOCK_DEAD)) |
David S. Miller | 676d236 | 2014-04-11 16:15:36 -0400 | [diff] [blame] | 1081 | sk->sk_data_ready(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | rc = 1; |
| 1083 | sock_put(sk); |
| 1084 | out: |
| 1085 | return rc; |
| 1086 | out_sock_put: |
| 1087 | sock_put(sk); |
| 1088 | out_clear_request: |
| 1089 | rc = 0; |
| 1090 | x25_transmit_clear_request(nb, lci, 0x01); |
| 1091 | goto out; |
| 1092 | } |
| 1093 | |
Ying Xue | 1b78414 | 2015-03-02 15:37:48 +0800 | [diff] [blame] | 1094 | static int x25_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | { |
| 1096 | struct sock *sk = sock->sk; |
| 1097 | struct x25_sock *x25 = x25_sk(sk); |
Steffen Hurrle | 342dfc3 | 2014-01-17 22:53:15 +0100 | [diff] [blame] | 1098 | DECLARE_SOCKADDR(struct sockaddr_x25 *, usx25, msg->msg_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | struct sockaddr_x25 sx25; |
| 1100 | struct sk_buff *skb; |
| 1101 | unsigned char *asmptr; |
| 1102 | int noblock = msg->msg_flags & MSG_DONTWAIT; |
| 1103 | size_t size; |
| 1104 | int qbit = 0, rc = -EINVAL; |
| 1105 | |
Arnd Bergmann | 77b2283 | 2011-01-22 23:44:59 +0100 | [diff] [blame] | 1106 | lock_sock(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_OOB|MSG_EOR|MSG_CMSG_COMPAT)) |
| 1108 | goto out; |
| 1109 | |
| 1110 | /* we currently don't support segmented records at the user interface */ |
| 1111 | if (!(msg->msg_flags & (MSG_EOR|MSG_OOB))) |
| 1112 | goto out; |
| 1113 | |
| 1114 | rc = -EADDRNOTAVAIL; |
| 1115 | if (sock_flag(sk, SOCK_ZAPPED)) |
| 1116 | goto out; |
| 1117 | |
| 1118 | rc = -EPIPE; |
| 1119 | if (sk->sk_shutdown & SEND_SHUTDOWN) { |
| 1120 | send_sig(SIGPIPE, current, 0); |
| 1121 | goto out; |
| 1122 | } |
| 1123 | |
| 1124 | rc = -ENETUNREACH; |
| 1125 | if (!x25->neighbour) |
| 1126 | goto out; |
| 1127 | |
| 1128 | if (usx25) { |
| 1129 | rc = -EINVAL; |
| 1130 | if (msg->msg_namelen < sizeof(sx25)) |
| 1131 | goto out; |
| 1132 | memcpy(&sx25, usx25, sizeof(sx25)); |
| 1133 | rc = -EISCONN; |
| 1134 | if (strcmp(x25->dest_addr.x25_addr, sx25.sx25_addr.x25_addr)) |
| 1135 | goto out; |
| 1136 | rc = -EINVAL; |
| 1137 | if (sx25.sx25_family != AF_X25) |
| 1138 | goto out; |
| 1139 | } else { |
| 1140 | /* |
| 1141 | * FIXME 1003.1g - if the socket is like this because |
| 1142 | * it has become closed (not started closed) we ought |
| 1143 | * to SIGPIPE, EPIPE; |
| 1144 | */ |
| 1145 | rc = -ENOTCONN; |
| 1146 | if (sk->sk_state != TCP_ESTABLISHED) |
| 1147 | goto out; |
| 1148 | |
| 1149 | sx25.sx25_family = AF_X25; |
| 1150 | sx25.sx25_addr = x25->dest_addr; |
| 1151 | } |
| 1152 | |
Alan Cox | 83e0bbc | 2009-03-27 00:28:21 -0700 | [diff] [blame] | 1153 | /* Sanity check the packet size */ |
| 1154 | if (len > 65535) { |
| 1155 | rc = -EMSGSIZE; |
| 1156 | goto out; |
| 1157 | } |
| 1158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | SOCK_DEBUG(sk, "x25_sendmsg: sendto: Addresses built.\n"); |
| 1160 | |
| 1161 | /* Build a packet */ |
| 1162 | SOCK_DEBUG(sk, "x25_sendmsg: sendto: building packet.\n"); |
| 1163 | |
| 1164 | if ((msg->msg_flags & MSG_OOB) && len > 32) |
| 1165 | len = 32; |
| 1166 | |
| 1167 | size = len + X25_MAX_L2_LEN + X25_EXT_MIN_LEN; |
| 1168 | |
Arnd Bergmann | 77b2283 | 2011-01-22 23:44:59 +0100 | [diff] [blame] | 1169 | release_sock(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | skb = sock_alloc_send_skb(sk, size, noblock, &rc); |
Arnd Bergmann | 77b2283 | 2011-01-22 23:44:59 +0100 | [diff] [blame] | 1171 | lock_sock(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | if (!skb) |
| 1173 | goto out; |
| 1174 | X25_SKB_CB(skb)->flags = msg->msg_flags; |
| 1175 | |
| 1176 | skb_reserve(skb, X25_MAX_L2_LEN + X25_EXT_MIN_LEN); |
| 1177 | |
| 1178 | /* |
| 1179 | * Put the data on the end |
| 1180 | */ |
| 1181 | SOCK_DEBUG(sk, "x25_sendmsg: Copying user data\n"); |
| 1182 | |
Arnaldo Carvalho de Melo | eeeb037 | 2007-03-14 21:04:34 -0300 | [diff] [blame] | 1183 | skb_reset_transport_header(skb); |
| 1184 | skb_put(skb, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | |
Al Viro | 6ce8e9c | 2014-04-06 21:25:44 -0400 | [diff] [blame] | 1186 | rc = memcpy_from_msg(skb_transport_header(skb), msg, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | if (rc) |
| 1188 | goto out_kfree_skb; |
| 1189 | |
| 1190 | /* |
| 1191 | * If the Q BIT Include socket option is in force, the first |
| 1192 | * byte of the user data is the logical value of the Q Bit. |
| 1193 | */ |
andrew hendry | cb863ff | 2010-05-16 22:59:41 +0000 | [diff] [blame] | 1194 | if (test_bit(X25_Q_BIT_FLAG, &x25->flags)) { |
Matthew Daley | cb101ed | 2011-10-14 18:45:04 +0000 | [diff] [blame] | 1195 | if (!pskb_may_pull(skb, 1)) |
| 1196 | goto out_kfree_skb; |
| 1197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | qbit = skb->data[0]; |
| 1199 | skb_pull(skb, 1); |
| 1200 | } |
| 1201 | |
| 1202 | /* |
| 1203 | * Push down the X.25 header |
| 1204 | */ |
| 1205 | SOCK_DEBUG(sk, "x25_sendmsg: Building X.25 Header.\n"); |
| 1206 | |
| 1207 | if (msg->msg_flags & MSG_OOB) { |
| 1208 | if (x25->neighbour->extended) { |
| 1209 | asmptr = skb_push(skb, X25_STD_MIN_LEN); |
| 1210 | *asmptr++ = ((x25->lci >> 8) & 0x0F) | X25_GFI_EXTSEQ; |
| 1211 | *asmptr++ = (x25->lci >> 0) & 0xFF; |
| 1212 | *asmptr++ = X25_INTERRUPT; |
| 1213 | } else { |
| 1214 | asmptr = skb_push(skb, X25_STD_MIN_LEN); |
| 1215 | *asmptr++ = ((x25->lci >> 8) & 0x0F) | X25_GFI_STDSEQ; |
| 1216 | *asmptr++ = (x25->lci >> 0) & 0xFF; |
| 1217 | *asmptr++ = X25_INTERRUPT; |
| 1218 | } |
| 1219 | } else { |
| 1220 | if (x25->neighbour->extended) { |
| 1221 | /* Build an Extended X.25 header */ |
| 1222 | asmptr = skb_push(skb, X25_EXT_MIN_LEN); |
| 1223 | *asmptr++ = ((x25->lci >> 8) & 0x0F) | X25_GFI_EXTSEQ; |
| 1224 | *asmptr++ = (x25->lci >> 0) & 0xFF; |
| 1225 | *asmptr++ = X25_DATA; |
| 1226 | *asmptr++ = X25_DATA; |
| 1227 | } else { |
| 1228 | /* Build an Standard X.25 header */ |
| 1229 | asmptr = skb_push(skb, X25_STD_MIN_LEN); |
| 1230 | *asmptr++ = ((x25->lci >> 8) & 0x0F) | X25_GFI_STDSEQ; |
| 1231 | *asmptr++ = (x25->lci >> 0) & 0xFF; |
| 1232 | *asmptr++ = X25_DATA; |
| 1233 | } |
| 1234 | |
| 1235 | if (qbit) |
| 1236 | skb->data[0] |= X25_Q_BIT; |
| 1237 | } |
| 1238 | |
| 1239 | SOCK_DEBUG(sk, "x25_sendmsg: Built header.\n"); |
| 1240 | SOCK_DEBUG(sk, "x25_sendmsg: Transmitting buffer\n"); |
| 1241 | |
| 1242 | rc = -ENOTCONN; |
| 1243 | if (sk->sk_state != TCP_ESTABLISHED) |
| 1244 | goto out_kfree_skb; |
| 1245 | |
| 1246 | if (msg->msg_flags & MSG_OOB) |
| 1247 | skb_queue_tail(&x25->interrupt_out_queue, skb); |
| 1248 | else { |
Roel Kluin | 8db09f2 | 2009-03-13 16:04:12 -0700 | [diff] [blame] | 1249 | rc = x25_output(sk, skb); |
| 1250 | len = rc; |
| 1251 | if (rc < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | kfree_skb(skb); |
andrew hendry | cb863ff | 2010-05-16 22:59:41 +0000 | [diff] [blame] | 1253 | else if (test_bit(X25_Q_BIT_FLAG, &x25->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | len++; |
| 1255 | } |
| 1256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | x25_kick(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | rc = len; |
| 1259 | out: |
Arnd Bergmann | 77b2283 | 2011-01-22 23:44:59 +0100 | [diff] [blame] | 1260 | release_sock(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | return rc; |
| 1262 | out_kfree_skb: |
| 1263 | kfree_skb(skb); |
| 1264 | goto out; |
| 1265 | } |
| 1266 | |
| 1267 | |
Ying Xue | 1b78414 | 2015-03-02 15:37:48 +0800 | [diff] [blame] | 1268 | static int x25_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | int flags) |
| 1270 | { |
| 1271 | struct sock *sk = sock->sk; |
| 1272 | struct x25_sock *x25 = x25_sk(sk); |
Steffen Hurrle | 342dfc3 | 2014-01-17 22:53:15 +0100 | [diff] [blame] | 1273 | DECLARE_SOCKADDR(struct sockaddr_x25 *, sx25, msg->msg_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | size_t copied; |
Dave Jones | 501e89d | 2011-11-01 16:26:44 +0000 | [diff] [blame] | 1275 | int qbit, header_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | struct sk_buff *skb; |
| 1277 | unsigned char *asmptr; |
| 1278 | int rc = -ENOTCONN; |
| 1279 | |
Arnd Bergmann | 77b2283 | 2011-01-22 23:44:59 +0100 | [diff] [blame] | 1280 | lock_sock(sk); |
Dave Jones | 501e89d | 2011-11-01 16:26:44 +0000 | [diff] [blame] | 1281 | |
| 1282 | if (x25->neighbour == NULL) |
| 1283 | goto out; |
| 1284 | |
| 1285 | header_len = x25->neighbour->extended ? |
| 1286 | X25_EXT_MIN_LEN : X25_STD_MIN_LEN; |
| 1287 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | /* |
| 1289 | * This works for seqpacket too. The receiver has ordered the queue for |
| 1290 | * us! We do one quick check first though |
| 1291 | */ |
| 1292 | if (sk->sk_state != TCP_ESTABLISHED) |
| 1293 | goto out; |
| 1294 | |
| 1295 | if (flags & MSG_OOB) { |
| 1296 | rc = -EINVAL; |
| 1297 | if (sock_flag(sk, SOCK_URGINLINE) || |
| 1298 | !skb_peek(&x25->interrupt_in_queue)) |
| 1299 | goto out; |
| 1300 | |
| 1301 | skb = skb_dequeue(&x25->interrupt_in_queue); |
| 1302 | |
Matthew Daley | cb101ed | 2011-10-14 18:45:04 +0000 | [diff] [blame] | 1303 | if (!pskb_may_pull(skb, X25_STD_MIN_LEN)) |
| 1304 | goto out_free_dgram; |
| 1305 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | skb_pull(skb, X25_STD_MIN_LEN); |
| 1307 | |
| 1308 | /* |
| 1309 | * No Q bit information on Interrupt data. |
| 1310 | */ |
andrew hendry | cb863ff | 2010-05-16 22:59:41 +0000 | [diff] [blame] | 1311 | if (test_bit(X25_Q_BIT_FLAG, &x25->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | asmptr = skb_push(skb, 1); |
| 1313 | *asmptr = 0x00; |
| 1314 | } |
| 1315 | |
| 1316 | msg->msg_flags |= MSG_OOB; |
| 1317 | } else { |
| 1318 | /* Now we can treat all alike */ |
Arnd Bergmann | 77b2283 | 2011-01-22 23:44:59 +0100 | [diff] [blame] | 1319 | release_sock(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT, |
| 1321 | flags & MSG_DONTWAIT, &rc); |
Arnd Bergmann | 77b2283 | 2011-01-22 23:44:59 +0100 | [diff] [blame] | 1322 | lock_sock(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | if (!skb) |
| 1324 | goto out; |
| 1325 | |
Matthew Daley | cb101ed | 2011-10-14 18:45:04 +0000 | [diff] [blame] | 1326 | if (!pskb_may_pull(skb, header_len)) |
| 1327 | goto out_free_dgram; |
| 1328 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | qbit = (skb->data[0] & X25_Q_BIT) == X25_Q_BIT; |
| 1330 | |
Matthew Daley | cb101ed | 2011-10-14 18:45:04 +0000 | [diff] [blame] | 1331 | skb_pull(skb, header_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | |
andrew hendry | cb863ff | 2010-05-16 22:59:41 +0000 | [diff] [blame] | 1333 | if (test_bit(X25_Q_BIT_FLAG, &x25->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | asmptr = skb_push(skb, 1); |
| 1335 | *asmptr = qbit; |
| 1336 | } |
| 1337 | } |
| 1338 | |
Arnaldo Carvalho de Melo | badff6d | 2007-03-13 13:06:52 -0300 | [diff] [blame] | 1339 | skb_reset_transport_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | copied = skb->len; |
| 1341 | |
| 1342 | if (copied > size) { |
| 1343 | copied = size; |
| 1344 | msg->msg_flags |= MSG_TRUNC; |
| 1345 | } |
| 1346 | |
YOSHIFUJI Hideaki | f8e1d201 | 2007-02-09 23:25:27 +0900 | [diff] [blame] | 1347 | /* Currently, each datagram always contains a complete record */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | msg->msg_flags |= MSG_EOR; |
| 1349 | |
David S. Miller | 51f3d02 | 2014-11-05 16:46:40 -0500 | [diff] [blame] | 1350 | rc = skb_copy_datagram_msg(skb, 0, msg, copied); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | if (rc) |
| 1352 | goto out_free_dgram; |
| 1353 | |
| 1354 | if (sx25) { |
| 1355 | sx25->sx25_family = AF_X25; |
| 1356 | sx25->sx25_addr = x25->dest_addr; |
Hannes Frederic Sowa | f3d3342 | 2013-11-21 03:14:22 +0100 | [diff] [blame] | 1357 | msg->msg_namelen = sizeof(*sx25); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | } |
| 1359 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | x25_check_rbuf(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | rc = copied; |
| 1362 | out_free_dgram: |
| 1363 | skb_free_datagram(sk, skb); |
| 1364 | out: |
Arnd Bergmann | 77b2283 | 2011-01-22 23:44:59 +0100 | [diff] [blame] | 1365 | release_sock(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | return rc; |
| 1367 | } |
| 1368 | |
| 1369 | |
| 1370 | static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) |
| 1371 | { |
| 1372 | struct sock *sk = sock->sk; |
| 1373 | struct x25_sock *x25 = x25_sk(sk); |
| 1374 | void __user *argp = (void __user *)arg; |
| 1375 | int rc; |
| 1376 | |
| 1377 | switch (cmd) { |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1378 | case TIOCOUTQ: { |
| 1379 | int amount; |
Eric Dumazet | 31e6d36 | 2009-06-17 19:05:41 -0700 | [diff] [blame] | 1380 | |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1381 | amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk); |
| 1382 | if (amount < 0) |
| 1383 | amount = 0; |
| 1384 | rc = put_user(amount, (unsigned int __user *)argp); |
| 1385 | break; |
| 1386 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1388 | case TIOCINQ: { |
| 1389 | struct sk_buff *skb; |
| 1390 | int amount = 0; |
| 1391 | /* |
| 1392 | * These two are safe on a single CPU system as |
| 1393 | * only user tasks fiddle here |
| 1394 | */ |
| 1395 | lock_sock(sk); |
| 1396 | if ((skb = skb_peek(&sk->sk_receive_queue)) != NULL) |
| 1397 | amount = skb->len; |
| 1398 | release_sock(sk); |
| 1399 | rc = put_user(amount, (unsigned int __user *)argp); |
| 1400 | break; |
| 1401 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1403 | case SIOCGSTAMP: |
| 1404 | rc = -EINVAL; |
| 1405 | if (sk) |
| 1406 | rc = sock_get_timestamp(sk, |
YOSHIFUJI Hideaki | f8e1d201 | 2007-02-09 23:25:27 +0900 | [diff] [blame] | 1407 | (struct timeval __user *)argp); |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1408 | break; |
| 1409 | case SIOCGSTAMPNS: |
| 1410 | rc = -EINVAL; |
| 1411 | if (sk) |
| 1412 | rc = sock_get_timestampns(sk, |
| 1413 | (struct timespec __user *)argp); |
| 1414 | break; |
| 1415 | case SIOCGIFADDR: |
| 1416 | case SIOCSIFADDR: |
| 1417 | case SIOCGIFDSTADDR: |
| 1418 | case SIOCSIFDSTADDR: |
| 1419 | case SIOCGIFBRDADDR: |
| 1420 | case SIOCSIFBRDADDR: |
| 1421 | case SIOCGIFNETMASK: |
| 1422 | case SIOCSIFNETMASK: |
| 1423 | case SIOCGIFMETRIC: |
| 1424 | case SIOCSIFMETRIC: |
| 1425 | rc = -EINVAL; |
| 1426 | break; |
| 1427 | case SIOCADDRT: |
| 1428 | case SIOCDELRT: |
| 1429 | rc = -EPERM; |
| 1430 | if (!capable(CAP_NET_ADMIN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | break; |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1432 | rc = x25_route_ioctl(cmd, argp); |
| 1433 | break; |
| 1434 | case SIOCX25GSUBSCRIP: |
| 1435 | rc = x25_subscr_ioctl(cmd, argp); |
| 1436 | break; |
| 1437 | case SIOCX25SSUBSCRIP: |
| 1438 | rc = -EPERM; |
| 1439 | if (!capable(CAP_NET_ADMIN)) |
Eric Dumazet | ae40eb1 | 2007-03-18 17:33:16 -0700 | [diff] [blame] | 1440 | break; |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1441 | rc = x25_subscr_ioctl(cmd, argp); |
| 1442 | break; |
| 1443 | case SIOCX25GFACILITIES: { |
| 1444 | lock_sock(sk); |
| 1445 | rc = copy_to_user(argp, &x25->facilities, |
| 1446 | sizeof(x25->facilities)) |
| 1447 | ? -EFAULT : 0; |
| 1448 | release_sock(sk); |
| 1449 | break; |
| 1450 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1452 | case SIOCX25SFACILITIES: { |
| 1453 | struct x25_facilities facilities; |
| 1454 | rc = -EFAULT; |
| 1455 | if (copy_from_user(&facilities, argp, sizeof(facilities))) |
| 1456 | break; |
| 1457 | rc = -EINVAL; |
| 1458 | lock_sock(sk); |
| 1459 | if (sk->sk_state != TCP_LISTEN && |
| 1460 | sk->sk_state != TCP_CLOSE) |
| 1461 | goto out_fac_release; |
| 1462 | if (facilities.pacsize_in < X25_PS16 || |
| 1463 | facilities.pacsize_in > X25_PS4096) |
| 1464 | goto out_fac_release; |
| 1465 | if (facilities.pacsize_out < X25_PS16 || |
| 1466 | facilities.pacsize_out > X25_PS4096) |
| 1467 | goto out_fac_release; |
| 1468 | if (facilities.winsize_in < 1 || |
| 1469 | facilities.winsize_in > 127) |
| 1470 | goto out_fac_release; |
| 1471 | if (facilities.throughput) { |
| 1472 | int out = facilities.throughput & 0xf0; |
| 1473 | int in = facilities.throughput & 0x0f; |
| 1474 | if (!out) |
| 1475 | facilities.throughput |= |
| 1476 | X25_DEFAULT_THROUGHPUT << 4; |
| 1477 | else if (out < 0x30 || out > 0xD0) |
andrew hendry | f90de66 | 2010-11-25 02:18:35 +0000 | [diff] [blame] | 1478 | goto out_fac_release; |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1479 | if (!in) |
| 1480 | facilities.throughput |= |
| 1481 | X25_DEFAULT_THROUGHPUT; |
| 1482 | else if (in < 0x03 || in > 0x0D) |
andrew hendry | f90de66 | 2010-11-25 02:18:35 +0000 | [diff] [blame] | 1483 | goto out_fac_release; |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1484 | } |
| 1485 | if (facilities.reverse && |
| 1486 | (facilities.reverse & 0x81) != 0x81) |
| 1487 | goto out_fac_release; |
| 1488 | x25->facilities = facilities; |
| 1489 | rc = 0; |
andrew hendry | f90de66 | 2010-11-25 02:18:35 +0000 | [diff] [blame] | 1490 | out_fac_release: |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1491 | release_sock(sk); |
| 1492 | break; |
| 1493 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1495 | case SIOCX25GDTEFACILITIES: { |
| 1496 | lock_sock(sk); |
| 1497 | rc = copy_to_user(argp, &x25->dte_facilities, |
| 1498 | sizeof(x25->dte_facilities)); |
| 1499 | release_sock(sk); |
| 1500 | if (rc) |
YOSHIFUJI Hideaki | f8e1d201 | 2007-02-09 23:25:27 +0900 | [diff] [blame] | 1501 | rc = -EFAULT; |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1502 | break; |
| 1503 | } |
| 1504 | |
| 1505 | case SIOCX25SDTEFACILITIES: { |
| 1506 | struct x25_dte_facilities dtefacs; |
| 1507 | rc = -EFAULT; |
| 1508 | if (copy_from_user(&dtefacs, argp, sizeof(dtefacs))) |
| 1509 | break; |
| 1510 | rc = -EINVAL; |
| 1511 | lock_sock(sk); |
| 1512 | if (sk->sk_state != TCP_LISTEN && |
| 1513 | sk->sk_state != TCP_CLOSE) |
| 1514 | goto out_dtefac_release; |
| 1515 | if (dtefacs.calling_len > X25_MAX_AE_LEN) |
| 1516 | goto out_dtefac_release; |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1517 | if (dtefacs.called_len > X25_MAX_AE_LEN) |
| 1518 | goto out_dtefac_release; |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1519 | x25->dte_facilities = dtefacs; |
| 1520 | rc = 0; |
andrew hendry | f90de66 | 2010-11-25 02:18:35 +0000 | [diff] [blame] | 1521 | out_dtefac_release: |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1522 | release_sock(sk); |
| 1523 | break; |
| 1524 | } |
| 1525 | |
| 1526 | case SIOCX25GCALLUSERDATA: { |
| 1527 | lock_sock(sk); |
| 1528 | rc = copy_to_user(argp, &x25->calluserdata, |
| 1529 | sizeof(x25->calluserdata)) |
| 1530 | ? -EFAULT : 0; |
| 1531 | release_sock(sk); |
| 1532 | break; |
| 1533 | } |
| 1534 | |
| 1535 | case SIOCX25SCALLUSERDATA: { |
| 1536 | struct x25_calluserdata calluserdata; |
| 1537 | |
| 1538 | rc = -EFAULT; |
| 1539 | if (copy_from_user(&calluserdata, argp, sizeof(calluserdata))) |
Shaun Pereira | a64b7b9 | 2006-03-22 00:01:31 -0800 | [diff] [blame] | 1540 | break; |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1541 | rc = -EINVAL; |
| 1542 | if (calluserdata.cudlength > X25_MAX_CUD_LEN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | break; |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1544 | lock_sock(sk); |
| 1545 | x25->calluserdata = calluserdata; |
| 1546 | release_sock(sk); |
| 1547 | rc = 0; |
| 1548 | break; |
| 1549 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1551 | case SIOCX25GCAUSEDIAG: { |
| 1552 | lock_sock(sk); |
| 1553 | rc = copy_to_user(argp, &x25->causediag, sizeof(x25->causediag)) |
| 1554 | ? -EFAULT : 0; |
| 1555 | release_sock(sk); |
| 1556 | break; |
| 1557 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1559 | case SIOCX25SCAUSEDIAG: { |
| 1560 | struct x25_causediag causediag; |
| 1561 | rc = -EFAULT; |
| 1562 | if (copy_from_user(&causediag, argp, sizeof(causediag))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1563 | break; |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1564 | lock_sock(sk); |
| 1565 | x25->causediag = causediag; |
| 1566 | release_sock(sk); |
| 1567 | rc = 0; |
| 1568 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1570 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1572 | case SIOCX25SCUDMATCHLEN: { |
| 1573 | struct x25_subaddr sub_addr; |
| 1574 | rc = -EINVAL; |
| 1575 | lock_sock(sk); |
| 1576 | if(sk->sk_state != TCP_CLOSE) |
| 1577 | goto out_cud_release; |
| 1578 | rc = -EFAULT; |
| 1579 | if (copy_from_user(&sub_addr, argp, |
| 1580 | sizeof(sub_addr))) |
| 1581 | goto out_cud_release; |
| 1582 | rc = -EINVAL; |
| 1583 | if (sub_addr.cudmatchlength > X25_MAX_CUD_LEN) |
| 1584 | goto out_cud_release; |
| 1585 | x25->cudmatchlength = sub_addr.cudmatchlength; |
| 1586 | rc = 0; |
andrew hendry | 3f0a069 | 2010-11-25 02:18:45 +0000 | [diff] [blame] | 1587 | out_cud_release: |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1588 | release_sock(sk); |
| 1589 | break; |
| 1590 | } |
Shaun Pereira | cb65d50 | 2005-06-22 22:15:01 -0700 | [diff] [blame] | 1591 | |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1592 | case SIOCX25CALLACCPTAPPRV: { |
| 1593 | rc = -EINVAL; |
| 1594 | lock_sock(sk); |
Dave Jones | 4ccb93c | 2013-06-28 12:13:52 -0400 | [diff] [blame] | 1595 | if (sk->sk_state == TCP_CLOSE) { |
| 1596 | clear_bit(X25_ACCPT_APPRV_FLAG, &x25->flags); |
| 1597 | rc = 0; |
| 1598 | } |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1599 | release_sock(sk); |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1600 | break; |
| 1601 | } |
Shaun Pereira | ebc3f64 | 2005-06-22 22:16:17 -0700 | [diff] [blame] | 1602 | |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1603 | case SIOCX25SENDCALLACCPT: { |
| 1604 | rc = -EINVAL; |
| 1605 | lock_sock(sk); |
| 1606 | if (sk->sk_state != TCP_ESTABLISHED) |
Dave Jones | 4ccb93c | 2013-06-28 12:13:52 -0400 | [diff] [blame] | 1607 | goto out_sendcallaccpt_release; |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1608 | /* must call accptapprv above */ |
| 1609 | if (test_bit(X25_ACCPT_APPRV_FLAG, &x25->flags)) |
Dave Jones | 4ccb93c | 2013-06-28 12:13:52 -0400 | [diff] [blame] | 1610 | goto out_sendcallaccpt_release; |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1611 | x25_write_internal(sk, X25_CALL_ACCEPTED); |
| 1612 | x25->state = X25_STATE_3; |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1613 | rc = 0; |
Dave Jones | 4ccb93c | 2013-06-28 12:13:52 -0400 | [diff] [blame] | 1614 | out_sendcallaccpt_release: |
| 1615 | release_sock(sk); |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1616 | break; |
| 1617 | } |
Shaun Pereira | ebc3f64 | 2005-06-22 22:16:17 -0700 | [diff] [blame] | 1618 | |
Joe Perches | fddc5f3 | 2011-07-01 09:43:13 +0000 | [diff] [blame] | 1619 | default: |
| 1620 | rc = -ENOIOCTLCMD; |
| 1621 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | } |
| 1623 | |
| 1624 | return rc; |
| 1625 | } |
| 1626 | |
Stephen Hemminger | ec1b4cf | 2009-10-05 05:58:39 +0000 | [diff] [blame] | 1627 | static const struct net_proto_family x25_family_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | .family = AF_X25, |
| 1629 | .create = x25_create, |
| 1630 | .owner = THIS_MODULE, |
| 1631 | }; |
| 1632 | |
Shaun Pereira | 1b06e6b | 2006-03-22 00:00:12 -0800 | [diff] [blame] | 1633 | #ifdef CONFIG_COMPAT |
| 1634 | static int compat_x25_subscr_ioctl(unsigned int cmd, |
| 1635 | struct compat_x25_subscrip_struct __user *x25_subscr32) |
| 1636 | { |
| 1637 | struct compat_x25_subscrip_struct x25_subscr; |
| 1638 | struct x25_neigh *nb; |
| 1639 | struct net_device *dev; |
| 1640 | int rc = -EINVAL; |
| 1641 | |
| 1642 | rc = -EFAULT; |
| 1643 | if (copy_from_user(&x25_subscr, x25_subscr32, sizeof(*x25_subscr32))) |
| 1644 | goto out; |
| 1645 | |
| 1646 | rc = -EINVAL; |
| 1647 | dev = x25_dev_get(x25_subscr.device); |
| 1648 | if (dev == NULL) |
| 1649 | goto out; |
| 1650 | |
| 1651 | nb = x25_get_neigh(dev); |
| 1652 | if (nb == NULL) |
| 1653 | goto out_dev_put; |
| 1654 | |
| 1655 | dev_put(dev); |
| 1656 | |
| 1657 | if (cmd == SIOCX25GSUBSCRIP) { |
andrew hendry | 5595a1a | 2010-11-25 02:18:15 +0000 | [diff] [blame] | 1658 | read_lock_bh(&x25_neigh_list_lock); |
Shaun Pereira | 1b06e6b | 2006-03-22 00:00:12 -0800 | [diff] [blame] | 1659 | x25_subscr.extended = nb->extended; |
| 1660 | x25_subscr.global_facil_mask = nb->global_facil_mask; |
andrew hendry | 5595a1a | 2010-11-25 02:18:15 +0000 | [diff] [blame] | 1661 | read_unlock_bh(&x25_neigh_list_lock); |
Shaun Pereira | 1b06e6b | 2006-03-22 00:00:12 -0800 | [diff] [blame] | 1662 | rc = copy_to_user(x25_subscr32, &x25_subscr, |
| 1663 | sizeof(*x25_subscr32)) ? -EFAULT : 0; |
| 1664 | } else { |
| 1665 | rc = -EINVAL; |
| 1666 | if (x25_subscr.extended == 0 || x25_subscr.extended == 1) { |
| 1667 | rc = 0; |
andrew hendry | 5595a1a | 2010-11-25 02:18:15 +0000 | [diff] [blame] | 1668 | write_lock_bh(&x25_neigh_list_lock); |
Shaun Pereira | 1b06e6b | 2006-03-22 00:00:12 -0800 | [diff] [blame] | 1669 | nb->extended = x25_subscr.extended; |
| 1670 | nb->global_facil_mask = x25_subscr.global_facil_mask; |
andrew hendry | 5595a1a | 2010-11-25 02:18:15 +0000 | [diff] [blame] | 1671 | write_unlock_bh(&x25_neigh_list_lock); |
Shaun Pereira | 1b06e6b | 2006-03-22 00:00:12 -0800 | [diff] [blame] | 1672 | } |
| 1673 | } |
| 1674 | x25_neigh_put(nb); |
| 1675 | out: |
| 1676 | return rc; |
| 1677 | out_dev_put: |
| 1678 | dev_put(dev); |
| 1679 | goto out; |
| 1680 | } |
| 1681 | |
| 1682 | static int compat_x25_ioctl(struct socket *sock, unsigned int cmd, |
| 1683 | unsigned long arg) |
| 1684 | { |
| 1685 | void __user *argp = compat_ptr(arg); |
| 1686 | struct sock *sk = sock->sk; |
| 1687 | |
| 1688 | int rc = -ENOIOCTLCMD; |
| 1689 | |
| 1690 | switch(cmd) { |
| 1691 | case TIOCOUTQ: |
| 1692 | case TIOCINQ: |
| 1693 | rc = x25_ioctl(sock, cmd, (unsigned long)argp); |
| 1694 | break; |
| 1695 | case SIOCGSTAMP: |
| 1696 | rc = -EINVAL; |
| 1697 | if (sk) |
| 1698 | rc = compat_sock_get_timestamp(sk, |
| 1699 | (struct timeval __user*)argp); |
| 1700 | break; |
Eric Dumazet | ae40eb1 | 2007-03-18 17:33:16 -0700 | [diff] [blame] | 1701 | case SIOCGSTAMPNS: |
| 1702 | rc = -EINVAL; |
| 1703 | if (sk) |
| 1704 | rc = compat_sock_get_timestampns(sk, |
| 1705 | (struct timespec __user*)argp); |
| 1706 | break; |
Shaun Pereira | 1b06e6b | 2006-03-22 00:00:12 -0800 | [diff] [blame] | 1707 | case SIOCGIFADDR: |
| 1708 | case SIOCSIFADDR: |
| 1709 | case SIOCGIFDSTADDR: |
| 1710 | case SIOCSIFDSTADDR: |
| 1711 | case SIOCGIFBRDADDR: |
| 1712 | case SIOCSIFBRDADDR: |
| 1713 | case SIOCGIFNETMASK: |
| 1714 | case SIOCSIFNETMASK: |
| 1715 | case SIOCGIFMETRIC: |
| 1716 | case SIOCSIFMETRIC: |
| 1717 | rc = -EINVAL; |
| 1718 | break; |
| 1719 | case SIOCADDRT: |
| 1720 | case SIOCDELRT: |
| 1721 | rc = -EPERM; |
| 1722 | if (!capable(CAP_NET_ADMIN)) |
| 1723 | break; |
| 1724 | rc = x25_route_ioctl(cmd, argp); |
| 1725 | break; |
| 1726 | case SIOCX25GSUBSCRIP: |
| 1727 | rc = compat_x25_subscr_ioctl(cmd, argp); |
| 1728 | break; |
| 1729 | case SIOCX25SSUBSCRIP: |
| 1730 | rc = -EPERM; |
| 1731 | if (!capable(CAP_NET_ADMIN)) |
| 1732 | break; |
| 1733 | rc = compat_x25_subscr_ioctl(cmd, argp); |
| 1734 | break; |
| 1735 | case SIOCX25GFACILITIES: |
| 1736 | case SIOCX25SFACILITIES: |
Shaun Pereira | 9a6b9f2 | 2006-03-22 00:02:00 -0800 | [diff] [blame] | 1737 | case SIOCX25GDTEFACILITIES: |
| 1738 | case SIOCX25SDTEFACILITIES: |
Shaun Pereira | 1b06e6b | 2006-03-22 00:00:12 -0800 | [diff] [blame] | 1739 | case SIOCX25GCALLUSERDATA: |
| 1740 | case SIOCX25SCALLUSERDATA: |
| 1741 | case SIOCX25GCAUSEDIAG: |
Andrew Hendry | 386e50c | 2009-11-18 23:30:41 -0800 | [diff] [blame] | 1742 | case SIOCX25SCAUSEDIAG: |
Shaun Pereira | 1b06e6b | 2006-03-22 00:00:12 -0800 | [diff] [blame] | 1743 | case SIOCX25SCUDMATCHLEN: |
| 1744 | case SIOCX25CALLACCPTAPPRV: |
| 1745 | case SIOCX25SENDCALLACCPT: |
| 1746 | rc = x25_ioctl(sock, cmd, (unsigned long)argp); |
| 1747 | break; |
| 1748 | default: |
| 1749 | rc = -ENOIOCTLCMD; |
| 1750 | break; |
| 1751 | } |
| 1752 | return rc; |
| 1753 | } |
| 1754 | #endif |
| 1755 | |
Arnd Bergmann | 9177490 | 2009-11-05 04:37:29 +0000 | [diff] [blame] | 1756 | static const struct proto_ops x25_proto_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1757 | .family = AF_X25, |
| 1758 | .owner = THIS_MODULE, |
| 1759 | .release = x25_release, |
| 1760 | .bind = x25_bind, |
| 1761 | .connect = x25_connect, |
| 1762 | .socketpair = sock_no_socketpair, |
| 1763 | .accept = x25_accept, |
| 1764 | .getname = x25_getname, |
andrew hendry | 768190f | 2010-09-21 15:24:45 +0000 | [diff] [blame] | 1765 | .poll = datagram_poll, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | .ioctl = x25_ioctl, |
Shaun Pereira | 1b06e6b | 2006-03-22 00:00:12 -0800 | [diff] [blame] | 1767 | #ifdef CONFIG_COMPAT |
| 1768 | .compat_ioctl = compat_x25_ioctl, |
| 1769 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | .listen = x25_listen, |
| 1771 | .shutdown = sock_no_shutdown, |
| 1772 | .setsockopt = x25_setsockopt, |
| 1773 | .getsockopt = x25_getsockopt, |
| 1774 | .sendmsg = x25_sendmsg, |
| 1775 | .recvmsg = x25_recvmsg, |
| 1776 | .mmap = sock_no_mmap, |
| 1777 | .sendpage = sock_no_sendpage, |
| 1778 | }; |
| 1779 | |
Stephen Hemminger | 7546dd9 | 2009-03-09 08:18:29 +0000 | [diff] [blame] | 1780 | static struct packet_type x25_packet_type __read_mostly = { |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 1781 | .type = cpu_to_be16(ETH_P_X25), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1782 | .func = x25_lapb_receive_frame, |
| 1783 | }; |
| 1784 | |
| 1785 | static struct notifier_block x25_dev_notifier = { |
| 1786 | .notifier_call = x25_device_event, |
| 1787 | }; |
| 1788 | |
| 1789 | void x25_kill_by_neigh(struct x25_neigh *nb) |
| 1790 | { |
| 1791 | struct sock *s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | |
| 1793 | write_lock_bh(&x25_list_lock); |
| 1794 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1795 | sk_for_each(s, &x25_list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1796 | if (x25_sk(s)->neighbour == nb) |
| 1797 | x25_disconnect(s, ENETUNREACH, 0, 0); |
| 1798 | |
| 1799 | write_unlock_bh(&x25_list_lock); |
Andrew Hendry | 95a9dc4 | 2007-02-08 13:34:02 -0800 | [diff] [blame] | 1800 | |
| 1801 | /* Remove any related forwards */ |
| 1802 | x25_clear_forward_by_dev(nb->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | } |
| 1804 | |
| 1805 | static int __init x25_init(void) |
| 1806 | { |
linzhang | 5367883 | 2017-05-17 12:05:07 +0800 | [diff] [blame] | 1807 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | |
linzhang | 5367883 | 2017-05-17 12:05:07 +0800 | [diff] [blame] | 1809 | rc = proto_register(&x25_proto, 0); |
| 1810 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | goto out; |
| 1812 | |
andrew hendry | 1fd975a | 2009-11-24 15:15:42 +0000 | [diff] [blame] | 1813 | rc = sock_register(&x25_family_ops); |
linzhang | 5367883 | 2017-05-17 12:05:07 +0800 | [diff] [blame] | 1814 | if (rc) |
andrew hendry | 1fd975a | 2009-11-24 15:15:42 +0000 | [diff] [blame] | 1815 | goto out_proto; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | |
| 1817 | dev_add_pack(&x25_packet_type); |
| 1818 | |
andrew hendry | 1fd975a | 2009-11-24 15:15:42 +0000 | [diff] [blame] | 1819 | rc = register_netdevice_notifier(&x25_dev_notifier); |
linzhang | 5367883 | 2017-05-17 12:05:07 +0800 | [diff] [blame] | 1820 | if (rc) |
andrew hendry | 1fd975a | 2009-11-24 15:15:42 +0000 | [diff] [blame] | 1821 | goto out_sock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | |
linzhang | 5367883 | 2017-05-17 12:05:07 +0800 | [diff] [blame] | 1823 | rc = x25_register_sysctl(); |
| 1824 | if (rc) |
| 1825 | goto out_dev; |
| 1826 | |
| 1827 | rc = x25_proc_init(); |
| 1828 | if (rc) |
| 1829 | goto out_sysctl; |
| 1830 | |
wangweidong | b73e9e3 | 2013-12-06 19:24:33 +0800 | [diff] [blame] | 1831 | pr_info("Linux Version 0.2\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | out: |
| 1834 | return rc; |
linzhang | 5367883 | 2017-05-17 12:05:07 +0800 | [diff] [blame] | 1835 | out_sysctl: |
| 1836 | x25_unregister_sysctl(); |
andrew hendry | 1fd975a | 2009-11-24 15:15:42 +0000 | [diff] [blame] | 1837 | out_dev: |
| 1838 | unregister_netdevice_notifier(&x25_dev_notifier); |
| 1839 | out_sock: |
linzhang | 5367883 | 2017-05-17 12:05:07 +0800 | [diff] [blame] | 1840 | dev_remove_pack(&x25_packet_type); |
andrew hendry | 1fd975a | 2009-11-24 15:15:42 +0000 | [diff] [blame] | 1841 | sock_unregister(AF_X25); |
| 1842 | out_proto: |
| 1843 | proto_unregister(&x25_proto); |
| 1844 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | } |
| 1846 | module_init(x25_init); |
| 1847 | |
| 1848 | static void __exit x25_exit(void) |
| 1849 | { |
| 1850 | x25_proc_exit(); |
| 1851 | x25_link_free(); |
| 1852 | x25_route_free(); |
| 1853 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | x25_unregister_sysctl(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | |
| 1856 | unregister_netdevice_notifier(&x25_dev_notifier); |
| 1857 | |
| 1858 | dev_remove_pack(&x25_packet_type); |
| 1859 | |
| 1860 | sock_unregister(AF_X25); |
| 1861 | proto_unregister(&x25_proto); |
| 1862 | } |
| 1863 | module_exit(x25_exit); |
| 1864 | |
| 1865 | MODULE_AUTHOR("Jonathan Naylor <g4klx@g4klx.demon.co.uk>"); |
| 1866 | MODULE_DESCRIPTION("The X.25 Packet Layer network layer protocol"); |
| 1867 | MODULE_LICENSE("GPL"); |
| 1868 | MODULE_ALIAS_NETPROTO(PF_X25); |