Exemple #1
0
    def newtuntap(self, ifindex=None, ifname=None, net=None):
        """
        Create a new tunnel tap.

        :param int ifindex: interface index
        :param str ifname: interface name
        :param net: network to associate with
        :return: interface index
        :rtype: int
        """
        with self.lock:
            if ifindex is None:
                ifindex = self.newifindex()

            if ifname is None:
                ifname = "eth%d" % ifindex

            sessionid = self.session.short_session_id()
            localname = "tap%s.%s.%s" % (self.id, ifindex, sessionid)
            name = ifname
            tuntap = TunTap(node=self,
                            name=name,
                            localname=localname,
                            net=net,
                            start=self.up)

            try:
                self.addnetif(tuntap, ifindex)
            except ValueError as e:
                tuntap.shutdown()
                del tuntap
                raise e

            return ifindex
Exemple #2
0
    def newtuntap(self, iface_id: int = None, ifname: str = None) -> int:
        """
        Create a new tunnel tap.

        :param iface_id: interface id
        :param ifname: interface name
        :return: interface index
        """
        with self.lock:
            if iface_id is None:
                iface_id = self.next_iface_id()

            if ifname is None:
                ifname = f"eth{iface_id}"

            sessionid = self.session.short_session_id()
            localname = f"tap{self.id}.{iface_id}.{sessionid}"
            name = ifname
            tuntap = TunTap(self.session, self, name, localname, start=self.up)

            try:
                self.add_iface(tuntap, iface_id)
            except ValueError as e:
                tuntap.shutdown()
                del tuntap
                raise e

            return iface_id
Exemple #3
0
    def newtuntap(self, ifindex=None, ifname=None):
        """
        Create a new tunnel tap.

        :param int ifindex: interface index
        :param str ifname: interface name
        :return: interface index
        :rtype: int
        """
        with self.lock:
            if ifindex is None:
                ifindex = self.newifindex()

            if ifname is None:
                ifname = f"eth{ifindex}"

            sessionid = self.session.short_session_id()
            localname = f"tap{self.id}.{ifindex}.{sessionid}"
            name = ifname
            tuntap = TunTap(self.session, self, name, localname, start=self.up)

            try:
                self.addnetif(tuntap, ifindex)
            except ValueError as e:
                tuntap.shutdown()
                del tuntap
                raise e

            return ifindex
Exemple #4
0
    def newtuntap(self, iface_id: int = None, ifname: str = None) -> int:
        """
        Create a new tunnel tap.

        :param iface_id: interface id
        :param ifname: interface name
        :return: interface index
        """
        with self.lock:
            iface_id = iface_id if iface_id is not None else self.next_iface_id(
            )
            ifname = ifname if ifname is not None else f"eth{iface_id}"
            sessionid = self.session.short_session_id()
            localname = f"tap{self.id}.{iface_id}.{sessionid}"
            name = ifname
            tuntap = TunTap(self.session, name, localname, node=self)
            if self.up:
                tuntap.startup()
            try:
                self.add_iface(tuntap, iface_id)
            except CoreError as e:
                tuntap.shutdown()
                raise e
            return iface_id