aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/devinet.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2007-06-05 02:34:44 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-06-07 16:39:13 -0400
commit42f811b8bcdf6695bf74de580b1daf53445e8949 (patch)
treec7c9dd321c63eb24c5d41488b47b7178c6c9b572 /net/ipv4/devinet.c
parent8d76527e728d00d1cf9d5dd663caffb2dcf05ae6 (diff)
[IPV4]: Convert IPv4 devconf to an array
This patch converts the ipv4_devconf config members (everything except sysctl) to an array. This allows easier manipulation which will be needed later on to provide better management of default config values. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/devinet.c')
-rw-r--r--net/ipv4/devinet.c264
1 files changed, 75 insertions, 189 deletions
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 88a22d20bf73..00940660739f 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -64,20 +64,26 @@
64#include <net/rtnetlink.h> 64#include <net/rtnetlink.h>
65 65
66struct ipv4_devconf ipv4_devconf = { 66struct ipv4_devconf ipv4_devconf = {
67 .accept_redirects = 1, 67 .data = {
68 .send_redirects = 1, 68 [NET_IPV4_CONF_ACCEPT_REDIRECTS - 1] = 1,
69 .secure_redirects = 1, 69 [NET_IPV4_CONF_SEND_REDIRECTS - 1] = 1,
70 .shared_media = 1, 70 [NET_IPV4_CONF_SECURE_REDIRECTS - 1] = 1,
71 [NET_IPV4_CONF_SHARED_MEDIA - 1] = 1,
72 },
71}; 73};
72 74
73static struct ipv4_devconf ipv4_devconf_dflt = { 75static struct ipv4_devconf ipv4_devconf_dflt = {
74 .accept_redirects = 1, 76 .data = {
75 .send_redirects = 1, 77 [NET_IPV4_CONF_ACCEPT_REDIRECTS - 1] = 1,
76 .secure_redirects = 1, 78 [NET_IPV4_CONF_SEND_REDIRECTS - 1] = 1,
77 .shared_media = 1, 79 [NET_IPV4_CONF_SECURE_REDIRECTS - 1] = 1,
78 .accept_source_route = 1, 80 [NET_IPV4_CONF_SHARED_MEDIA - 1] = 1,
81 [NET_IPV4_CONF_ACCEPT_SOURCE_ROUTE - 1] = 1,
82 },
79}; 83};
80 84
85#define IPV4_DEVCONF_DFLT(attr) IPV4_DEVCONF(ipv4_devconf_dflt, attr)
86
81static struct nla_policy ifa_ipv4_policy[IFA_MAX+1] __read_mostly = { 87static struct nla_policy ifa_ipv4_policy[IFA_MAX+1] __read_mostly = {
82 [IFA_LOCAL] = { .type = NLA_U32 }, 88 [IFA_LOCAL] = { .type = NLA_U32 },
83 [IFA_ADDRESS] = { .type = NLA_U32 }, 89 [IFA_ADDRESS] = { .type = NLA_U32 },
@@ -1061,8 +1067,8 @@ static int inetdev_event(struct notifier_block *this, unsigned long event,
1061 if (!in_dev) 1067 if (!in_dev)
1062 panic("devinet: " 1068 panic("devinet: "
1063 "Failed to create loopback\n"); 1069 "Failed to create loopback\n");
1064 in_dev->cnf.no_xfrm = 1; 1070 IN_DEV_CONF_SET(in_dev, NOXFRM, 1);
1065 in_dev->cnf.no_policy = 1; 1071 IN_DEV_CONF_SET(in_dev, NOPOLICY, 1);
1066 } 1072 }
1067 } 1073 }
1068 goto out; 1074 goto out;
@@ -1241,10 +1247,10 @@ errout:
1241void inet_forward_change(void) 1247void inet_forward_change(void)
1242{ 1248{
1243 struct net_device *dev; 1249 struct net_device *dev;
1244 int on = ipv4_devconf.forwarding; 1250 int on = IPV4_DEVCONF_ALL(FORWARDING);
1245 1251
1246 ipv4_devconf.accept_redirects = !on; 1252 IPV4_DEVCONF_ALL(ACCEPT_REDIRECTS) = !on;
1247 ipv4_devconf_dflt.forwarding = on; 1253 IPV4_DEVCONF_DFLT(FORWARDING) = on;
1248 1254
1249 read_lock(&dev_base_lock); 1255 read_lock(&dev_base_lock);
1250 for_each_netdev(dev) { 1256 for_each_netdev(dev) {
@@ -1252,7 +1258,7 @@ void inet_forward_change(void)
1252 rcu_read_lock(); 1258 rcu_read_lock();
1253 in_dev = __in_dev_get_rcu(dev); 1259 in_dev = __in_dev_get_rcu(dev);
1254 if (in_dev) 1260 if (in_dev)
1255 in_dev->cnf.forwarding = on; 1261 IN_DEV_CONF_SET(in_dev, FORWARDING, on);
1256 rcu_read_unlock(); 1262 rcu_read_unlock();
1257 } 1263 }
1258 read_unlock(&dev_base_lock); 1264 read_unlock(&dev_base_lock);
@@ -1269,9 +1275,9 @@ static int devinet_sysctl_forward(ctl_table *ctl, int write,
1269 int ret = proc_dointvec(ctl, write, filp, buffer, lenp, ppos); 1275 int ret = proc_dointvec(ctl, write, filp, buffer, lenp, ppos);
1270 1276
1271 if (write && *valp != val) { 1277 if (write && *valp != val) {
1272 if (valp == &ipv4_devconf.forwarding) 1278 if (valp == &IPV4_DEVCONF_ALL(FORWARDING))
1273 inet_forward_change(); 1279 inet_forward_change();
1274 else if (valp != &ipv4_devconf_dflt.forwarding) 1280 else if (valp != &IPV4_DEVCONF_DFLT(FORWARDING))
1275 rt_cache_flush(0); 1281 rt_cache_flush(0);
1276 } 1282 }
1277 1283
@@ -1333,6 +1339,31 @@ int ipv4_doint_and_flush_strategy(ctl_table *table, int __user *name, int nlen,
1333} 1339}
1334 1340
1335 1341
1342#define DEVINET_SYSCTL_ENTRY(attr, name, mval, proc, sysctl) \
1343 { \
1344 .ctl_name = NET_IPV4_CONF_ ## attr, \
1345 .procname = name, \
1346 .data = ipv4_devconf.data + \
1347 NET_IPV4_CONF_ ## attr - 1, \
1348 .maxlen = sizeof(int), \
1349 .mode = mval, \
1350 .proc_handler = proc, \
1351 .strategy = sysctl, \
1352 }
1353
1354#define DEVINET_SYSCTL_RW_ENTRY(attr, name) \
1355 DEVINET_SYSCTL_ENTRY(attr, name, 0644, &proc_dointvec, NULL)
1356
1357#define DEVINET_SYSCTL_RO_ENTRY(attr, name) \
1358 DEVINET_SYSCTL_ENTRY(attr, name, 0444, &proc_dointvec, NULL)
1359
1360#define DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, proc, sysctl) \
1361 DEVINET_SYSCTL_ENTRY(attr, name, 0644, proc, sysctl)
1362
1363#define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
1364 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush, \
1365 ipv4_doint_and_flush_strategy)
1366
1336static struct devinet_sysctl_table { 1367static struct devinet_sysctl_table {
1337 struct ctl_table_header *sysctl_header; 1368 struct ctl_table_header *sysctl_header;
1338 ctl_table devinet_vars[__NET_IPV4_CONF_MAX]; 1369 ctl_table devinet_vars[__NET_IPV4_CONF_MAX];
@@ -1342,178 +1373,33 @@ static struct devinet_sysctl_table {
1342 ctl_table devinet_root_dir[2]; 1373 ctl_table devinet_root_dir[2];
1343} devinet_sysctl = { 1374} devinet_sysctl = {
1344 .devinet_vars = { 1375 .devinet_vars = {
1345 { 1376 DEVINET_SYSCTL_COMPLEX_ENTRY(FORWARDING, "forwarding",
1346 .ctl_name = NET_IPV4_CONF_FORWARDING, 1377 devinet_sysctl_forward, NULL),
1347 .procname = "forwarding", 1378 DEVINET_SYSCTL_RO_ENTRY(MC_FORWARDING, "mc_forwarding"),
1348 .data = &ipv4_devconf.forwarding, 1379
1349 .maxlen = sizeof(int), 1380 DEVINET_SYSCTL_RW_ENTRY(ACCEPT_REDIRECTS, "accept_redirects"),
1350 .mode = 0644, 1381 DEVINET_SYSCTL_RW_ENTRY(SECURE_REDIRECTS, "secure_redirects"),
1351 .proc_handler = &devinet_sysctl_forward, 1382 DEVINET_SYSCTL_RW_ENTRY(SHARED_MEDIA, "shared_media"),
1352 }, 1383 DEVINET_SYSCTL_RW_ENTRY(RP_FILTER, "rp_filter"),
1353 { 1384 DEVINET_SYSCTL_RW_ENTRY(SEND_REDIRECTS, "send_redirects"),
1354 .ctl_name = NET_IPV4_CONF_MC_FORWARDING, 1385 DEVINET_SYSCTL_RW_ENTRY(ACCEPT_SOURCE_ROUTE,
1355 .procname = "mc_forwarding", 1386 "accept_source_route"),
1356 .data = &ipv4_devconf.mc_forwarding, 1387 DEVINET_SYSCTL_RW_ENTRY(PROXY_ARP, "proxy_arp"),
1357 .maxlen = sizeof(int), 1388 DEVINET_SYSCTL_RW_ENTRY(MEDIUM_ID, "medium_id"),
1358 .mode = 0444, 1389 DEVINET_SYSCTL_RW_ENTRY(BOOTP_RELAY, "bootp_relay"),
1359 .proc_handler = &proc_dointvec, 1390 DEVINET_SYSCTL_RW_ENTRY(LOG_MARTIANS, "log_martians"),
1360 }, 1391 DEVINET_SYSCTL_RW_ENTRY(TAG, "tag"),
1361 { 1392 DEVINET_SYSCTL_RW_ENTRY(ARPFILTER, "arp_filter"),
1362 .ctl_name = NET_IPV4_CONF_ACCEPT_REDIRECTS, 1393 DEVINET_SYSCTL_RW_ENTRY(ARP_ANNOUNCE, "arp_announce"),
1363 .procname = "accept_redirects", 1394 DEVINET_SYSCTL_RW_ENTRY(ARP_IGNORE, "arp_ignore"),
1364 .data = &ipv4_devconf.accept_redirects, 1395 DEVINET_SYSCTL_RW_ENTRY(ARP_ACCEPT, "arp_accept"),
1365 .maxlen = sizeof(int), 1396
1366 .mode = 0644, 1397 DEVINET_SYSCTL_FLUSHING_ENTRY(NOXFRM, "disable_xfrm"),
1367 .proc_handler = &proc_dointvec, 1398 DEVINET_SYSCTL_FLUSHING_ENTRY(NOPOLICY, "disable_policy"),
1368 }, 1399 DEVINET_SYSCTL_FLUSHING_ENTRY(FORCE_IGMP_VERSION,
1369 { 1400 "force_igmp_version"),
1370 .ctl_name = NET_IPV4_CONF_SECURE_REDIRECTS, 1401 DEVINET_SYSCTL_FLUSHING_ENTRY(PROMOTE_SECONDARIES,
1371 .procname = "secure_redirects", 1402 "promote_secondaries"),
1372 .data = &ipv4_devconf.secure_redirects,
1373 .maxlen = sizeof(int),
1374 .mode = 0644,
1375 .proc_handler = &proc_dointvec,
1376 },
1377 {
1378 .ctl_name = NET_IPV4_CONF_SHARED_MEDIA,
1379 .procname = "shared_media",
1380 .data = &ipv4_devconf.shared_media,
1381 .maxlen = sizeof(int),
1382 .mode = 0644,
1383 .proc_handler = &proc_dointvec,
1384 },
1385 {
1386 .ctl_name = NET_IPV4_CONF_RP_FILTER,
1387 .procname = "rp_filter",
1388 .data = &ipv4_devconf.rp_filter,
1389 .maxlen = sizeof(int),
1390 .mode = 0644,
1391 .proc_handler = &proc_dointvec,
1392 },
1393 {
1394 .ctl_name = NET_IPV4_CONF_SEND_REDIRECTS,
1395 .procname = "send_redirects",
1396 .data = &ipv4_devconf.send_redirects,
1397 .maxlen = sizeof(int),
1398 .mode = 0644,
1399 .proc_handler = &proc_dointvec,
1400 },
1401 {
1402 .ctl_name = NET_IPV4_CONF_ACCEPT_SOURCE_ROUTE,
1403 .procname = "accept_source_route",
1404 .data = &ipv4_devconf.accept_source_route,
1405 .maxlen = sizeof(int),
1406 .mode = 0644,
1407 .proc_handler = &proc_dointvec,
1408 },
1409 {
1410 .ctl_name = NET_IPV4_CONF_PROXY_ARP,
1411 .procname = "proxy_arp",
1412 .data = &ipv4_devconf.proxy_arp,
1413 .maxlen = sizeof(int),
1414 .mode = 0644,
1415 .proc_handler = &proc_dointvec,
1416 },
1417 {
1418 .ctl_name = NET_IPV4_CONF_MEDIUM_ID,
1419 .procname = "medium_id",
1420 .data = &ipv4_devconf.medium_id,
1421 .maxlen = sizeof(int),
1422 .mode = 0644,
1423 .proc_handler = &proc_dointvec,
1424 },
1425 {
1426 .ctl_name = NET_IPV4_CONF_BOOTP_RELAY,
1427 .procname = "bootp_relay",
1428 .data = &ipv4_devconf.bootp_relay,
1429 .maxlen = sizeof(int),
1430 .mode = 0644,
1431 .proc_handler = &proc_dointvec,
1432 },
1433 {
1434 .ctl_name = NET_IPV4_CONF_LOG_MARTIANS,
1435 .procname = "log_martians",
1436 .data = &ipv4_devconf.log_martians,
1437 .maxlen = sizeof(int),
1438 .mode = 0644,
1439 .proc_handler = &proc_dointvec,
1440 },
1441 {
1442 .ctl_name = NET_IPV4_CONF_TAG,
1443 .procname = "tag",
1444 .data = &ipv4_devconf.tag,
1445 .maxlen = sizeof(int),
1446 .mode = 0644,
1447 .proc_handler = &proc_dointvec,
1448 },
1449 {
1450 .ctl_name = NET_IPV4_CONF_ARPFILTER,
1451 .procname = "arp_filter",
1452 .data = &ipv4_devconf.arp_filter,
1453 .maxlen = sizeof(int),
1454 .mode = 0644,
1455 .proc_handler = &proc_dointvec,
1456 },
1457 {
1458 .ctl_name = NET_IPV4_CONF_ARP_ANNOUNCE,
1459 .procname = "arp_announce",
1460 .data = &ipv4_devconf.arp_announce,
1461 .maxlen = sizeof(int),
1462 .mode = 0644,
1463 .proc_handler = &proc_dointvec,
1464 },
1465 {
1466 .ctl_name = NET_IPV4_CONF_ARP_IGNORE,
1467 .procname = "arp_ignore",
1468 .data = &ipv4_devconf.arp_ignore,
1469 .maxlen = sizeof(int),
1470 .mode = 0644,
1471 .proc_handler = &proc_dointvec,
1472 },
1473 {
1474 .ctl_name = NET_IPV4_CONF_ARP_ACCEPT,
1475 .procname = "arp_accept",
1476 .data = &ipv4_devconf.arp_accept,
1477 .maxlen = sizeof(int),
1478 .mode = 0644,
1479 .proc_handler = &proc_dointvec,
1480 },
1481 {
1482 .ctl_name = NET_IPV4_CONF_NOXFRM,
1483 .procname = "disable_xfrm",
1484 .data = &ipv4_devconf.no_xfrm,
1485 .maxlen = sizeof(int),
1486 .mode = 0644,
1487 .proc_handler = &ipv4_doint_and_flush,
1488 .strategy = &ipv4_doint_and_flush_strategy,
1489 },
1490 {
1491 .ctl_name = NET_IPV4_CONF_NOPOLICY,
1492 .procname = "disable_policy",
1493 .data = &ipv4_devconf.no_policy,
1494 .maxlen = sizeof(int),
1495 .mode = 0644,
1496 .proc_handler = &ipv4_doint_and_flush,
1497 .strategy = &ipv4_doint_and_flush_strategy,
1498 },
1499 {
1500 .ctl_name = NET_IPV4_CONF_FORCE_IGMP_VERSION,
1501 .procname = "force_igmp_version",
1502 .data = &ipv4_devconf.force_igmp_version,
1503 .maxlen = sizeof(int),
1504 .mode = 0644,
1505 .proc_handler = &ipv4_doint_and_flush,
1506 .strategy = &ipv4_doint_and_flush_strategy,
1507 },
1508 {
1509 .ctl_name = NET_IPV4_CONF_PROMOTE_SECONDARIES,
1510 .procname = "promote_secondaries",
1511 .data = &ipv4_devconf.promote_secondaries,
1512 .maxlen = sizeof(int),
1513 .mode = 0644,
1514 .proc_handler = &ipv4_doint_and_flush,
1515 .strategy = &ipv4_doint_and_flush_strategy,
1516 },
1517 }, 1403 },
1518 .devinet_dev = { 1404 .devinet_dev = {
1519 { 1405 {