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
| 1243 int __sock_create(struct net *net, int family, int type, int protocol, 1244 struct socket **res, int kern) 1245 { 1246 int err; 1247 struct socket *sock; 1248 const struct net_proto_family *pf; 1249 1250
1253 if (family < 0 || family >= NPROTO) 1254 return -EAFNOSUPPORT; 1255 if (type < 0 || type >= SOCK_MAX) 1256 return -EINVAL; 1257 1258
1263 if (family == PF_INET && type == SOCK_PACKET) { 1264 static int warned; 1265 if (!warned) { 1266 warned = 1; 1267 printk(KERN_INFO "%s uses obsolete (PF_INET,SOCK_PACKET)\n", 1268 current->comm); 1269 } 1270 family = PF_PACKET; 1271 } 1272 1273 err = security_socket_create(family, type, protocol, kern); 1274 if (err) 1275 return err; 1276 1277
1282 sock = sock_alloc(); 1283 if (!sock) { 1284 net_warn_ratelimited("socket: no more sockets\n"); 1285 return -ENFILE;
1287 } 1288 1289 sock->type = type; 1290 1291 #ifdef CONFIG_MODULES 1292
1298 if (rcu_access_pointer(net_families[family]) == NULL) 1299 request_module("net-pf-%d", family); 1300 #endif 1301 1302 rcu_read_lock(); 1303 pf = rcu_dereference(net_families[family]); 1304 err = -EAFNOSUPPORT; 1305 if (!pf) 1306 goto out_release; 1307 1308
1312 if (!try_module_get(pf->owner)) 1313 goto out_release; 1314 1315 1316 rcu_read_unlock(); 1317 1318 err = pf->create(net, sock, protocol, kern); 1319 if (err < 0) 1320 goto out_module_put; 1321 1322
1326 if (!try_module_get(sock->ops->owner)) 1327 goto out_module_busy; 1328 1329
1333 module_put(pf->owner); 1334 err = security_socket_post_create(sock, family, type, protocol, kern); 1335 if (err) 1336 goto out_sock_release; 1337 *res = sock; 1338 1339 return 0; 1340 1341 out_module_busy: 1342 err = -EAFNOSUPPORT; 1343 out_module_put: 1344 sock->ops = NULL; 1345 module_put(pf->owner); 1346 out_sock_release: 1347 sock_release(sock); 1348 return err; 1349 1350 out_release: 1351 rcu_read_unlock(); 1352 goto out_sock_release; 1353 } 1354 EXPORT_SYMBOL(__sock_create);
|