HALF ECHO LEARN / REFERENCE COLLECTION

v262.2

src/network/networkd-network.c

46,639 bytesGit mode 100644Download original fileLGPL-2.1-or-later

Git blob: 61a247ee9fb4f32a4ef3c4738d99aeaee6a4252c

Lines 1001–1200 of 1,200

                        log_syntax(unit, LOG_DEBUG, filename, line, r,
                                   "NetDev '%s' specified twice, ignoring.", name);
                else
                        TAKE_PTR(name);
        }
}
 
int config_parse_required_for_online(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
 
        Network *network = ASSERT_PTR(userdata);
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                network->required_for_online = -1;
                network->required_operstate_for_online = LINK_OPERSTATE_RANGE_INVALID;
                return 0;
        }
 
        r = parse_operational_state_range(rvalue, &network->required_operstate_for_online);
        if (r < 0) {
                r = parse_boolean(rvalue);
                if (r < 0) {
                        log_syntax(unit, LOG_WARNING, filename, line, r,
                                   "Failed to parse %s= setting, ignoring assignment: %s",
                                   lvalue, rvalue);
                        return 0;
                }
 
                network->required_for_online = r;
                network->required_operstate_for_online = LINK_OPERSTATE_RANGE_DEFAULT;
                return 0;
        }
 
        network->required_for_online = true;
        return 0;
}
 
int config_parse_link_group(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
 
        Network *network = ASSERT_PTR(userdata);
        int r;
        int32_t group;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                network->group = -1;
                return 0;
        }
 
        r = safe_atoi32(rvalue, &group);
        if (r < 0) {
                log_syntax(unit, LOG_WARNING, filename, line, r,
                           "Failed to parse Group=, ignoring assignment: %s", rvalue);
                return 0;
        }
 
        if (group < 0) {
                log_syntax(unit, LOG_WARNING, filename, line, r,
                           "Value of Group= must be in the range 0…2147483647, ignoring assignment: %s", rvalue);
                return 0;
        }
 
        network->group = group;
        return 0;
}
 
int config_parse_ignore_carrier_loss(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
 
        Network *network = ASSERT_PTR(userdata);
        usec_t usec;
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                network->ignore_carrier_loss_set = false;
                return 0;
        }
 
        r = parse_boolean(rvalue);
        if (r >= 0) {
                network->ignore_carrier_loss_set = true;
                network->ignore_carrier_loss_usec = r > 0 ? USEC_INFINITY : 0;
                return 0;
        }
 
        r = parse_sec(rvalue, &usec);
        if (r < 0) {
                log_syntax(unit, LOG_WARNING, filename, line, r,
                           "Failed to parse %s=, ignoring assignment: %s", lvalue, rvalue);
                return 0;
        }
 
        network->ignore_carrier_loss_set = true;
        network->ignore_carrier_loss_usec = usec;
        return 0;
}
 
int config_parse_keep_configuration(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
 
        KeepConfiguration t, *k = ASSERT_PTR(data);
        Network *network = ASSERT_PTR(userdata);
 
        if (isempty(rvalue)) {
                *k = ASSERT_PTR(network->manager)->keep_configuration;
                return 0;
        }
 
        /* backward compatibility */
        if (streq(rvalue, "dhcp")) {
                *k = KEEP_CONFIGURATION_DYNAMIC;
                return 0;
        }
 
        if (streq(rvalue, "dhcp-on-stop")) {
                *k = KEEP_CONFIGURATION_DYNAMIC_ON_STOP;
                return 0;
        }
 
        t = keep_configuration_from_string(rvalue);
        if (t < 0)
                return log_syntax_parse_error(unit, filename, line, t, lvalue, rvalue);
 
        *k = t;
        return 0;
}
 
DEFINE_CONFIG_PARSE_ENUM(config_parse_required_family_for_online, link_required_address_family, AddressFamily);
 
static const char* const keep_configuration_table[_KEEP_CONFIGURATION_MAX] = {
        [KEEP_CONFIGURATION_NO]              = "no",
        [KEEP_CONFIGURATION_DYNAMIC_ON_STOP] = "dynamic-on-stop",
        [KEEP_CONFIGURATION_DYNAMIC]         = "dynamic",
        [KEEP_CONFIGURATION_STATIC]          = "static",
        [KEEP_CONFIGURATION_YES]             = "yes",
};
 
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(keep_configuration, KeepConfiguration, KEEP_CONFIGURATION_YES);
 
static const char* const activation_policy_table[_ACTIVATION_POLICY_MAX] = {
        [ACTIVATION_POLICY_UP]          = "up",
        [ACTIVATION_POLICY_ALWAYS_UP]   = "always-up",
        [ACTIVATION_POLICY_MANUAL]      = "manual",
        [ACTIVATION_POLICY_ALWAYS_DOWN] = "always-down",
        [ACTIVATION_POLICY_DOWN]        = "down",
        [ACTIVATION_POLICY_BOUND]       = "bound",
};
 
DEFINE_STRING_TABLE_LOOKUP(activation_policy, ActivationPolicy);
DEFINE_CONFIG_PARSE_ENUM(config_parse_activation_policy, activation_policy, ActivationPolicy);