/* ** Adds the interface '*IfDp' as virtual interface to the mrouted API ** */ void addVIF( struct IfDesc *IfDp ) { struct vifctl VifCtl; struct VifDesc *VifDp; /* search free VifDesc */ for ( VifDp = VifDescVc; VifDp < VCEP( VifDescVc ); VifDp++ ) { if ( ! VifDp->IfDp ) break; } /* no more space */ if ( VifDp >= VCEP( VifDescVc ) ) my_log( LOG_ERR, ENOMEM, "addVIF, out of VIF space" ); VifDp->IfDp = IfDp; VifCtl.vifc_vifi = VifDp - VifDescVc; VifCtl.vifc_flags = 0; /* no tunnel, no source routing, register ? */ VifCtl.vifc_threshold = VifDp->IfDp->threshold; // Packet TTL must be at least 1 to pass them VifCtl.vifc_rate_limit = VifDp->IfDp->ratelimit; // Ratelimit VifCtl.vifc_lcl_addr.s_addr = VifDp->IfDp->InAdr.s_addr; VifCtl.vifc_rmt_addr.s_addr = INADDR_ANY; // Set the index... VifDp->IfDp->index = VifCtl.vifc_vifi; my_log( LOG_NOTICE, 0, "adding VIF, Ix %d Fl 0x%x IP 0x%08x %s, Threshold: %d, Ratelimit: %d", VifCtl.vifc_vifi, VifCtl.vifc_flags, VifCtl.vifc_lcl_addr.s_addr, VifDp->IfDp->Name, VifCtl.vifc_threshold, VifCtl.vifc_rate_limit); struct SubnetList *currSubnet; for(currSubnet = IfDp->allowednets; currSubnet; currSubnet = currSubnet->next) { my_log(LOG_DEBUG, 0, " Network for [%s] : %s", IfDp->Name, inetFmts(currSubnet->subnet_addr, currSubnet->subnet_mask, s1)); } if ( setsockopt( MRouterFD, IPPROTO_IP, MRT_ADD_VIF, (char *)&VifCtl, sizeof( VifCtl ) ) ) my_log( LOG_ERR, errno, "MRT_ADD_VIF" ); }
static void learn(int result) { int pos; board_t board[1]; int move; ASSERT(result>=-1&&result<=+1); ASSERT(XB->result); ASSERT(State->computer[White]||State->computer[Black]); // init pos = 0; if (false) { } else if (State->computer[White]) { pos = 0; } else if (State->computer[Black]) { pos = 1; result = -result; } else { my_fatal("learn(): unknown side\n"); } if (false) { } else if (result > 0) { my_log("POLYGLOT *LEARN WIN*\n"); } else if (result < 0) { my_log("POLYGLOT *LEARN LOSS*\n"); } else { my_log("POLYGLOT *LEARN DRAW*\n"); } // loop for (; pos < Game->size; pos += 2) { game_get_board(Game,board,pos); move = game_move(Game,pos); book_learn_move(board,move,result); } book_flush(); }
/** * Updates the Kernel routing table. If activate is 1, the route * is (re-)activated. If activate is false, the route is removed. */ int internUpdateKernelRoute(struct RouteTable *route, int activate) { struct MRouteDesc mrDesc; struct IfDesc *Dp; unsigned Ix; int i; for (i = 0; i < MAX_ORIGINS; i++) { if (route->originAddrs[i] == 0) { continue; } // Build route descriptor from table entry... // Set the source address and group address... mrDesc.McAdr.s_addr = route->group; mrDesc.OriginAdr.s_addr = route->originAddrs[i]; // clear output interfaces memset( mrDesc.TtlVc, 0, sizeof( mrDesc.TtlVc ) ); my_log(LOG_DEBUG, 0, "Vif bits : 0x%08x", route->vifBits); // Set the TTL's for the route descriptor... for ( Ix = 0; (Dp = getIfByIx(Ix)); Ix++ ) { if(Dp->state == IF_STATE_UPSTREAM) { mrDesc.InVif = Dp->index; } else if(BIT_TST(route->vifBits, Dp->index)) { my_log(LOG_DEBUG, 0, "Setting TTL for Vif %d to %d", Dp->index, Dp->threshold); mrDesc.TtlVc[ Dp->index ] = Dp->threshold; } } // Do the actual Kernel route update... if(activate) { // Add route in kernel... addMRoute( &mrDesc ); } else { // Delete the route from Kernel... delMRoute( &mrDesc ); } } return 1; }
static void DHCPv6SocketDemux(int if_index, const DHCPv6PacketRef pkt, int pkt_len) { DHCPv6SocketReceiveData data; DHCPv6OptionErrorString err; int i; if (pkt_len < DHCPV6_PACKET_HEADER_LENGTH) { return; } data.pkt = pkt; data.pkt_len = pkt_len; data.options = DHCPv6OptionListCreateWithPacket(pkt, pkt_len, &err); if (data.options == NULL) { my_log(LOG_NOTICE, "DHCPv6Socket: options parse failed, %s", err.str); return; } for (i = 0; i < dynarray_count(&S_globals->sockets); i++) { DHCPv6SocketRef client; client = dynarray_element(&S_globals->sockets, i); if (if_index != if_link_index(DHCPv6SocketGetInterface(client))) { continue; } if (S_verbose) { CFMutableStringRef str; str = CFStringCreateMutable(NULL, 0); DHCPv6PacketPrintToString(str, pkt, pkt_len); if (data.options != NULL) { DHCPv6OptionListPrintToString(str, data.options); } my_log(-LOG_DEBUG, "[%s] Receive %@", if_name(DHCPv6SocketGetInterface(client)), str); CFRelease(str); } if (client->receive_func != NULL) { (*client->receive_func)(client->receive_arg1, client->receive_arg2, &data); } } DHCPv6OptionListRelease(&data.options); return; }
/** * clears the associated timer. Returns 1 if succeeded. */ int timer_clearTimer(int timer_id) { struct timeOutQueue *ptr, *prev; int i = 0; if (!timer_id) return 0; prev = ptr = queue; /* * find the right node, delete it. the subsequent node's time * gets bumped up */ debugQueue(); while (ptr) { if (ptr->id == timer_id) { /* got the right node */ /* unlink it from the queue */ if (ptr == queue) queue = queue->next; else prev->next = ptr->next; /* increment next node if any */ if (ptr->next != 0) (ptr->next)->time += ptr->time; if (ptr->data) free(ptr->data); my_log(LOG_DEBUG, 0, "deleted timer %d (#%d)", ptr->id, i); free(ptr); debugQueue(); return 1; } prev = ptr; ptr = ptr->next; i++; } // If we get here, the timer was not deleted. my_log(LOG_DEBUG, 0, "failed to delete timer %d (#%d)", timer_id, i); debugQueue(); return 0; }
/** * Clean up all on exit... */ void igmpProxyCleanUp() { my_log( LOG_DEBUG, 0, "clean handler called" ); free_all_callouts(); // No more timeouts. clearAllRoutes(); // Remove all routes. disableMRouter(); // Disable the multirout API }
Boolean peek_engine_get(engine_t * engine, char *szLineStr, int size){ if (pipeEngine.LineInput(szLineStr)) { my_log("Engine->Adapter: %s\n", szLineStr); return TRUE; } else { szLineStr[0]='\0'; return FALSE; } }
void k_set_if(uint32_t ifa) { struct in_addr adr; adr.s_addr = ifa; if (setsockopt(MRouterFD, IPPROTO_IP, IP_MULTICAST_IF, (char *)&adr, sizeof(adr)) < 0) my_log(LOG_ERR, errno, "setsockopt IP_MULTICAST_IF %s", inetFmt(ifa, s1)); }
/* * Call build_igmp() to build an IGMP message in the output packet buffer. * Then send the message from the interface with IP address 'src' to * destination 'dst'. */ void sendIgmp(uint32_t src, uint32_t dst, int type, int code, uint32_t group, int datalen) { struct sockaddr_in sdst; int setloop = 0, setigmpsource = 0; buildIgmp(src, dst, type, code, group, datalen); if (IN_MULTICAST(ntohl(dst))) { k_set_if(src); setigmpsource = 1; if (type != IGMP_DVMRP || dst == allhosts_group) { setloop = 1; k_set_loop(true); } } memset(&sdst, 0, sizeof(sdst)); sdst.sin_family = AF_INET; #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN sdst.sin_len = sizeof(sdst); #endif sdst.sin_addr.s_addr = dst; if (sendto(MRouterFD, send_buf, IP_HEADER_RAOPT_LEN + IGMP_MINLEN + datalen, 0, (struct sockaddr *)&sdst, sizeof(sdst)) < 0) { if (errno == ENETDOWN) my_log(LOG_ERR, errno, "Sender VIF was down."); else my_log(LOG_INFO, errno, "sendto to %s on %s", inetFmt(dst, s1), inetFmt(src, s2)); } if(setigmpsource) { if (setloop) { k_set_loop(false); } // Restore original... k_set_if(INADDR_ANY); } my_log(LOG_DEBUG, 0, "SENT %s from %-15s to %s", igmpPacketKind(type, code), src == INADDR_ANY ? "INADDR_ANY" : inetFmt(src, s1), inetFmt(dst, s2)); }
static void set_arp_linklocal(const char * name, int val) { int s; s = socket(AF_INET, SOCK_DGRAM, 0); if (s == -1) { my_log(LOG_NOTICE, "set_arp_linklocal(%s) socket() failed, %s", name, strerror(errno)); return; } if (siocarpipll(s, name, val) < 0) { if (errno != ENXIO) { my_log(LOG_NOTICE, "set_arp_linklocal(%s) SIOCARPIPLL %d failed, %s", name, val, strerror(errno)); } } close(s); }
/** * Returns true when the given group belongs to the given interface */ int interfaceInRoute(int32_t group, int Ix) { struct RouteTable* croute; croute = findRoute(group); if (croute != NULL) { my_log(LOG_DEBUG, 0, "Interface id %d is in group $d", Ix, group); return BIT_TST(croute->vifBits, Ix); } else { return 0; } }
static void failover_timed_out(ServiceRef service_p) { my_log(LOG_DEBUG, "FAILOVER %s: address timer fired", if_name(service_interface(service_p))); failover_cancel_pending_events(service_p); service_remove_address(service_p); service_publish_failure(service_p, ipconfig_status_address_timed_out_e); return; }
void list_disp(const list_t * list, const board_t * board) { int i, move, value; char string[256]; ASSERT(list_is_ok(list)); ASSERT(board_is_ok(board)); for (i = 0; i < list->size; i++) { move = list->move[i]; value = list->value[i]; if (!move_to_can(move,board,string,256)) ASSERT(false); my_log("POLYGLOT %-5s %04X %+4d\n",string,move,value); } my_log("POLYGLOT\n"); }
/** * Recieves and handles a group leave message. */ void acceptLeaveMessage(uint32_t src, uint32_t group) { struct IfDesc *sourceVif; my_log(LOG_DEBUG, 0, "Got leave message from %s to %s. Starting last member detection.", inetFmt(src, s1), inetFmt(group, s2)); // Sanitycheck the group adress... if(!IN_MULTICAST( ntohl(group) )) { my_log(LOG_WARNING, 0, "The group address %s is not a valid Multicast group.", inetFmt(group, s1)); return; } // Find the interface on which the report was recieved. sourceVif = getIfByAddress( src ); if(sourceVif == NULL) { my_log(LOG_WARNING, 0, "No interfaces found for source %s", inetFmt(src,s1)); return; } // We have a IF so check that it's an downstream IF. if(sourceVif->state == IF_STATE_DOWNSTREAM) { GroupVifDesc *gvDesc; gvDesc = (GroupVifDesc*) malloc(sizeof(GroupVifDesc)); // Tell the route table that we are checking for remaining members... setRouteLastMemberMode(group); // Call the group spesific membership querier... gvDesc->group = group; gvDesc->vifAddr = sourceVif->InAdr.s_addr; gvDesc->started = 0; sendGroupSpecificMemberQuery(gvDesc); } else { // just ignore the leave request... my_log(LOG_DEBUG, 0, "The found if for %s was not downstream. Ignoring leave request.", inetFmt(src, s1)); } }
static Boolean ptr_query_start(CFStringRef address) { union { struct sockaddr sa; struct sockaddr_in sin; struct sockaddr_in6 sin6; } addr; char buf[64]; CFDataRef data; CFMutableDictionaryRef options; if (_SC_cfstring_to_cstring(address, buf, sizeof(buf), kCFStringEncodingASCII) == NULL) { my_log(LOG_ERR, "could not convert [primary] address string"); return FALSE; } if (_SC_string_to_sockaddr(buf, AF_UNSPEC, (void *)&addr, sizeof(addr)) == NULL) { my_log(LOG_ERR, "could not convert [primary] address"); return FALSE; } options = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); data = CFDataCreate(NULL, (const UInt8 *)&addr.sa, addr.sa.sa_len); CFDictionarySetValue(options, kSCNetworkReachabilityOptionPTRAddress, data); CFRelease(data); ptrTarget = SCNetworkReachabilityCreateWithOptions(NULL, options); CFRelease(options); if (ptrTarget == NULL) { my_log(LOG_ERR, "could not resolve [primary] address"); return FALSE; } my_log(LOG_INFO, "NetBIOS name: ptr query start"); (void) SCNetworkReachabilitySetCallback(ptrTarget, ptr_query_callback, NULL); (void) SCNetworkReachabilityScheduleWithRunLoop(ptrTarget, rl, kCFRunLoopDefaultMode); return TRUE; }
STATIC bool RTADVSocketOpenSocket(RTADVSocketRef sock) { if (sock->fd_open) { return (TRUE); } timer_cancel(S_globals->timer_callout); S_globals->read_fd_refcount++; my_log(LOG_INFO, "RTADVSocketOpenSocket (%s): refcount %d", if_name(sock->if_p), S_globals->read_fd_refcount); sock->fd_open = TRUE; if (S_globals->read_fd_refcount > 1) { /* already open */ return (TRUE); } if (S_globals->read_fd != NULL) { my_log(LOG_INFO, "RTADVSocketOpenSocket(): socket is still open"); } else { int sockfd; sockfd = open_rtadv_socket(); if (sockfd < 0) { my_log(LOG_ERR, "RTADVSocketOpenSocket: socket() failed, %s", strerror(errno)); goto failed; } my_log(LOG_INFO, "RTADVSocketOpenSocket(): opened RTADV socket %d", sockfd); /* register as a reader */ S_globals->read_fd = FDCalloutCreate(sockfd, RTADVSocketRead, NULL, NULL); } return (TRUE); failed: RTADVSocketCloseSocket(sock); return (FALSE); }
static boolean_t DHCPv6SocketOpenSocket(DHCPv6SocketRef sock) { if (sock->fd_open) { return (TRUE); } timer_cancel(S_globals->timer_callout); S_globals->read_fd_refcount++; my_log(LOG_DEBUG, "DHCPv6SocketOpenSocket (%s): refcount %d", if_name(sock->if_p), S_globals->read_fd_refcount); sock->fd_open = TRUE; if (S_globals->read_fd_refcount > 1) { /* already open */ return (TRUE); } if (S_globals->read_fd != NULL) { my_log(LOG_DEBUG, "DHCPv6SocketOpenSocket(): socket is still open"); } else { int sockfd; sockfd = open_dhcpv6_socket(S_client_port); if (sockfd < 0) { my_log(LOG_ERR, "DHCPv6SocketOpenSocket: socket() failed, %s", strerror(errno)); goto failed; } my_log(LOG_DEBUG, "DHCPv6SocketOpenSocket(): opened DHCPv6 socket %d", sockfd); /* register as a reader */ S_globals->read_fd = FDCalloutCreate(sockfd, DHCPv6SocketRead, NULL, NULL); } return (TRUE); failed: DHCPv6SocketCloseSocket(sock); return (FALSE); }
/* ** Diables the mrouted API and relases by this the lock. ** */ void disableMRouter() { if ( setsockopt( MRouterFD, IPPROTO_IP, MRT_DONE, NULL, 0 ) || close( MRouterFD ) ) { MRouterFD = 0; my_log( LOG_ERR, errno, "MRT_DONE/close" ); } MRouterFD = 0; }
static void xboard_get(xboard_t * xboard, char string[], int size) { ASSERT(xboard!=NULL); ASSERT(string!=NULL); ASSERT(size>=256); if (!io_get_line(xboard->io,string,size)) { // EOF my_log("POLYGLOT *** EOF from XBoard ***\n"); quit(); } }
void k_set_ttl(int t) { #ifndef RAW_OUTPUT_IS_RAW u_char ttl; ttl = t; if (setsockopt(MRouterFD, IPPROTO_IP, IP_MULTICAST_TTL, (char *)&ttl, sizeof(ttl)) < 0) my_log(LOG_ERR, errno, "setsockopt IP_MULTICAST_TTL %u", ttl); #endif curttl = t; }
/** * Return in how many seconds age_callout_queue() would like to be called. * Return -1 if there are no events pending. */ int timer_nextTimer() { if (queue) { if (queue->time < 0) { my_log(LOG_WARNING, 0, "timer_nextTimer top of queue says %d", queue->time); return 0; } return queue->time; } return -1; }
int DHCPv6SocketTransmit(DHCPv6SocketRef sock, DHCPv6PacketRef pkt, int pkt_len) { DHCPv6OptionErrorString err; int ret; boolean_t needs_close = FALSE; if (sock->fd_open == FALSE) { /* open the DHCPv6 socket in case it's needed */ if (DHCPv6SocketOpenSocket(sock) == FALSE) { my_log(LOG_ERR, "DHCPv6Socket: failed to open socket"); return (FALSE); } needs_close = TRUE; } if (S_verbose) { DHCPv6OptionListRef options; CFMutableStringRef str; str = CFStringCreateMutable(NULL, 0); DHCPv6PacketPrintToString(str, pkt, pkt_len); options = DHCPv6OptionListCreateWithPacket(pkt, pkt_len, &err); if (options == NULL) { my_log_fl(LOG_DEBUG, "parse options failed, %s", err.str); } else { DHCPv6OptionListPrintToString(str, options); DHCPv6OptionListRelease(&options); } my_log(-LOG_DEBUG,"[%s] Transmit %@", if_name(sock->if_p), str); CFRelease(str); } ret = S_send_packet(FDCalloutGetFD(S_globals->read_fd), if_link_index(sock->if_p), pkt, pkt_len); if (needs_close) { DHCPv6SocketCloseSocket(sock); } return (ret); }
static void parse_id(uci_t * uci, const char string[]) { parse_t parse[1]; char command[StringSize]; char option[StringSize]; char argument[StringSize]; ASSERT(uci!=NULL); ASSERT(string!=NULL); // init strcpy(command,"id"); parse_open(parse,string); parse_add_keyword(parse,"author"); parse_add_keyword(parse,"name"); // loop while (parse_get_word(parse,option,StringSize)) { parse_get_string(parse,argument,StringSize); if (UseDebug) my_log("POLYGLOT COMMAND \"%s\" OPTION \"%s\" ARGUMENT \"%s\"\n",command,option,argument); if (false) { } else if (my_string_equal(option,"author")) { ASSERT(!my_string_empty(argument)); my_string_set(&uci->author,argument); } else if (my_string_equal(option,"name")) { ASSERT(!my_string_empty(argument)); my_string_set(&uci->name,argument); } else { my_log("POLYGLOT unknown option \"%s\" for command \"%s\"\n",option,command); } } parse_close(parse); if (UseDebug) my_log("POLYGLOT engine name \"%s\" author \"%s\"\n",uci->name,uci->author); }
STATIC void RTADVSocketDelayedClose(void * arg1, void * arg2, void * arg3) { if (S_globals->read_fd == NULL) { my_log(LOG_NOTICE, "RTADVSocketDelayedClose(): socket is already closed"); return; } if (S_globals->read_fd_refcount > 0) { my_log(LOG_NOTICE, "RTADVSocketDelayedClose(): called when socket in use"); return; } my_log(LOG_INFO, "RTADVSocketDelayedClose(): closing RTADV socket %d", FDCalloutGetFD(S_globals->read_fd)); /* this closes the file descriptor */ FDCalloutRelease(&S_globals->read_fd); return; }
const char * option_get(option_list_t *option, const char name[]) { option_t * opt; ASSERT(name!=NULL); opt = option_find(option,name); if (opt == NULL) my_fatal("option_get(): unknown option \"%s\"\n",name); if (UseDebug) my_log("POLYGLOT OPTION GET \"%s\" -> \"%s\"\n",opt->name,opt->value); return opt->value; }
static void update_remaining_time(){ double reduce; if(State->timer->running){ my_timer_stop(State->timer); reduce = my_timer_elapsed_real(State->timer); my_log("POLYGLOT reducing remaing time by %f seconds\n",reduce); XB->my_time -= reduce; if(XB->my_time<0.0){ XB->my_time=0.0; } } }
static intptr_t open_conf_file(){ char_t *s=init_char(); add_chars(s,DAWN_HOME); add_chars(s,CONF_FILE); add_terminal(s); intptr_t fd=open(s->data,O_RDWR); if(fd==-1){ my_log(ERROR,"open config file error\n"); } destroy_char(s); return fd; }
static void DHCPv6SocketDelayedClose(void * arg1, void * arg2, void * arg3) { if (S_globals->read_fd == NULL) { my_log(LOG_ERR, "DHCPv6SocketDelayedClose(): socket is already closed"); return; } if (S_globals->read_fd_refcount > 0) { my_log(LOG_ERR, "DHCPv6SocketDelayedClose(): called when socket in use"); return; } my_log(LOG_DEBUG, "DHCPv6SocketDelayedClose(): closing DHCPv6 socket %d", FDCalloutGetFD(S_globals->read_fd)); /* this closes the file descriptor */ FDCalloutRelease(&S_globals->read_fd); return; }
pthread_t dispatcher(int idx ) { pthread_t tid; int * pIndex = malloc(sizeof(int)); *pIndex = idx; if ( 0 != pthread_create(&tid, NULL, dispatcher_thread_handler, (void*)pIndex )) { my_log("Error: Cannot create thread for dispatcher\n"); return 0; } return tid; }
/** * Handles incoming membership reports, and * appends them to the routing table. */ void acceptGroupReport(uint32_t src, uint32_t group, uint8_t type) { struct IfDesc *sourceVif; // Sanitycheck the group adress... if(!IN_MULTICAST( ntohl(group) )) { my_log(LOG_WARNING, 0, "The group address %s is not a valid Multicast group.", inetFmt(group, s1)); return; } // Find the interface on which the report was recieved. sourceVif = getIfByAddress( src ); if(sourceVif == NULL) { my_log(LOG_WARNING, 0, "No interfaces found for source %s", inetFmt(src,s1)); return; } if(sourceVif->InAdr.s_addr == src) { my_log(LOG_NOTICE, 0, "The IGMP message was from myself. Ignoring."); return; } // We have a IF so check that it's an downstream IF. if(sourceVif->state == IF_STATE_DOWNSTREAM) { my_log(LOG_DEBUG, 0, "Should insert group %s (from: %s) to route table. Vif Ix : %d", inetFmt(group,s1), inetFmt(src,s2), sourceVif->index); // The membership report was OK... Insert it into the route table.. insertRoute(group, sourceVif->index); } else { // Log the state of the interface the report was recieved on. my_log(LOG_INFO, 0, "Membership report was recieved on %s. Ignoring.", sourceVif->state==IF_STATE_UPSTREAM?"the upstream interface":"a disabled interface"); } }