It is overly complex, yet does not cover common scenarios very well.
It will be replaced with a simpler shell script that provides a better
default policy
Signed-off-by: Felix Fietkau <nbd@nbd.name>
iprule_update_complete();
}
-static int
-config_parse_global_ps_val(struct uci_section *globals, const char *option)
-{
- const char *val = uci_lookup_option_string(
- uci_ctx, globals, option);
- int ret = 0;
-
- if (val)
- ret = strtol(val, 0, 10);
-
- return ret;
-}
static void
config_init_globals(void)
const char *ula_prefix = uci_lookup_option_string(
uci_ctx, globals, "ula_prefix");
interface_ip_set_ula_prefix(ula_prefix);
-
- const char *default_ps = uci_lookup_option_string(
- uci_ctx, globals, "default_ps");
-
- if (default_ps)
- device_set_default_ps(strcmp(default_ps, "1") ? false : true,
- config_parse_global_ps_val(globals, "default_xps_val"),
- config_parse_global_ps_val(globals, "default_rps_val"),
- config_parse_global_ps_val(globals, "default_rps_flow_cnt"));
}
static void
static struct list_head devtypes = LIST_HEAD_INIT(devtypes);
static struct avl_tree devices;
-static bool default_ps = true;
-static int default_rps_val;
-static int default_rps_flow_cnt;
-static int default_xps_val;
static const struct blobmsg_policy dev_attrs[__DEV_ATTR_MAX] = {
[DEV_ATTR_TYPE] = { .name = "type", .type = BLOBMSG_TYPE_STRING },
[DEV_ATTR_MLDVERSION] = { .name = "mldversion", .type = BLOBMSG_TYPE_INT32 },
[DEV_ATTR_NEIGHREACHABLETIME] = { .name = "neighreachabletime", .type = BLOBMSG_TYPE_INT32 },
[DEV_ATTR_NEIGHGCSTALETIME] = { .name = "neighgcstaletime", .type = BLOBMSG_TYPE_INT32 },
- [DEV_ATTR_RPS] = { .name = "rps", .type = BLOBMSG_TYPE_BOOL },
- [DEV_ATTR_XPS] = { .name = "xps", .type = BLOBMSG_TYPE_BOOL },
[DEV_ATTR_DADTRANSMITS] = { .name = "dadtransmits", .type = BLOBMSG_TYPE_INT32 },
[DEV_ATTR_MULTICAST_TO_UNICAST] = { .name = "multicast_to_unicast", .type = BLOBMSG_TYPE_BOOL },
[DEV_ATTR_MULTICAST_ROUTER] = { .name = "multicast_router", .type = BLOBMSG_TYPE_INT32 },
s->flags |= DEV_OPT_NEIGHLOCKTIME;
}
- if ((cur = tb[DEV_ATTR_RPS])) {
- s->rps = blobmsg_get_bool(cur);
- s->flags |= DEV_OPT_RPS;
- }
- else
- s->rps = default_ps;
-
- if ((cur = tb[DEV_ATTR_XPS])) {
- s->xps = blobmsg_get_bool(cur);
- s->flags |= DEV_OPT_XPS;
- }
- else
- s->xps = default_ps;
-
if ((cur = tb[DEV_ATTR_DADTRANSMITS])) {
s->dadtransmits = blobmsg_get_u32(cur);
s->flags |= DEV_OPT_DADTRANSMITS;
system_if_clear_state(dev);
device_check_state(dev);
- dev->settings.rps = default_ps;
- dev->settings.xps = default_ps;
return 0;
}
}
}
-void
-device_set_default_ps(bool state, int xps, int rps, int rps_flow_cnt)
-{
- struct device *dev;
-
- if ((state == default_ps) && (default_rps_val == rps) &&
- (default_xps_val == xps) && (default_rps_flow_cnt == rps_flow_cnt))
- return;
-
- default_ps = state;
- default_rps_val = rps;
- default_rps_flow_cnt = rps_flow_cnt;
- default_xps_val = xps;
-
- avl_for_each_element(&devices, dev, avl) {
- struct device_settings *s = &dev->settings;
- unsigned int apply_mask = 0;
-
- if (!(s->flags & DEV_OPT_RPS)) {
- s->rps = default_ps;
- s->rps_val = default_rps_val;
- s->rps_flow_cnt = default_rps_flow_cnt;
- apply_mask |= DEV_OPT_RPS;
- }
-
- if (!(s->flags & DEV_OPT_XPS)) {
- s->xps = default_ps;
- s->xps_val = default_xps_val;
- apply_mask |= DEV_OPT_XPS;
- }
-
- if (!apply_mask)
- continue;
-
- if (!(dev->external || (dev->present && dev->active)) ||
- dev->config_pending)
- continue;
-
- system_if_apply_settings(dev, s, apply_mask);
- }
-}
-
struct device *
device_create(const char *name, struct device_type *type,
struct blob_attr *config)
DEV_ATTR_IGMPVERSION,
DEV_ATTR_MLDVERSION,
DEV_ATTR_NEIGHREACHABLETIME,
- DEV_ATTR_RPS,
- DEV_ATTR_XPS,
DEV_ATTR_DADTRANSMITS,
DEV_ATTR_MULTICAST_TO_UNICAST,
DEV_ATTR_MULTICAST_ROUTER,
DEV_OPT_IGMPVERSION = (1 << 7),
DEV_OPT_MLDVERSION = (1 << 8),
DEV_OPT_NEIGHREACHABLETIME = (1 << 9),
- DEV_OPT_RPS = (1 << 10),
- DEV_OPT_XPS = (1 << 11),
+ /* 2 bit hole */
DEV_OPT_MTU6 = (1 << 12),
DEV_OPT_DADTRANSMITS = (1 << 13),
DEV_OPT_MULTICAST_TO_UNICAST = (1 << 14),
unsigned int neigh4gcstaletime;
unsigned int neigh6gcstaletime;
int neigh4locktime;
- bool rps;
- int rps_val;
- int rps_flow_cnt;
- bool xps;
- int xps_val;
unsigned int dadtransmits;
bool multicast_to_unicast;
unsigned int multicast_router;
void device_reset_config(void);
void device_reset_old(void);
-void device_set_default_ps(bool state, int xps, int rps, int rps_flow_cnt);
void device_init_virtual(struct device *dev, struct device_type *type, const char *name);
int device_init(struct device *dev, struct device_type *type, const char *ifname);
}
}
-static void
-system_if_set_rps_xps_val(const char *path, char *fmt, int val)
-{
- char val_buf[8];
- glob_t gl;
- int i;
-
- if (glob(path, 0, NULL, &gl))
- return;
-
- snprintf(val_buf, sizeof(val_buf), fmt, val);
- for (i = 0; i < gl.gl_pathc; i++)
- system_set_sysctl(gl.gl_pathv[i], val_buf);
-
- globfree(&gl);
-}
-
-static void
-system_if_apply_rps_xps(struct device *dev, struct device_settings *s)
-{
- long n_cpus = sysconf(_SC_NPROCESSORS_ONLN);
- int val, rps_val, rps_flow_cnt, xps_val;
-
- if (n_cpus < 2)
- return;
-
- val = (1 << n_cpus) - 1;
- rps_val = s->rps_val ? s->rps_val : val;
- snprintf(dev_buf, sizeof(dev_buf), "/sys/class/net/%s/queues/*/rps_cpus", dev->ifname);
- system_if_set_rps_xps_val(dev_buf, "%x", s->rps ? rps_val : 0);
-
- rps_flow_cnt = s->rps_flow_cnt ? s->rps_flow_cnt : 0;
- snprintf(dev_buf, sizeof(dev_buf), "/sys/class/net/%s/queues/*/rps_flow_cnt", dev->ifname);
- system_if_set_rps_xps_val(dev_buf, "%d", s->rps ? rps_flow_cnt : 0);
-
- xps_val = s->xps_val ? s->xps_val : val;
- snprintf(dev_buf, sizeof(dev_buf), "/sys/class/net/%s/queues/*/xps_cpus", dev->ifname);
- system_if_set_rps_xps_val(dev_buf, "%x", s->xps ? xps_val : 0);
-}
-
void
system_if_apply_settings(struct device *dev, struct device_settings *s, unsigned int apply_mask)
{
}
if (s->flags & DEV_OPT_SENDREDIRECTS & apply_mask)
system_set_sendredirects(dev, s->sendredirects ? "1" : "0");
-
- system_if_apply_rps_xps(dev, s);
}
int system_if_up(struct device *dev)