

def _client_network_relay(self, namespace):
    try:
        with self.ns_lock, netns.Namespace(namespace):
            (recv_sock, send_sock, int_addr) = self._open_dhcp_int_socket()
    except Exception:
        self.int_sock_retries += 1
        if (self.int_sock_retries >= 2):
            LOG.exception(_LE('Failed to open dhcp server socket in %s'), namespace)
            self.int_sock_retries = 0
        del self.ns_states[namespace]
        return
    self.int_sock_retries = 0
    self.ns_states[namespace] = NS_RELAY_RUNNING
    vpnid = self._convert_ns_to_vpnid(namespace)
    self.debug_stats.add_network_stats(vpnid)
    self.int_sockets_by_vpn[vpnid] = send_sock
    recvbuf = bytearray(RECV_BUFFER_SIZE)
    LOG.debug('Opened dhcp server socket on ns:%s, addr:%s, vpn:%s', namespace, int_addr, vpnid)
    while (self.ns_states[namespace] != NS_RELAY_DELETING):
        try:
            recv_sock.recv_into(recvbuf)
            pkt = DhcpPacket.parse(recvbuf)
            options = [(5, int_addr), (11, int_addr), (151, vpnid), (152, '')]
            for option in options:
                pkt.set_relay_option(*option)
            pkt.set_giaddr(self.ext_addr)
            self.debug_stats.increment_pkts_from_client(vpnid)
            LOG.debug('Forwarding DHCP request for vpn %s', vpnid)
            self.ext_sock.send(pkt.data())
            self.debug_stats.increment_pkts_to_server(vpnid)
        except Exception:
            LOG.exception(_LE('Failed to forward dhcp to server from %s'), namespace)
    try:
        del self.ns_states[namespace]
        del self.int_sockets_by_vpn[vpnid]
        self.debug_stats.del_network_stats(vpnid)
        recv_sock.close()
        send_sock.close()
    except Exception:
        LOG.warning(_LW('Failed to cleanup relay for %s'), namespace)

dataset/ETHPy150Open openstack/networking-cisco/networking_cisco/plugins/cisco/cpnr/dhcp_relay.py DhcpRelayAgent._client_network_relay/original