int gotFreshRoute(char *address, int staleness) { int i; struct sockaddr *sa; char interface_addr[16]; time_t curr_time = time(NULL); i = findInTable(address); //if there is a route that is not stale, return it if(i >= 0) { if(routing_table[i].timestamp == 0) { printf("No route\n"); return -1; } if(difftime(routing_table[i].timestamp, curr_time) < staleness) { printf("Got fresh route\n"); return i; } else { deleteRoute(i); printf("Got stale route, deleting\n"); return -1; } } printf("No route for %s\n", address); return -1; }
boolean RF22Router::deleteRouteTo(uint8_t dest) { uint8_t i; for (i = 0; i < RF22_ROUTING_TABLE_SIZE; i++) { if (_routes[i].dest == dest) { deleteRoute(i); return true; } } return false; }
void RF22Router::retireOldestRoute() { // We just obliterate the first in the table and clear the last deleteRoute(0); }
/** * Accept a V3 Membership Report */ void acceptV3GroupReport(uint32_t src, uint8_t type, struct igmpv3_groupreport* igmpv3rep) { 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) { // 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"); } else { my_log(LOG_DEBUG, 0, "IGMPv3 Membership Report") // TODO: Can we batch-report here? uint16_t num_entries = ntohl(igmpv3rep->num_entries); uint16_t eix = 0; while ( eix < num_entries ) { struct igmpv3_groupreport_entry* e = (struct igmpv3_groupreport_entry* igmpv3rep->grec) + eix; uint16_t num_sources = ntohl(e->nsrcs); uint16_t six = 0; while ( six < num_sources ) { uint32_t* srcgroup = (uint32_t* e->sources) + six; group = ntohl(*srcgroup); switch ( e->type == 0x0 ) { case IGMPV3_GRE_MODE_INCLUDE: case IGMPV3_GRE_CHMODE_INCLUDE: case IGMPV3_GRE_ALLOW_NEW_SOURCES: my_log(LOG_DEBUG, 0, "IGMPv3 Subscribe to %s.", inetFmt(group, s1)); insertRoute(group, sourceVif->index); break; case IGMPV3_GRE_MODE_EXCLUDE: case IGMPV3_GRE_CHMODE_EXCLUDE: case IGMPV3_GRE_BLOCK_OLD_SOURCES: my_log(LOG_DEBUG, 0, "IGMPv3 Unsubscribe from %s.", inetFmt(group, s1)); deleteRoute(group, sourceVif->index); break; default: my_log(LOG_INFO, 0, "Membership V3 group report received with unknown type %d.", e->type); } }; eix++; }; return; } }