Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lazybsd_veth实现 #13

Open
mengdemao opened this issue Feb 19, 2024 · 0 comments
Open

lazybsd_veth实现 #13

mengdemao opened this issue Feb 19, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@mengdemao
Copy link
Owner

lazybsd虚拟网卡实现

lazybsd_veth_attach --> lazybsd_veth_setup_interface

参考f-stack实现

static int
ff_veth_setup_interface(struct ff_veth_softc *sc, struct ff_port_cfg *cfg)
{
    struct ifnet *ifp;

    ifp = sc->ifp = if_alloc(IFT_ETHER);

    ifp->if_init = ff_veth_init;
    ifp->if_softc = sc;

    if_initname(ifp, sc->host_ifname, IF_DUNIT_NONE);
    ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
    ifp->if_ioctl = ff_veth_ioctl;
    ifp->if_start = ff_veth_start;
    ifp->if_transmit = ff_veth_transmit;
    ifp->if_qflush = ff_veth_qflush;
    ether_ifattach(ifp, sc->mac);

    if (cfg->hw_features.rx_csum) {
        ifp->if_capabilities |= IFCAP_RXCSUM;
    }
    if (cfg->hw_features.tx_csum_ip) {
        ifp->if_capabilities |= IFCAP_TXCSUM;
        ifp->if_hwassist |= CSUM_IP;
    }
    if (cfg->hw_features.tx_csum_l4) {
        ifp->if_hwassist |= CSUM_DELAY_DATA;
    }
    if (cfg->hw_features.tx_tso) {
        ifp->if_capabilities |= IFCAP_TSO;
        ifp->if_hwassist |= CSUM_TSO;
    }

    ifp->if_capenable = ifp->if_capabilities;

    sc->host_ctx = ff_dpdk_register_if((void *)sc, (void *)sc->ifp, cfg);
    if (sc->host_ctx == NULL) {
        printf("%s: Failed to register dpdk interface\n", sc->host_ifname);
        return -1;
    }

    // Set IP
    int ret = ff_veth_setaddr(sc);
    if (ret != 0) {
        printf("ff_veth_setaddr failed\n");
    }
    ret = ff_veth_set_gateway(sc);
    if (ret != 0) {
        printf("ff_veth_set_gateway failed\n");
    }

    if (sc->nb_vip) {
        ret = ff_veth_setvaddr(sc, cfg);
    }

#ifdef INET6
    // Set IPv6
    if (cfg->addr6_str) {
        ret = ff_veth_setaddr6(sc);
        if (ret != 0) {
            printf("ff_veth_setaddr6 failed\n");
        }

        if (cfg->gateway6_str) {
            ret = ff_veth_set_gateway6(sc);
            if (ret != 0) {
                printf("ff_veth_set_gateway6 failed\n");
            }
        }
    }

    if (sc->nb_vip6) {
        ret = ff_veth_setvaddr6(sc, cfg);
    }
#endif /* INET6 */

    return (0);
}
@mengdemao mengdemao added the enhancement New feature or request label Feb 19, 2024
@mengdemao mengdemao self-assigned this Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

1 participant