aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/devinet.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/ipv4/devinet.c')
-rw-r--r--net/ipv4/devinet.c111
1 files changed, 17 insertions, 94 deletions
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index e3126612fcbb..5cdbc102a418 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -1311,58 +1311,6 @@ static int devinet_conf_proc(ctl_table *ctl, int write,
1311 return ret; 1311 return ret;
1312} 1312}
1313 1313
1314static int devinet_conf_sysctl(ctl_table *table,
1315 void __user *oldval, size_t __user *oldlenp,
1316 void __user *newval, size_t newlen)
1317{
1318 struct ipv4_devconf *cnf;
1319 struct net *net;
1320 int *valp = table->data;
1321 int new;
1322 int i;
1323
1324 if (!newval || !newlen)
1325 return 0;
1326
1327 if (newlen != sizeof(int))
1328 return -EINVAL;
1329
1330 if (get_user(new, (int __user *)newval))
1331 return -EFAULT;
1332
1333 if (new == *valp)
1334 return 0;
1335
1336 if (oldval && oldlenp) {
1337 size_t len;
1338
1339 if (get_user(len, oldlenp))
1340 return -EFAULT;
1341
1342 if (len) {
1343 if (len > table->maxlen)
1344 len = table->maxlen;
1345 if (copy_to_user(oldval, valp, len))
1346 return -EFAULT;
1347 if (put_user(len, oldlenp))
1348 return -EFAULT;
1349 }
1350 }
1351
1352 *valp = new;
1353
1354 cnf = table->extra1;
1355 net = table->extra2;
1356 i = (int *)table->data - cnf->data;
1357
1358 set_bit(i, cnf->state);
1359
1360 if (cnf == net->ipv4.devconf_dflt)
1361 devinet_copy_dflt_conf(net, i);
1362
1363 return 1;
1364}
1365
1366static int devinet_sysctl_forward(ctl_table *ctl, int write, 1314static int devinet_sysctl_forward(ctl_table *ctl, int write,
1367 void __user *buffer, 1315 void __user *buffer,
1368 size_t *lenp, loff_t *ppos) 1316 size_t *lenp, loff_t *ppos)
@@ -1408,47 +1356,28 @@ int ipv4_doint_and_flush(ctl_table *ctl, int write,
1408 return ret; 1356 return ret;
1409} 1357}
1410 1358
1411int ipv4_doint_and_flush_strategy(ctl_table *table, 1359#define DEVINET_SYSCTL_ENTRY(attr, name, mval, proc) \
1412 void __user *oldval, size_t __user *oldlenp,
1413 void __user *newval, size_t newlen)
1414{
1415 int ret = devinet_conf_sysctl(table, oldval, oldlenp, newval, newlen);
1416 struct net *net = table->extra2;
1417
1418 if (ret == 1)
1419 rt_cache_flush(net, 0);
1420
1421 return ret;
1422}
1423
1424
1425#define DEVINET_SYSCTL_ENTRY(attr, name, mval, proc, sysctl) \
1426 { \ 1360 { \
1427 .ctl_name = NET_IPV4_CONF_ ## attr, \
1428 .procname = name, \ 1361 .procname = name, \
1429 .data = ipv4_devconf.data + \ 1362 .data = ipv4_devconf.data + \
1430 NET_IPV4_CONF_ ## attr - 1, \ 1363 NET_IPV4_CONF_ ## attr - 1, \
1431 .maxlen = sizeof(int), \ 1364 .maxlen = sizeof(int), \
1432 .mode = mval, \ 1365 .mode = mval, \
1433 .proc_handler = proc, \ 1366 .proc_handler = proc, \
1434 .strategy = sysctl, \
1435 .extra1 = &ipv4_devconf, \ 1367 .extra1 = &ipv4_devconf, \
1436 } 1368 }
1437 1369
1438#define DEVINET_SYSCTL_RW_ENTRY(attr, name) \ 1370#define DEVINET_SYSCTL_RW_ENTRY(attr, name) \
1439 DEVINET_SYSCTL_ENTRY(attr, name, 0644, devinet_conf_proc, \ 1371 DEVINET_SYSCTL_ENTRY(attr, name, 0644, devinet_conf_proc)
1440 devinet_conf_sysctl)
1441 1372
1442#define DEVINET_SYSCTL_RO_ENTRY(attr, name) \ 1373#define DEVINET_SYSCTL_RO_ENTRY(attr, name) \
1443 DEVINET_SYSCTL_ENTRY(attr, name, 0444, devinet_conf_proc, \ 1374 DEVINET_SYSCTL_ENTRY(attr, name, 0444, devinet_conf_proc)
1444 devinet_conf_sysctl)
1445 1375
1446#define DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, proc, sysctl) \ 1376#define DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, proc) \
1447 DEVINET_SYSCTL_ENTRY(attr, name, 0644, proc, sysctl) 1377 DEVINET_SYSCTL_ENTRY(attr, name, 0644, proc)
1448 1378
1449#define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \ 1379#define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
1450 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush, \ 1380 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
1451 ipv4_doint_and_flush_strategy)
1452 1381
1453static struct devinet_sysctl_table { 1382static struct devinet_sysctl_table {
1454 struct ctl_table_header *sysctl_header; 1383 struct ctl_table_header *sysctl_header;
@@ -1457,8 +1386,7 @@ static struct devinet_sysctl_table {
1457} devinet_sysctl = { 1386} devinet_sysctl = {
1458 .devinet_vars = { 1387 .devinet_vars = {
1459 DEVINET_SYSCTL_COMPLEX_ENTRY(FORWARDING, "forwarding", 1388 DEVINET_SYSCTL_COMPLEX_ENTRY(FORWARDING, "forwarding",
1460 devinet_sysctl_forward, 1389 devinet_sysctl_forward),
1461 devinet_conf_sysctl),
1462 DEVINET_SYSCTL_RO_ENTRY(MC_FORWARDING, "mc_forwarding"), 1390 DEVINET_SYSCTL_RO_ENTRY(MC_FORWARDING, "mc_forwarding"),
1463 1391
1464 DEVINET_SYSCTL_RW_ENTRY(ACCEPT_REDIRECTS, "accept_redirects"), 1392 DEVINET_SYSCTL_RW_ENTRY(ACCEPT_REDIRECTS, "accept_redirects"),
@@ -1490,7 +1418,7 @@ static struct devinet_sysctl_table {
1490}; 1418};
1491 1419
1492static int __devinet_sysctl_register(struct net *net, char *dev_name, 1420static int __devinet_sysctl_register(struct net *net, char *dev_name,
1493 int ctl_name, struct ipv4_devconf *p) 1421 struct ipv4_devconf *p)
1494{ 1422{
1495 int i; 1423 int i;
1496 struct devinet_sysctl_table *t; 1424 struct devinet_sysctl_table *t;
@@ -1498,9 +1426,9 @@ static int __devinet_sysctl_register(struct net *net, char *dev_name,
1498#define DEVINET_CTL_PATH_DEV 3 1426#define DEVINET_CTL_PATH_DEV 3
1499 1427
1500 struct ctl_path devinet_ctl_path[] = { 1428 struct ctl_path devinet_ctl_path[] = {
1501 { .procname = "net", .ctl_name = CTL_NET, }, 1429 { .procname = "net", },
1502 { .procname = "ipv4", .ctl_name = NET_IPV4, }, 1430 { .procname = "ipv4", },
1503 { .procname = "conf", .ctl_name = NET_IPV4_CONF, }, 1431 { .procname = "conf", },
1504 { /* to be set */ }, 1432 { /* to be set */ },
1505 { }, 1433 { },
1506 }; 1434 };
@@ -1525,7 +1453,6 @@ static int __devinet_sysctl_register(struct net *net, char *dev_name,
1525 goto free; 1453 goto free;
1526 1454
1527 devinet_ctl_path[DEVINET_CTL_PATH_DEV].procname = t->dev_name; 1455 devinet_ctl_path[DEVINET_CTL_PATH_DEV].procname = t->dev_name;
1528 devinet_ctl_path[DEVINET_CTL_PATH_DEV].ctl_name = ctl_name;
1529 1456
1530 t->sysctl_header = register_net_sysctl_table(net, devinet_ctl_path, 1457 t->sysctl_header = register_net_sysctl_table(net, devinet_ctl_path,
1531 t->devinet_vars); 1458 t->devinet_vars);
@@ -1559,9 +1486,9 @@ static void __devinet_sysctl_unregister(struct ipv4_devconf *cnf)
1559static void devinet_sysctl_register(struct in_device *idev) 1486static void devinet_sysctl_register(struct in_device *idev)
1560{ 1487{
1561 neigh_sysctl_register(idev->dev, idev->arp_parms, NET_IPV4, 1488 neigh_sysctl_register(idev->dev, idev->arp_parms, NET_IPV4,
1562 NET_IPV4_NEIGH, "ipv4", NULL, NULL); 1489 NET_IPV4_NEIGH, "ipv4", NULL);
1563 __devinet_sysctl_register(dev_net(idev->dev), idev->dev->name, 1490 __devinet_sysctl_register(dev_net(idev->dev), idev->dev->name,
1564 idev->dev->ifindex, &idev->cnf); 1491 &idev->cnf);
1565} 1492}
1566 1493
1567static void devinet_sysctl_unregister(struct in_device *idev) 1494static void devinet_sysctl_unregister(struct in_device *idev)
@@ -1572,14 +1499,12 @@ static void devinet_sysctl_unregister(struct in_device *idev)
1572 1499
1573static struct ctl_table ctl_forward_entry[] = { 1500static struct ctl_table ctl_forward_entry[] = {
1574 { 1501 {
1575 .ctl_name = NET_IPV4_FORWARD,
1576 .procname = "ip_forward", 1502 .procname = "ip_forward",
1577 .data = &ipv4_devconf.data[ 1503 .data = &ipv4_devconf.data[
1578 NET_IPV4_CONF_FORWARDING - 1], 1504 NET_IPV4_CONF_FORWARDING - 1],
1579 .maxlen = sizeof(int), 1505 .maxlen = sizeof(int),
1580 .mode = 0644, 1506 .mode = 0644,
1581 .proc_handler = devinet_sysctl_forward, 1507 .proc_handler = devinet_sysctl_forward,
1582 .strategy = devinet_conf_sysctl,
1583 .extra1 = &ipv4_devconf, 1508 .extra1 = &ipv4_devconf,
1584 .extra2 = &init_net, 1509 .extra2 = &init_net,
1585 }, 1510 },
@@ -1587,8 +1512,8 @@ static struct ctl_table ctl_forward_entry[] = {
1587}; 1512};
1588 1513
1589static __net_initdata struct ctl_path net_ipv4_path[] = { 1514static __net_initdata struct ctl_path net_ipv4_path[] = {
1590 { .procname = "net", .ctl_name = CTL_NET, }, 1515 { .procname = "net", },
1591 { .procname = "ipv4", .ctl_name = NET_IPV4, }, 1516 { .procname = "ipv4", },
1592 { }, 1517 { },
1593}; 1518};
1594#endif 1519#endif
@@ -1627,13 +1552,11 @@ static __net_init int devinet_init_net(struct net *net)
1627 } 1552 }
1628 1553
1629#ifdef CONFIG_SYSCTL 1554#ifdef CONFIG_SYSCTL
1630 err = __devinet_sysctl_register(net, "all", 1555 err = __devinet_sysctl_register(net, "all", all);
1631 NET_PROTO_CONF_ALL, all);
1632 if (err < 0) 1556 if (err < 0)
1633 goto err_reg_all; 1557 goto err_reg_all;
1634 1558
1635 err = __devinet_sysctl_register(net, "default", 1559 err = __devinet_sysctl_register(net, "default", dflt);
1636 NET_PROTO_CONF_DEFAULT, dflt);
1637 if (err < 0) 1560 if (err < 0)
1638 goto err_reg_dflt; 1561 goto err_reg_dflt;
1639 1562