if __name__ == "__main__": parser = argparse.ArgumentParser(usage=""" %(prog)s -h %(prog)s [-c <config-file>]""") parser.add_argument('-c', dest='config_file', default="/etc/respondd/bat0.json", metavar='<config-file>', help='config file in JSON format (default: /etc/respondd/bat0.json)') args = parser.parse_args() with open(args.config_file, 'r') as f: config = json.load(f) socketserver.ThreadingUDPServer.address_family = socket.AF_INET6 server = socketserver.ThreadingUDPServer( (config['iface'], config['port']), get_handler(get_providers(config['directory']), {'batadv_dev': config['batadv_iface'], 'mesh_ipv4': config['mesh_ipv4']}) ) server.daemon_threads = True if config['mcast_ifaces']: mcast_ifaces = { ifname: group for ifname, group, *_ in [ reversed([ config['group'] ] + ifspec.split('%')) for ifspec in config['mcast_ifaces'] ] } for (inf_id, inf_name) in socket.if_nameindex(): if inf_name in mcast_ifaces: group_bin = socket.inet_pton(socket.AF_INET6, mcast_ifaces[inf_name]) mreq = group_bin + struct.pack('@I', inf_id) server.socket.setsockopt( socket.IPPROTO_IPV6, socket.IPV6_JOIN_GROUP,
help='data provider directory (default: $PWD/providers)') parser.add_argument('-b', dest='batadv_iface', default='bat0', metavar='<iface>', help='batman-adv interface (default: bat0)') parser.add_argument('-m', dest='mesh_ipv4', metavar='<mesh_ipv4>', help='mesh ipv4 address') args = parser.parse_args() socketserver.ThreadingUDPServer.address_family = socket.AF_INET6 server = socketserver.ThreadingUDPServer( ("", args.port), get_handler(get_providers(args.directory), { 'batadv_dev': args.batadv_iface, 'mesh_ipv4': args.mesh_ipv4 })) server.daemon_threads = True if args.mcast_ifaces: mcast_ifaces = { ifname: group for ifname, group, *_ in [ reversed([args.group] + ifspec.split('%')) for ifspec in args.mcast_ifaces ] } for (inf_id, inf_name) in socket.if_nameindex():
batadv_mesh_ipv4_overrides = {} batadv_ifaces = [] for ifspec in args.batadv_ifaces: iface, *mesh_ipv4 = ifspec.split(':') batadv_ifaces.append(iface) if mesh_ipv4: # mesh_ipv4 list is not empty, there is an override address batadv_mesh_ipv4_overrides[iface] = mesh_ipv4[0] domain_code = args.domain_code metasocketserver.MetadataUDPServer.address_family = socket.AF_INET6 metasocketserver.MetadataUDPServer.allow_reuse_address = True server = metasocketserver.MetadataUDPServer( ("", args.port), get_handler(get_providers(args.directory), batadv_ifaces, batadv_mesh_ipv4_overrides, {'mesh_ipv4': args.mesh_ipv4})) server.daemon_threads = True def join_group(mcast_group, if_index=0): group_bin = socket.inet_pton(socket.AF_INET6, mcast_group) mreq = group_bin + struct.pack('@I', if_index) server.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_JOIN_GROUP, mreq) # Extract multicast interfaces from commandline parameters mcast_iface_groups = {} for ifspec in args.mcast_ifaces: iface, *groups = reversed(ifspec.split('%')) # Populate with default link and site mcast groups if entry not yet created if not iface in mcast_iface_groups:
help='data provider directory (default: $PWD/providers)') args = parser.parse_args() config = Config.from_file(args.config) for domname in config.get_domain_names(): domcfg = config.get_domain_config(domname) domain = domcfg.domain_type(domcfg) DomainRegistry.get_instance().add_domain(domain) if domname == config.get_default_domain(): DomainRegistry.get_instance().set_default_domain(domain) metasocketserver.MetadataUDPServer.address_family = socket.AF_INET6 metasocketserver.MetadataUDPServer.allow_reuse_address = True server = metasocketserver.MetadataUDPServer( ("", config.get_port()), get_handler(get_providers(args.directory))) server.daemon_threads = True def join_group(mcast_group, if_index=0): group_bin = socket.inet_pton(socket.AF_INET6, mcast_group) mreq = group_bin + struct.pack('@I', if_index) server.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_JOIN_GROUP, mreq) for (if_index, if_name) in socket.if_nameindex(): # Check if daemon should listen on interface if if_name in DomainRegistry.get_instance().get_interfaces(): dom = DomainRegistry.get_instance().get_domain_by_interface( if_name) # Join all multicast groups specified for this interface join_group(dom.get_multicast_address_link(), if_index)
if '' != possible_override: batadv_mesh_ipv4_overrides[iface] = possible_override # if left_over list is not empty, there is a domain_code known_codes[iface] = left_over.pop(0) except IndexError: continue global_handler_env = { 'domain_code': config['domain_code'], 'known_codes': known_codes, 'mesh_ipv4': config['mesh_ipv4'] } metasocketserver.MetadataUDPServer.address_family = socket.AF_INET6 metasocketserver.MetadataUDPServer.allow_reuse_address = True oProviders = get_providers(config['directory']) server = metasocketserver.MetadataUDPServer( ("", config['port']), get_handler(oProviders, batadv_ifaces, batadv_mesh_ipv4_overrides, global_handler_env)) print("respondd server created.\nProviders") for p in oProviders: print('\t', oProviders[p].name) server.daemon_threads = True def join_group(mcast_group, if_index=0): group_bin = socket.inet_pton(socket.AF_INET6, mcast_group) mreq = group_bin + struct.pack('@I', if_index) server.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_JOIN_GROUP, mreq)
help='interface on which the group is joined') parser.add_argument('-d', dest='directory', default='./providers', metavar='<dir>', help='data provider directory (default: $PWD/providers)') parser.add_argument('-b', dest='batadv_iface', default='bat0', metavar='<iface>', help='batman-adv interface (default: bat0)') parser.add_argument('-m', dest='mesh_ipv4', metavar='<mesh_ipv4>', help='mesh ipv4 address') args = parser.parse_args() socketserver.ThreadingUDPServer.address_family = socket.AF_INET6 server = socketserver.ThreadingUDPServer( ("", args.port), get_handler(get_providers(args.directory), {'batadv_dev': args.batadv_iface, 'mesh_ipv4': args.mesh_ipv4}) ) if args.mcast_ifaces: mcast_ifaces = { ifname: group for ifname, group, *_ in [ reversed([ args.group ] + ifspec.split('%')) for ifspec in args.mcast_ifaces ] } for (inf_id, inf_name) in socket.if_nameindex(): if inf_name in mcast_ifaces: group_bin = socket.inet_pton(socket.AF_INET6, mcast_ifaces[inf_name]) mreq = group_bin + struct.pack('@I', inf_id) server.socket.setsockopt( socket.IPPROTO_IPV6, socket.IPV6_JOIN_GROUP, mreq