HALF ECHO LEARN / REFERENCE COLLECTION

v262.2

src/network/netdev/tunnel.c

43,876 bytesGit mode 100644Download original fileLGPL-2.1-or-later

Git blob: 08acfb1ceeb87d06aa7f86994f456b6ec124d1f9

Lines 1001–1280 of 1,280

        if (r < 0) {
                log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse 6rd prefix \"%s\", ignoring: %m", rvalue);
                return 0;
        }
        if (l == 0) {
                log_syntax(unit, LOG_WARNING, filename, line, 0, "6rd prefix length of \"%s\" must be greater than zero, ignoring", rvalue);
                return 0;
        }
 
        t->sixrd_prefix = p.in6;
        t->sixrd_prefixlen = l;
 
        return 0;
}
 
int config_parse_erspan_version(
                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) {
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        uint8_t *v = ASSERT_PTR(data);
 
        if (isempty(rvalue)) {
                *v = 1; /* defaults to 1 */
                return 0;
        }
 
        return config_parse_uint8_bounded(
                        unit, filename, line, section, section_line, lvalue, rvalue,
                        0, 2, true,
                        v);
}
 
int config_parse_erspan_index(
                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) {
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        uint32_t *v = ASSERT_PTR(data);
 
        if (isempty(rvalue)) {
                *v = 0; /* defaults to 0 */
                return 0;
        }
 
        return config_parse_uint32_bounded(
                        unit, filename, line, section, section_line, lvalue, rvalue,
                        0, 0x100000 - 1, true,
                        v);
}
 
int config_parse_erspan_direction(
                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) {
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        uint8_t *v = ASSERT_PTR(data);
 
        if (isempty(rvalue) || streq(rvalue, "ingress"))
                *v = 0; /* defaults to ingress */
        else if (streq(rvalue, "egress"))
                *v = 1;
        else
                log_syntax(unit, LOG_WARNING, filename, line, 0,
                           "Invalid erspan direction \"%s\", which must be \"ingress\" or \"egress\", ignoring.", rvalue);
 
        return 0;
}
 
int config_parse_erspan_hwid(
                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) {
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        uint16_t *v = ASSERT_PTR(data);
 
        if (isempty(rvalue)) {
                *v = 0; /* defaults to 0 */
                return 0;
        }
 
        return config_parse_uint16_bounded(
                        unit, filename, line, section, section_line, lvalue, rvalue,
                        0, 63, true,
                        v);
}
 
static void netdev_tunnel_init(NetDev *netdev) {
        Tunnel *t = ASSERT_PTR(TUNNEL(netdev));
 
        t->local_type = _NETDEV_LOCAL_ADDRESS_TYPE_INVALID;
        t->pmtudisc = -1;
        t->fou_encap_type = NETDEV_FOO_OVER_UDP_ENCAP_DIRECT;
        t->isatap = -1;
        t->gre_erspan_sequence = -1;
        t->encap_limit = IPV6_DEFAULT_TNL_ENCAP_LIMIT;
        t->mode = _TUNNEL_MODE_INVALID;
        t->ipv6_flowlabel = _NETDEV_IPV6_FLOWLABEL_INVALID;
        t->allow_localremote = -1;
        t->erspan_version = 1;
 
        if (IN_SET(netdev->kind, NETDEV_KIND_IP6GRE, NETDEV_KIND_IP6GRETAP, NETDEV_KIND_IP6TNL))
                t->ttl = DEFAULT_IPV6_TTL;
}
 
static bool tunnel_can_set_mac(NetDev *netdev, const struct hw_addr_data *hw_addr) {
        assert(IN_SET(netdev->kind, NETDEV_KIND_GRETAP, NETDEV_KIND_IP6GRETAP, NETDEV_KIND_ERSPAN));
        return true;
}
 
const NetDevVTable ipip_vtable = {
        .object_size = sizeof(Tunnel),
        .init = netdev_tunnel_init,
        .sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
        .fill_message_create = netdev_ipip_sit_fill_message_create,
        .create_type = NETDEV_CREATE_STACKED,
        .is_ready_to_create = netdev_tunnel_is_ready_to_create,
        .config_verify = netdev_tunnel_verify,
        .needs_reconfigure = tunnel_needs_reconfigure,
        .iftype = ARPHRD_TUNNEL,
};
 
const NetDevVTable sit_vtable = {
        .object_size = sizeof(Tunnel),
        .init = netdev_tunnel_init,
        .sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
        .fill_message_create = netdev_ipip_sit_fill_message_create,
        .create_type = NETDEV_CREATE_STACKED,
        .is_ready_to_create = netdev_tunnel_is_ready_to_create,
        .config_verify = netdev_tunnel_verify,
        .needs_reconfigure = tunnel_needs_reconfigure,
        .iftype = ARPHRD_SIT,
};
 
const NetDevVTable vti_vtable = {
        .object_size = sizeof(Tunnel),
        .init = netdev_tunnel_init,
        .sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
        .fill_message_create = netdev_vti_fill_message_create,
        .create_type = NETDEV_CREATE_STACKED,
        .is_ready_to_create = netdev_tunnel_is_ready_to_create,
        .config_verify = netdev_tunnel_verify,
        .needs_reconfigure = tunnel_needs_reconfigure,
        .iftype = ARPHRD_TUNNEL,
};
 
const NetDevVTable vti6_vtable = {
        .object_size = sizeof(Tunnel),
        .init = netdev_tunnel_init,
        .sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
        .fill_message_create = netdev_vti_fill_message_create,
        .create_type = NETDEV_CREATE_STACKED,
        .is_ready_to_create = netdev_tunnel_is_ready_to_create,
        .config_verify = netdev_tunnel_verify,
        .needs_reconfigure = tunnel_needs_reconfigure,
        .iftype = ARPHRD_TUNNEL6,
};
 
const NetDevVTable gre_vtable = {
        .object_size = sizeof(Tunnel),
        .init = netdev_tunnel_init,
        .sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
        .fill_message_create = netdev_gre_erspan_fill_message_create,
        .create_type = NETDEV_CREATE_STACKED,
        .is_ready_to_create = netdev_tunnel_is_ready_to_create,
        .config_verify = netdev_tunnel_verify,
        .needs_reconfigure = tunnel_needs_reconfigure,
        .iftype = ARPHRD_IPGRE,
};
 
const NetDevVTable gretap_vtable = {
        .object_size = sizeof(Tunnel),
        .init = netdev_tunnel_init,
        .sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
        .fill_message_create = netdev_gre_erspan_fill_message_create,
        .create_type = NETDEV_CREATE_STACKED,
        .is_ready_to_create = netdev_tunnel_is_ready_to_create,
        .config_verify = netdev_tunnel_verify,
        .needs_reconfigure = tunnel_needs_reconfigure,
        .can_set_mac = tunnel_can_set_mac,
        .iftype = ARPHRD_ETHER,
        .generate_mac = true,
};
 
const NetDevVTable ip6gre_vtable = {
        .object_size = sizeof(Tunnel),
        .init = netdev_tunnel_init,
        .sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
        .fill_message_create = netdev_ip6gre_fill_message_create,
        .create_type = NETDEV_CREATE_STACKED,
        .is_ready_to_create = netdev_tunnel_is_ready_to_create,
        .config_verify = netdev_tunnel_verify,
        .needs_reconfigure = tunnel_needs_reconfigure,
        .iftype = ARPHRD_IP6GRE,
};
 
const NetDevVTable ip6gretap_vtable = {
        .object_size = sizeof(Tunnel),
        .init = netdev_tunnel_init,
        .sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
        .fill_message_create = netdev_ip6gre_fill_message_create,
        .create_type = NETDEV_CREATE_STACKED,
        .is_ready_to_create = netdev_tunnel_is_ready_to_create,
        .config_verify = netdev_tunnel_verify,
        .needs_reconfigure = tunnel_needs_reconfigure,
        .can_set_mac = tunnel_can_set_mac,
        .iftype = ARPHRD_ETHER,
        .generate_mac = true,
};
 
const NetDevVTable ip6tnl_vtable = {
        .object_size = sizeof(Tunnel),
        .init = netdev_tunnel_init,
        .sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
        .fill_message_create = netdev_ip6tnl_fill_message_create,
        .create_type = NETDEV_CREATE_STACKED,
        .is_ready_to_create = netdev_tunnel_is_ready_to_create,
        .config_verify = netdev_tunnel_verify,
        .needs_reconfigure = tunnel_needs_reconfigure,
        .iftype = ARPHRD_TUNNEL6,
};
 
const NetDevVTable erspan_vtable = {
        .object_size = sizeof(Tunnel),
        .init = netdev_tunnel_init,
        .sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
        .fill_message_create = netdev_gre_erspan_fill_message_create,
        .create_type = NETDEV_CREATE_STACKED,
        .is_ready_to_create = netdev_tunnel_is_ready_to_create,
        .config_verify = netdev_tunnel_verify,
        .needs_reconfigure = tunnel_needs_reconfigure,
        .can_set_mac = tunnel_can_set_mac,
        .iftype = ARPHRD_ETHER,
        .generate_mac = true,
};