1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
| 271
274 275 static int inet_create(struct net *net, struct socket *sock, int protocol, 276 int kern) 277 { 278 struct sock *sk; 279 struct inet_protosw *answer; 280 struct inet_sock *inet; 281 struct proto *answer_prot; 282 unsigned char answer_flags; 283 char answer_no_check; 284 int try_loading_module = 0; 285 int err; 286 287 if (unlikely(!inet_ehash_secret)) 288 if (sock->type != SOCK_RAW && sock->type != SOCK_DGRAM) 289 build_ehash_secret(); 290 291 sock->state = SS_UNCONNECTED; 292 293 294 lookup_protocol: 295 err = -ESOCKTNOSUPPORT; 296 rcu_read_lock(); 297 list_for_each_entry_rcu(answer, &inetsw[sock->type], list) { 298 299 err = 0; 300 301 if (protocol == answer->protocol) { 302 if (protocol != IPPROTO_IP) 303 break; 304 } else { 305 306 if (IPPROTO_IP == protocol) { 307 protocol = answer->protocol; 308 break; 309 } 310 if (IPPROTO_IP == answer->protocol) 311 break; 312 } 313 err = -EPROTONOSUPPORT; 314 } 315 316 if (unlikely(err)) { 317 if (try_loading_module < 2) { 318 rcu_read_unlock(); 319
323 if (++try_loading_module == 1) 324 request_module("net-pf-%d-proto-%d-type-%d", 325 PF_INET, protocol, sock->type); 326
330 else 331 request_module("net-pf-%d-proto-%d", 332 PF_INET, protocol); 333 goto lookup_protocol; 334 } else 335 goto out_rcu_unlock; 336 } 337 338 err = -EPERM; 339 if (sock->type == SOCK_RAW && !kern && 340 !ns_capable(net->user_ns, CAP_NET_RAW)) 341 goto out_rcu_unlock; 342 343 sock->ops = answer->ops; 344 answer_prot = answer->prot; 345 answer_no_check = answer->no_check; 346 answer_flags = answer->flags; 347 rcu_read_unlock(); 348 349 WARN_ON(answer_prot->slab == NULL); 350 351 err = -ENOBUFS; 352 sk = sk_alloc(net, PF_INET, GFP_KERNEL, answer_prot); 353 if (sk == NULL) 354 goto out; 355 356 err = 0; 357 sk->sk_no_check = answer_no_check; 358 if (INET_PROTOSW_REUSE & answer_flags) 359 sk->sk_reuse = SK_CAN_REUSE; 360 361 inet = inet_sk(sk); 362 inet->is_icsk = (INET_PROTOSW_ICSK & answer_flags) != 0; 363 364 inet->nodefrag = 0; 365 366 if (SOCK_RAW == sock->type) { 367 inet->inet_num = protocol; 368 if (IPPROTO_RAW == protocol) 369 inet->hdrincl = 1; 370 } 371 372 if (ipv4_config.no_pmtu_disc) 373 inet->pmtudisc = IP_PMTUDISC_DONT; 374 else 375 inet->pmtudisc = IP_PMTUDISC_WANT; 376 377 inet->inet_id = 0; 378 379 sock_init_data(sock, sk); 380 381 sk->sk_destruct = inet_sock_destruct; 382 sk->sk_protocol = protocol; 383 sk->sk_backlog_rcv = sk->sk_prot->backlog_rcv; 384 385 inet->uc_ttl = -1; 386 inet->mc_loop = 1; 387 inet->mc_ttl = 1; 388 inet->mc_all = 1; 389 inet->mc_index = 0; 390 inet->mc_list = NULL; 391 inet->rcv_tos = 0; 392 393 sk_refcnt_debug_inc(sk); 394 395 if (inet->inet_num) { 396
401 inet->inet_sport = htons(inet->inet_num); 402 403 sk->sk_prot->hash(sk); 404 } 405 406 if (sk->sk_prot->init) { 407 err = sk->sk_prot->init(sk); 408 if (err) 409 sk_common_release(sk); 410 } 411 out: 412 return err; 413 out_rcu_unlock: 414 rcu_read_unlock(); 415 goto out; 416 }
|