Commit 764f829a authored by Christos Stavrakakis's avatar Christos Stavrakakis

Improve log msgs

parent d7b852fd
......@@ -122,7 +122,6 @@ DHCP_REQRESP = {
def get_indev(payload):
try:
indev_ifindex = payload.get_physindev()
logging.debug("get_physindev %s", indev_ifindex)
if indev_ifindex:
logging.debug("Incomming packet from bridge %s", indev_ifindex)
return indev_ifindex
......@@ -136,23 +135,26 @@ def get_indev(payload):
return indev_ifindex
def get_binding(proxy, ifindex, mac):
try:
if proxy.mac_indexed_clients:
logging.debug("get_binding for mac %s", mac)
logging.debug("Getting binding for mac %s", mac)
b = proxy.clients[mac]
else:
logging.debug("get_binding for ifindex %s", ifindex)
logging.debug("Getting binding for ifindex %s", ifindex)
b = proxy.clients[ifindex]
return b
except KeyError:
logging.debug("No client found for mac/ifindex %s/%s", mac, ifindex)
return None
def parse_binding_file(path):
""" Read a client configuration from a tap file
"""
logging.info("Parsing binding file %s", path)
try:
iffile = open(path, 'r')
except EnvironmentError, e:
......@@ -204,6 +206,7 @@ def parse_binding_file(path):
except:
return None
class ClientFileHandler(pyinotify.ProcessEvent):
def __init__(self, server):
pyinotify.ProcessEvent.__init__(self)
......@@ -396,7 +399,7 @@ class VMNetProxy(object): # pylint: disable=R0902
logging.info("Cleanup finished")
def _setup_nfqueue(self, queue_num, family, callback):
logging.debug("Setting up NFQUEUE for queue %d, AF %s",
logging.info("Setting up NFQUEUE for queue %d, AF %s",
queue_num, family)
q = nfqueue.queue()
q.set_callback(callback)
......@@ -405,12 +408,13 @@ class VMNetProxy(object): # pylint: disable=R0902
# This is mandatory for the queue to operate
q.set_mode(nfqueue.NFQNL_COPY_PACKET)
self.nfq[q.get_fd()] = q
logging.debug("Successfully set up NFQUEUE %d", queue_num)
def sendp(self, data, dev):
""" Send a raw packet using a layer-2 socket
"""
logging.debug("%s", data)
logging.debug("Sending raw packet %s", data)
if isinstance(data, BasePacket):
data = str(data)
......@@ -427,15 +431,16 @@ class VMNetProxy(object): # pylint: disable=R0902
for path in glob.glob(os.path.join(self.data_path, "*")):
self.add_tap(path)
logging.debug("\n\n\n\n\n")
logging.debug("%10s %20s %7s %15s", 'Client', 'MAC', 'TAP', 'IP')
logging.debug("%15s %20s %7s %15s", 'Client', 'MAC', 'TAP', 'IP')
for b in self.clients.values():
logging.debug("%10s %20s %7s %15s", b.hostname, b.mac, b.tap, b.ip)
logging.debug("%15s %20s %7s %15s", b.hostname, b.mac, b.tap, b.ip)
def get_ifindex(self, iface):
""" Get the interface index from sysfs
"""
logging.debug("Getting ifindex for interface %s from sysfs", iface)
path = os.path.abspath(os.path.join(SYSFS_NET, iface, "ifindex"))
if not path.startswith(SYSFS_NET):
return None
......@@ -466,11 +471,11 @@ class VMNetProxy(object): # pylint: disable=R0902
return ifindex
def get_iface_hw_addr(self, iface):
""" Get the interface hardware address from sysfs
"""
logging.debug("Getting mac for iface %s", iface)
path = os.path.abspath(os.path.join(SYSFS_NET, iface, "address"))
if not path.startswith(SYSFS_NET):
return None
......@@ -532,7 +537,6 @@ class VMNetProxy(object): # pylint: disable=R0902
except:
logging.debug("Client on %s disappeared!!!", tap)
def dhcp_response(self, i, payload): # pylint: disable=W0613,R0914
""" Generate a reply to bnetfilter-queue-deva BOOTP/DHCP request
......@@ -546,7 +550,7 @@ class VMNetProxy(object): # pylint: disable=R0902
resp = pkt.getlayer(BOOTP).copy()
hlen = resp.hlen
mac = resp.chaddr[:hlen].encode("hex")
mac, _ = re.subn(r'([0-9a-fA-F]{2})', r'\1:', mac, hlen-1)
mac, _ = re.subn(r'([0-9a-fA-F]{2})', r'\1:', mac, hlen - 1)
# Server responses are always BOOTREPLYs
resp.op = "BOOTREPLY"
......@@ -564,7 +568,6 @@ class VMNetProxy(object): # pylint: disable=R0902
payload.set_verdict(nfqueue.NF_ACCEPT)
return
# Signal the kernel that it shouldn't further process the packet
payload.set_verdict(nfqueue.NF_DROP)
......@@ -629,7 +632,7 @@ class VMNetProxy(object): # pylint: disable=R0902
elif req_type == DHCPRELEASE:
# Log and ignore
logging.info("DHCPRELEASE from %s on %s", binding.mac, binding.tap )
logging.info("DHCPRELEASE from %s on %s", binding.mac, binding.tap)
return
# Finally, always add the server identifier and end options
......@@ -654,8 +657,8 @@ class VMNetProxy(object): # pylint: disable=R0902
""" Generate a reply to a BOOTP/DHCP request
"""
pkt = IPv6(payload.get_data())
logging.debug("IN RS RESPONCE")
#logging.debug(pkt.show())
try:
mac = pkt.lladdr
......@@ -663,7 +666,7 @@ class VMNetProxy(object): # pylint: disable=R0902
logging.debug("Cannot obtain lladdr in rs")
return
logging.debug("rs for mac %s", mac)
logging.debug("Generating an rs response for mac %s", mac)
indev = get_indev(payload)
......@@ -695,7 +698,6 @@ class VMNetProxy(object): # pylint: disable=R0902
if ifll is None:
return
resp = Ether(src=indevmac)/\
IPv6(src=str(ifll))/ICMPv6ND_RA(routerlifetime=14400)/\
ICMPv6NDOptPrefixInfo(prefix=str(subnet.prefix),
......@@ -718,8 +720,8 @@ class VMNetProxy(object): # pylint: disable=R0902
""" Generate a reply to an ICMPv6 neighbor solicitation
"""
ns = IPv6(payload.get_data())
logging.debug("IN NS RESPONCE")
#logging.debug(ns.show())
try:
mac = ns.lladdr
......@@ -727,7 +729,7 @@ class VMNetProxy(object): # pylint: disable=R0902
logging.debug("Cannot obtain lladdr from ns")
return
logging.debug("dst %s tgt %s" , ns.dst, ns.tgt)
logging.debug("Generating ns response, dst: %s tgt: %s", ns.dst, ns.tgt)
indev = get_indev(payload)
......@@ -790,7 +792,7 @@ class VMNetProxy(object): # pylint: disable=R0902
for binding in self.clients.values():
tap = binding.tap
indev = binding.indev
mac = binding.mac
# mac = binding.mac
subnet = binding.net6
if subnet.net is None:
logging.debug("Skipping periodic RA on interface %s,"
......@@ -847,7 +849,7 @@ class VMNetProxy(object): # pylint: disable=R0902
rlist, _, xlist = select(self.nfq.keys() + [iwfd], [], [], timeout)
if xlist:
logging.warn("Warning: Exception on %s",
", ".join([ str(fd) for fd in xlist]))
", ".join([str(fd) for fd in xlist]))
if rlist:
if iwfd in rlist:
......@@ -910,7 +912,6 @@ if __name__ == "__main__":
validator.functions["ip_addr_list"] = is_ip_list
config_spec = StringIO(CONFIG_SPEC)
parser = optparse.OptionParser()
parser.add_option("-c", "--config", dest="config_file",
help="The location of the data files", metavar="FILE",
......@@ -921,7 +922,6 @@ if __name__ == "__main__":
dest="daemonize", default=True,
help="Do not daemonize, stay in the foreground")
opts, args = parser.parse_args()
try:
......@@ -1017,10 +1017,10 @@ if __name__ == "__main__":
# CAP_NET_ADMIN: we need to send nfqueue packet verdicts to a netlinkgroup
capng.capng_clear(capng.CAPNG_SELECT_BOTH)
capng.capng_update(capng.CAPNG_ADD,
capng.CAPNG_EFFECTIVE|capng.CAPNG_PERMITTED,
capng.CAPNG_EFFECTIVE | capng.CAPNG_PERMITTED,
capng.CAP_NET_ADMIN)
capng.capng_change_id(uid.pw_uid, uid.pw_gid,
capng.CAPNG_DROP_SUPP_GRP|capng.CAPNG_CLEAR_BOUNDING)
capng.CAPNG_DROP_SUPP_GRP | capng.CAPNG_CLEAR_BOUNDING)
logging.info("Ready to serve requests")
try:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment