/* *=========================================================================== * ipnet_nat_proxy_sip_addrportstrparse *=========================================================================== * Description: Parse the address/port string * This routine parses a combination of address and port string. * The address part can be terminated by ':', '\r' or '>' * characters. * Parameters: pstr - pointer to message * pipaddr - buffer for parsed IP address * pport - buffer for parsed port * type - type of search * Returns: The next character position after the parsed string or * IP_NULL if parse fails */ IP_STATIC char * ipnet_nat_proxy_sip_addrportstrparse(char *pstr, Ip_u32 *pipaddr, int *pport, int type) { int i; char *pend; Ip_bool noport = IP_FALSE; char tmpholder[20]; if (type == SIP_ADDRESS_PORT_STRING) { for (i = 0; i < 20; i++) { if (pstr[i] == ':' || pstr[i] == '\r' || pstr[i] == '>') break; else tmpholder[i] = pstr[i]; } if (i >= 20 || i == 0) { IPCOM_LOG0(ERR, "ipnet_nat_proxy_sip_payload_parse() :: ERROR: invalid string"); return IP_NULL; } /* If the address terminated by these characters, then the parsed * string is considered to contain only the address informantion. */ if (pstr[i] == '\r' || pstr[i] == '>') noport = IP_TRUE; tmpholder[i] = 0; *pipaddr = ipcom_inet_addr(tmpholder); if (*pipaddr == IP_INADDR_NONE) return IP_NULL; *pipaddr = ip_ntohl(*pipaddr); pstr += i; } if (type == SIP_PORT_STRING || (type == SIP_ADDRESS_PORT_STRING && noport == IP_FALSE)) { if (type == SIP_ADDRESS_PORT_STRING) pstr++; /* find the port number */ *pport = ipcom_strtol(pstr, &pend, 10); pstr = pend; } else *pport = 0; return pstr; }
/* *=========================================================================== * ipnet_nat_proxy_sip_localaddrprocess *=========================================================================== * Description: Process the private transport address * Parameters: pmsgstr - pointer to message * pipaddrstr - pointer to buffer for the local address string * pgaddrstr - pointer to buffer for the gloab address string * pcallid - pointer to the call id string * type - type of search * ppend - pointer to pointer to last byte of message * Returns: The next character position after the parsed string or * IP_NULL if parse fails */ IP_STATIC char * ipnet_nat_proxy_sip_localaddrprocess(char *pmsgstr, char *pipaddrstr, char *pgaddrstr, char *pcallid, int type, Ipnet_nat_proxy_param *param, char **ppend) { int localport, newport; int len, diff; Ip_u32 ipaddr; char *pstart; char tmpholder[30]; Ipnet_nat_proxy_tuple proxy_tuple; (void)pcallid; SIP_SKIP_SPACES(pmsgstr); pstart = pmsgstr; pmsgstr = ipnet_nat_proxy_sip_addrportstrparse(pmsgstr, &ipaddr, &localport, type); if (pmsgstr == IP_NULL) return IP_NULL; if (!localport) localport = SIP_DEFAULT_PORT; if (type == SIP_ADDRESS_PORT_STRING) { ipaddr = ip_htonl(ipaddr); (void)ipcom_inet_ntop(IP_AF_INET, &ipaddr, pipaddrstr, 16); ipaddr = ip_ntohl(ipaddr); } else /* PORT string only */ { ipaddr = ipcom_inet_addr(pipaddrstr); ipaddr = ip_ntohl(ipaddr); } /* make sure it is the private address, otherwise no translation */ if (ipaddr != param->tuple.private_addr) return pmsgstr; /* create a bind entry for this transport address if it hasn't been created yet */ if (param->tuple.private_port != localport) { ipcom_memset(&proxy_tuple, 0, sizeof(proxy_tuple)); proxy_tuple.protocol = IP_IPPROTO_UDP; proxy_tuple.private_addr = ipaddr; proxy_tuple.private_port = localport; newport = ipnet_nat_proxy_add_mapping(&proxy_tuple, IPNET_NAT_SIP_ENTRY_MEDIA_TIMEOUT, param->mapping, IP_FALSE, /* Use port translation */ IP_TRUE, /* Inbound session */ IP_NULL, IP_NULL); if (newport < 0) { IPCOM_LOG2(ERR, "ipnet_nat_proxy_sip_localaddrprocess() :: Failed to add mapping for address = 0x%08x, port = %d", ipaddr, localport); } else { IPCOM_LOG2(DEBUG, "ipnet_nat_proxy_sip_localaddrprocess() :: Added mapping for address = 0x%08x, port = %d", ipaddr, localport); } } else { newport = param->nat_port; IPCOM_LOG2(DEBUG, "ipnet_nat_proxy_sip_localaddrprocess() :: Mapping already existed for address = 0x%08x, port = %d", ipaddr, localport); } /* compose the new modified string */ len = 0; if (type == SIP_ADDRESS_PORT_STRING) { ipaddr = ip_htonl(param->nat_addr); (void)ipcom_inet_ntop(IP_AF_INET, &ipaddr, tmpholder, 16); ipcom_strcpy(pgaddrstr, tmpholder); len = ipcom_strlen(tmpholder); tmpholder[len++]= ':'; } ipcom_sprintf(tmpholder + len, "%d", newport); IPCOM_LOG1(DEBUG, "ipnet_nat_proxy_sip_localaddrprocess() new str: %s", tmpholder); if (ipnet_nat_proxy_sip_modmsg(tmpholder, ipcom_strlen(tmpholder), pstart, pmsgstr - pstart, ppend) < 0) { return IP_NULL; } diff = ipcom_strlen(tmpholder) - (pmsgstr - pstart); return pmsgstr + diff; }
static void ipsecctrl_saTables_print(Argvars *vars, Ip_u8 direction, Ip_u8 protocol, int domain) { Ipipsec_ioctl_sactrl sa_next; Ipipsec_ioctl_sactrl sa_u64; Ip_err retval; int i, num; Ip_tag tags[41]; char table[32]; #ifdef IPCOM_USE_INET6 char str[IP_INET6_ADDRSTRLEN]; #else char str[16]; #endif /* pre-init print stuff. */ ipcom_sprintf(table, "ipsecSa%s%s", protocol == IP_IPPROTO_AH ? "Ah" : "Esp", direction == IPIPSEC_SADIR_INPUT ? "In" : direction == IPIPSEC_SADIR_OUTPUT ? "Out" : "Any"); /* Fill in the info tags. */ tags[0] = IPIPSEC_SACTRLT_GET_SaSelector; tags[2] = IPIPSEC_SACTRLT_GET_SaCreator; tags[4] = IPIPSEC_SACTRLT_GET_Encapsulation; tags[6] = IPIPSEC_SACTRLT_GET_EncAlg; tags[8] = IPIPSEC_SACTRLT_GET_EncKeyLength; tags[10] = IPIPSEC_SACTRLT_GET_AuthAlg; tags[12] = IPIPSEC_SACTRLT_GET_AuthKeyLength; tags[14] = IPIPSEC_SACTRLT_GET_RepWinSize; tags[16] = IPIPSEC_SACTRLT_GET_LimitSeconds; tags[18] = IPIPSEC_SACTRLT_GET_LimitKbytes; tags[20] = IPIPSEC_SACTRLT_GET_AccSeconds; tags[22] = IPIPSEC_SACTRLT_GET_InAccKbytes; tags[24] = IPIPSEC_SACTRLT_GET_DecryptErrors; tags[26] = IPIPSEC_SACTRLT_GET_AuthErrors; tags[28] = IPIPSEC_SACTRLT_GET_ReplayErrors; tags[30] = IPIPSEC_SACTRLT_GET_PolicyErrors; tags[32] = IPIPSEC_SACTRLT_GET_PadErrors; tags[34] = IPIPSEC_SACTRLT_GET_OtherReceiveErrors; tags[36] = IPIPSEC_SACTRLT_GET_OutAccKbytes; tags[38] = IPIPSEC_SACTRLT_GET_OutSendErrors; tags[40] = IP_TAG_END; ipcom_printf(IP_LF"***** %stable ::"IP_LF, table); /* Get and print the SAs in MIB format. */ sa_next.arg.next.spi_n = 0; for (num = 0;;) { ipcom_memcpy(&sa_next.sa, &sa_next.arg.next, sizeof(Ipipsec_sa_handle)); sa_next.arg.next.direction = direction; sa_next.arg.next.protocol = protocol; sa_next.arg.next.domain = (Ip_u8)domain; if (ipcom_socketioctl(vars->fd, IP_SIOCXIPSEC_NEXT_SA, &sa_next) < 0) { ipcom_printf("ipsecctrl: ipcom_socketioctl(NEXT_SA) failed (%s)"IP_LF, ipcom_strerror(ipcom_errno)); return; } if (sa_next.arg.next.spi_n == 0) break; retval = ipipsec_sactrl(&sa_next.arg.next, tags); if (retval != IPCOM_SUCCESS) { ipcom_printf("ipsecctrl: ipipsec_sactrl(info) failed, error = %d"IP_LF, retval); return; } /* SA id */ ipcom_printf(IP_LF"%sEntry #%d:"IP_LF "%sAddresstype = %d"IP_LF "%sAddress = %s"IP_LF "%sSpi = 0x%lx"IP_LF , table, num , table, domain == IP_AF_INET ? 1 : domain == IP_AF_INET6 ? 2 : 3 , table, ipcom_inet_ntop(sa_next.arg.next.domain, &sa_next.arg.next.dst, str, sizeof(str)) , table, ip_ntohl(sa_next.arg.next.spi_n)); /* SA MIB entries */ for (i = 0; tags[i] != IP_TAG_END; i += 2) { switch(tags[i]) { case IPIPSEC_SACTRLT_GET_SaSelector : ipcom_printf("%sSelector = %ld"IP_LF, table, tags[i+1]); break; case IPIPSEC_SACTRLT_GET_SaCreator : ipcom_printf("%sCreator = %s"IP_LF, table, mib_Creator[tags[i+1]]); break; case IPIPSEC_SACTRLT_GET_Encapsulation : ipcom_printf("%sEncapsulation = %s"IP_LF, table, mib_Encapsulation[tags[i+1]]); break; case IPIPSEC_SACTRLT_GET_EncAlg : ipcom_printf("%sEncAlg = %s"IP_LF, table, mib_EncAlg[tags[i+1]]); break; case IPIPSEC_SACTRLT_GET_EncKeyLength : ipcom_printf("%sEncKeyLength = %ld"IP_LF, table, tags[i+1]); break; case IPIPSEC_SACTRLT_GET_AuthAlg : ipcom_printf("%sAuthAlg = %s"IP_LF, table, mib_AuthAlg[tags[i+1]]); break; case IPIPSEC_SACTRLT_GET_AuthKeyLength : ipcom_printf("%sAuthKeyLength = %ld"IP_LF, table, tags[i+1]); break; case IPIPSEC_SACTRLT_GET_RepWinSize : ipcom_printf("%sRepWinSize = %ld"IP_LF, table, tags[i+1]); break; case IPIPSEC_SACTRLT_GET_LimitSeconds : ipcom_printf("%sLimitSeconds = %ld"IP_LF, table, tags[i+1]); break; case IPIPSEC_SACTRLT_GET_LimitKbytes : ipcom_printf("%sLimitKbytes = %ld"IP_LF, table, tags[i+1]); break; case IPIPSEC_SACTRLT_GET_AccSeconds : ipcom_printf("%sAccSeconds = %ld"IP_LF, table, tags[i+1]); break; case IPIPSEC_SACTRLT_GET_InAccKbytes : ipcom_printf("%sInAccKbytes = %ld"IP_LF, table, tags[i+1]); break; case IPIPSEC_SACTRLT_GET_OutAccKbytes : ipcom_printf("%sOutAccKbytes = %ld"IP_LF, table, tags[i+1]); break; case IPIPSEC_SACTRLT_GET_DecryptErrors : ipcom_printf("%sDecryptErrors = %ld"IP_LF, table, tags[i+1]); break; case IPIPSEC_SACTRLT_GET_AuthErrors : ipcom_printf("%sAuthErrors = %ld"IP_LF, table, tags[i+1]); break; case IPIPSEC_SACTRLT_GET_ReplayErrors : ipcom_printf("%sReplayErrors = %ld"IP_LF, table, tags[i+1]); break; case IPIPSEC_SACTRLT_GET_PolicyErrors : ipcom_printf("%sPolicyErrors = %ld"IP_LF, table, tags[i+1]); break; case IPIPSEC_SACTRLT_GET_PadErrors : ipcom_printf("%sPadErrors = %ld"IP_LF, table, tags[i+1]); break; case IPIPSEC_SACTRLT_GET_OtherReceiveErrors : ipcom_printf("%sOtherReceiveErrors = %ld"IP_LF, table, tags[i+1]); break; case IPIPSEC_SACTRLT_GET_OutSendErrors : ipcom_printf("%sOutSendErrors = %ld"IP_LF, table, tags[i+1]); break; default: ipcom_printf("error: unknown tag type '%ld'"IP_LF, tags[i]); break; } } /* for */ ipcom_memcpy(&sa_u64.sa, &sa_next.arg.next, sizeof(Ipipsec_sa_handle)); if (ipcom_socketioctl(vars->fd, IP_SIOCXIPSEC_InUserOctets, &sa_u64) == 0) ipcom_printf("%sInUserOctets = %ld"IP_LF, table, IP_U64_GETLO(sa_u64.arg.u64)); /*lint !e530 */ if (ipcom_socketioctl(vars->fd, IP_SIOCXIPSEC_InUserPackets, &sa_u64) == 0) ipcom_printf("%sInUserPackets = %ld"IP_LF, table, IP_U64_GETLO(sa_u64.arg.u64)); /*lint !e530 */ if (ipcom_socketioctl(vars->fd, IP_SIOCXIPSEC_OutUserOctets, &sa_u64) == 0) ipcom_printf("%sOutUserOctets = %ld"IP_LF, table, IP_U64_GETLO(sa_u64.arg.u64)); /*lint !e530 */ if (ipcom_socketioctl(vars->fd, IP_SIOCXIPSEC_OutUserPackets, &sa_u64) == 0) ipcom_printf("%sOutUserPackets = %ld"IP_LF, table, IP_U64_GETLO(sa_u64.arg.u64)); /*lint !e530 */ } }
/* *=========================================================================== * ipsecctrl_sa *=========================================================================== */ static int ipsecctrl_sa(Argvars *vars) { Ipipsec_ioctl_sactrl sa_next; Ipipsec_ioctl_sactrl sa_group; int num; Ip_err retval; Ip_tag tags[7]; #ifdef IPCOM_USE_INET6 char str[IP_INET6_ADDRSTRLEN]; char str2[IP_INET6_ADDRSTRLEN]; #else char str[16], str2[16]; #endif /* Print all SAs. */ ipcom_printf("SA - Security Associations:"IP_LF); sa_next.arg.next.spi_n = 0; /* get first SA. */ for (num = 0;;) { ipcom_memcpy(&sa_next.sa, &sa_next.arg.next, sizeof(Ipipsec_sa_handle)); sa_next.arg.next.direction = IPIPSEC_SADIR_ANY; sa_next.arg.next.protocol = 0; sa_next.arg.next.domain = 0; /* Get first/next Selector */ if (ipcom_socketioctl(vars->fd, IP_SIOCXIPSEC_NEXT_SA, &sa_next) < 0) { ipcom_printf("ipsecctrl: ipcom_socketioctl(NEXT_SA) failed (%s)"IP_LF, ipcom_strerror(ipcom_errno)); return -1; } if (sa_next.arg.next.spi_n == 0) break; /* Get additional information. */ tags[0] = IPIPSEC_SACTRLT_GET_AuthAlg; tags[2] = IPIPSEC_SACTRLT_GET_EncAlg; tags[4] = IP_TAG_END; retval = ipipsec_sactrl(&sa_next.arg.next, tags); if (retval != IPCOM_SUCCESS) { ipcom_printf("ipsecctrl: ipipsec_sactrl(info) failed, error = %d"IP_LF, retval); return -1; } ipcom_printf("[%2d] :: %-6s %s spi=0x%-5lx src=%-17s dst=%-17s auth=%s", ++num, sa_next.arg.next.direction == IPIPSEC_SADIR_INPUT ? "input" : sa_next.arg.next.direction == IPIPSEC_SADIR_OUTPUT ? "output" : "any", ipcom_ipproto_name(sa_next.arg.next.protocol), ip_ntohl(sa_next.arg.next.spi_n), ipcom_inet_ntop(sa_next.arg.next.domain, &sa_next.arg.next.src, str, sizeof(str)), ipcom_inet_ntop(sa_next.arg.next.domain, &sa_next.arg.next.dst, str2, sizeof(str2)), mib_AuthAlg[tags[1]]); if (sa_next.arg.next.protocol == IP_IPPROTO_ESP) ipcom_printf(" enc=%s", mib_EncAlg[tags[3]]); if (sa_next.arg.next.priority != 0) ipcom_printf(" pri=%d", (int)sa_next.arg.next.priority); if (sa_next.arg.next.dscp != 0) ipcom_printf(" DSCP=%d", (int)sa_next.arg.next.dscp); ipcom_printf(IP_LF); /* Get grouped info */ ipcom_memcpy(&sa_group.sa, &sa_next.arg.next, sizeof(Ipipsec_sa_handle)); if (ipcom_socketioctl(vars->fd, IP_SIOCXIPSEC_Grouped, &sa_group) < 0) { ipcom_printf("ipsecctrl: ipcom_socketioctl(Grouped) failed (%s)"IP_LF, ipcom_strerror(ipcom_errno)); return -1; } if (sa_group.arg.group.spi_n) /*lint !e530 */ { ipcom_printf(" -> %s spi=0x%-5lx src=%-17s dst=%-17s", ipcom_ipproto_name(sa_group.arg.group.protocol), ip_ntohl(sa_group.arg.group.spi_n), ipcom_inet_ntop(sa_next.arg.next.domain, &sa_next.arg.next.src, str, sizeof(str)), ipcom_inet_ntop(sa_group.arg.group.domain, &sa_next.arg.next.dst, str2, sizeof(str2))); if (sa_group.arg.group.priority != 0) ipcom_printf(" pri=%d", (int)sa_group.arg.group.priority); if (sa_group.arg.group.dscp != 0) ipcom_printf(" DSCP=%d", (int)sa_group.arg.group.dscp); ipcom_printf(IP_LF); } } ipcom_printf("Total of %d SAs."IP_LF, num); return 0; }
/* *=========================================================================== * ipsecctrl_flows *=========================================================================== */ static int ipsecctrl_flows(Argvars *vars) { Ipipsec_ctrl_selector sel; char srcport[32], dstport[32]; int num = 0; char str[IP_INET6_ADDRSTRLEN]; char str2[IP_INET6_ADDRSTRLEN+1]; ipcom_printf("Flows:"IP_LF); sel.Index = 0; /* get first selector. */ /* Get and print the Selectors in MIB format. */ for (;;) { /* Get first/next Selector */ if (ipcom_socketioctl(vars->fd, IP_SIOCXIPSEC_SELECTOR, &sel) < 0) { ipcom_printf("ipsecctrl: ipcom_socketioctl(SELECTOR) failed (%s)"IP_LF, ipcom_strerror(ipcom_errno)); return -1; } if (sel.Index == 0) break; /* Print selector aka flow: */ num++; ipcom_printf("[%ld] :: %s ", sel.Index, FLOW_TYPE(sel.flowtype)); if (sel.flowpri != 0) ipcom_printf("pri=%d ", (signed char)sel.flowpri); /* source */ if (sel.LocalPort != sel.LocalMaxPort) ipcom_sprintf(srcport, "%d-%d", (int)ip_ntohs(sel.LocalPort), (int)ip_ntohs(sel.LocalMaxPort)); else if (sel.LocalPort == 0) ipcom_strcpy(srcport, "any"); else ipcom_sprintf(srcport, "%d", (int)ip_ntohs(sel.LocalPort)); if (ipcom_memcmp(&sel.LocalId, &sel.LocalMaxId, sizeof(union Ip_in_addr_union))) ipcom_sprintf(str2, "-%s", ipcom_inet_ntop(sel.domain, &sel.LocalMaxId, str, sizeof(str))); else *str2 = '\0'; ipcom_printf("src=%s%s/%d:%s ", ipcom_inet_ntop(sel.domain, &sel.LocalId, str, sizeof(str)), str2, ipipsec_addrmasklen(sel.domain, (Ip_u8 *)&sel.local_mask), srcport); /* destination */ if (sel.RemotePort != sel.RemoteMaxPort) ipcom_sprintf(dstport, "%d-%d", (int)ip_ntohs(sel.RemotePort), (int)ip_ntohs(sel.RemoteMaxPort)); else if (sel.RemotePort == 0) ipcom_strcpy(dstport, "any"); else ipcom_sprintf(dstport, "%d", (int)ip_ntohs(sel.RemotePort)); if (ipcom_memcmp(&sel.RemoteId, &sel.RemoteMaxId, sizeof(union Ip_in_addr_union))) ipcom_sprintf(str2, "-%s", ipcom_inet_ntop(sel.domain, &sel.RemoteMaxId, str, sizeof(str))); else *str2 = '\0'; ipcom_printf("dst=%s%s/%d:%s ", ipcom_inet_ntop(sel.domain, &sel.RemoteId, str, sizeof(str)), str2, ipipsec_addrmasklen(sel.domain, (Ip_u8 *)&sel.remote_mask), dstport); ipcom_printf("%s", ipcom_ipproto_name(sel.Protocol)); switch (sel.Protocol) { case IP_IPPROTO_ICMP: case IP_IPPROTO_ICMPV6: if (sel.ports[0] || sel.ports[1]) ipcom_printf(" type=%d code=%d", sel.ports[0], sel.ports[1]); break; case IP_IPPROTO_MH: if (sel.ports[0]) ipcom_printf(" type=%d", sel.ports[0]); break; default: break; } /* Print SA */ if (sel.sa.domain) { if (sel.sa.domain == IPIPSEC_AF_BYPASS) ipcom_printf(" %s SA: %s", sel.direction == IPIPSEC_SADIR_INPUT ? "<-" : sel.direction == IPIPSEC_SADIR_OUTPUT ? "->" : "--", IPSECSATYPENAME(sel.sa.satype)); else ipcom_printf(" %s SA: %s spi=0x%lx src=%s dst=%s", sel.direction == IPIPSEC_SADIR_INPUT ? "<-" : sel.direction == IPIPSEC_SADIR_OUTPUT ? "->" : "--", IPSECSATYPENAME(sel.sa.satype), ip_ntohl(sel.sa.spi_n), ipcom_inet_ntop(sel.sa.domain, &sel.sa.src, str, sizeof(str)), ipcom_inet_ntop(sel.sa.domain, &sel.sa.dst, str2, sizeof(str2))); } else ipcom_printf(" %s SA: none", sel.direction == IPIPSEC_SADIR_INPUT ? "<-" : sel.direction == IPIPSEC_SADIR_OUTPUT ? "->" : "--"); ipcom_printf(IP_LF); } ipcom_printf("Total of %d flows."IP_LF, num); return 0; }
/* *=========================================================================== * ipnet_ip_forward_mib_handler_ipCidrRouteTable *=========================================================================== * Description: MIB handler for ipCidrRouteDest * Parameters: See file 'ipsnmp.h' * Returns: IPSNMP_ERROR_XXX * */ IP_STATIC Ip_s32 ipnet_ip_forward_mib_handler_ipCidrRouteTable(Ip_s32 cmd, char *id, Ipsnmp_varbind *vb, Ip_s32 magic, struct Ipsnmp_node_object *nodeobj) { Ip_s32 lid, bestindex, ret = -1; char *iid; char *buf = ipcom_malloc(IPSNMP_CONFIG_MAX_OBJECT_ID); char *best = ipcom_malloc(IPSNMP_CONFIG_MAX_OBJECT_ID); if(buf == IP_NULL || best == IP_NULL) { ret = IPSNMP_ERROR_GENERROR; goto exit; } lid = ipsnmp_util_last_subid(nodeobj->id); ip_assert(lid >= 1 && lid <= 16); bestindex = ipnet_ip_forward_mib_table_search_ipCidrRouteTable(id, buf, best, cmd); if(bestindex == -2) { ret = IPSNMP_ERROR_GENERROR; goto exit; } else if(bestindex == -1) { ret = IPSNMP_ERROR_NOSUCHNAME; goto exit; } if(cmd == IPSNMP_MIB_COMMAND_GET || cmd == IPSNMP_MIB_COMMAND_NEXT) { iid = ipsnmp_create_iid_direct(nodeobj->id, best); if(iid == IP_NULL) { ret = IPSNMP_ERROR_GENERROR; goto exit; } ip_assert(routewalk.bestrt != IP_NULL); switch(lid) { case 1: /* ipCidrRouteDest */ ret = ipsnmp_util_put_ipaddress(magic, iid, ip_ntohl(*(Ip_u32 *)routewalk.bestrt->hdr.key)); break; case 2: /* ipCidrRouteMask */ if(routewalk.bestrt->hdr.mask != IP_NULL) ret = ipsnmp_util_put_ipaddress(magic, iid, ip_ntohl(*(Ip_u32 *)routewalk.bestrt->hdr.mask)); else ret = ipsnmp_util_put_ipaddress(magic, iid, 0xffffffff); break; case 3: /* ipCidrRouteTos */ ret = ipsnmp_util_put_integer(magic, iid, 0); break; case 4: /* ipCidrRouteNextHop */ if(IP_BIT_ISSET(routewalk.bestrt->hdr.flags, IPNET_RTF_GATEWAY)) { struct Ip_sockaddr_in *sa = (struct Ip_sockaddr_in *)routewalk.bestrt->gateway; ret = ipsnmp_util_put_ipaddress(magic, iid, ip_ntohl(sa->sin_addr.s_addr)); } else ret = ipsnmp_util_put_ipaddress(magic, iid, 0); break; case 5: /* ipCidrRouteIfIndex */ ret = ipsnmp_util_put_integer(magic, iid, routewalk.bestrt->netif->ipcom.ifindex); break; case 6: /* ipCidrRouteType */ if(IP_BIT_ISSET(routewalk.bestrt->hdr.flags, IPNET_RTF_GATEWAY)) ret = ipsnmp_util_put_integer(magic, iid, 4); /* remote */ else ret = ipsnmp_util_put_integer(magic, iid, 3); /* local */ break; case 7: /* ipCidrRouteProto */ ret = ipsnmp_util_put_integer(magic, iid, 2); /* local */ break; case 8: /* ipCidrRouteAge */ ret = ipsnmp_util_put_integer(magic, iid, 0); break; case 9: /* ipCidrRouteInfo */ ret = ipsnmp_util_put_oid(magic, iid, "0.0"); break; case 10: /* ipCidrRouteNextHopAS */ ret = ipsnmp_util_put_integer(magic, iid, 0); break; case 11: /* ipCidrRouteMetric1 */ ret = ipsnmp_util_put_integer(magic, iid, -1); break; case 12: /* ipCidrRouteMetric2 */ ret = ipsnmp_util_put_integer(magic, iid, -1); break; case 13: /* ipCidrRouteMetric3 */ ret = ipsnmp_util_put_integer(magic, iid, -1); break; case 14: /* ipCidrRouteMetric4 */ ret = ipsnmp_util_put_integer(magic, iid, -1); break; case 15: /* ipCidrRouteMetric5 */ ret = ipsnmp_util_put_integer(magic, iid, -1); break; case 16: /* ipCidrRouteStatus */ ret = ipsnmp_util_put_integer(magic, iid, 1); /* active */ break; default: IP_PANIC(); ret = IPSNMP_ERROR_GENERROR; break; } ipcom_free(iid); } if(cmd == IPSNMP_MIB_COMMAND_TEST || cmd == IPSNMP_MIB_COMMAND_SET) { (void)vb; switch(lid) { case 5: /* ipCidrRouteIfIndex */ case 6: /* ipCidrRouteType */ case 9: /* ipCidrRouteInfo */ case 10: /* ipCidrRouteNextHopAS */ case 11: /* ipCidrRouteMetric1 */ case 12: /* ipCidrRouteMetric2 */ case 13: /* ipCidrRouteMetric3 */ case 14: /* ipCidrRouteMetric4 */ case 15: /* ipCidrRouteMetric5 */ case 16: /* ipCidrRouteStatus */ ret = IPSNMP_ERROR_NOSUCHNAME; break; default: IP_PANIC(); ret = IPSNMP_ERROR_GENERROR; break; } } exit: if(buf != IP_NULL) ipcom_free(buf); if(best != IP_NULL) ipcom_free(best); return ret; }
/* *=========================================================================== * ipnet_ip_mib_cb_ipCidrRouteTable *=========================================================================== * Description: * Parameters: * Returns: * */ IP_STATIC Ip_bool ipnet_ip_mib_cb_ipCidrRouteTable(Ipnet_route_entry *rt, Ipsnmp_route_walk *rwp) { Ip_s32 tmp, lex, len = 0; /* Early exit if exact match was found previously */ if(rwp->bestrt != IP_NULL && (rwp->cmd == IPSNMP_MIB_COMMAND_GET || rwp->cmd == IPSNMP_MIB_COMMAND_TEST || rwp->cmd == IPSNMP_MIB_COMMAND_SET)) goto exit; if(rt->netif == IP_NULL) goto exit; /* Do not use hidden entries */ if(IP_BIT_ISSET(rt->hdr.flags, IPNET_RTF_X_HIDDEN)) goto exit; /* Route must be usable */ if(IP_BIT_ISFALSE(rt->hdr.flags, IPNET_RTF_UP)) goto exit; /* Do not use link layer entries */ if(IP_BIT_ISSET(rt->hdr.flags, IPNET_RTF_LLINFO)) goto exit; /* Do not use loopback entries */ if (IP_BIT_ISSET(rt->netif->ipcom.flags, IP_IFF_LOOPBACK)) goto exit; ip_assert(rt->hdr.key != IP_NULL); /* Do not use multicast entries */ if(IP_IN_CLASSD(*(Ip_u32 *)rt->hdr.key)) goto exit; /* Do not use broadcast entries */ if(ip_ntohl(*(Ip_u32 *)rt->hdr.key) == IP_INADDR_BROADCAST) goto exit; if(rwp->count_only == IP_TRUE) { count++; goto exit; } rwp->buf[0] = '\0'; /* ipCidrRouteDest */ if(ipcom_inet_ntop(IP_AF_INET, rt->hdr.key, &rwp->buf[len], IPSNMP_CONFIG_MAX_OBJECT_ID-len) == IP_NULL) goto exit; len = ipcom_strlen(rwp->buf); if(ipcom_snprintf(&rwp->buf[len], IPSNMP_CONFIG_MAX_OBJECT_ID-len, ".") < 0) goto exit; len = ipcom_strlen(rwp->buf); /* ipCidrRouteMask */ if(rt->hdr.mask == IP_NULL) { if(ipcom_snprintf(&rwp->buf[len], IPSNMP_CONFIG_MAX_OBJECT_ID-len, "255.255.255.255") < 0) goto exit; } else { if(ipcom_inet_ntop(IP_AF_INET, rt->hdr.mask, &rwp->buf[len], IPSNMP_CONFIG_MAX_OBJECT_ID-len) == IP_NULL) goto exit; } len = ipcom_strlen(rwp->buf); if(ipcom_snprintf(&rwp->buf[len], IPSNMP_CONFIG_MAX_OBJECT_ID-len, ".") < 0) goto exit; len = ipcom_strlen(rwp->buf); /* ipCidrRouteTos */ tmp = 0; if(ipcom_snprintf(&rwp->buf[len], IPSNMP_CONFIG_MAX_OBJECT_ID-len, "%d.", (int)tmp) < 0) goto exit; len = ipcom_strlen(rwp->buf); /* ipCidrRouteNextHop */ if(IP_BIT_ISSET(rt->hdr.flags, IPNET_RTF_GATEWAY)) { struct Ip_sockaddr_in *sa; ip_assert(rt->gateway != IP_NULL); sa = (struct Ip_sockaddr_in *)rt->gateway; if(ipcom_inet_ntop(IP_AF_INET, &sa->sin_addr.s_addr, &rwp->buf[len], IPSNMP_CONFIG_MAX_OBJECT_ID - len) == IP_NULL) goto exit; } else { if(ipcom_snprintf(&rwp->buf[len], IPSNMP_CONFIG_MAX_OBJECT_ID-len, "0.0.0.0") < 0) goto exit; } len = ipcom_strlen(rwp->buf); if(ipcom_snprintf(&rwp->buf[len], IPSNMP_CONFIG_MAX_OBJECT_ID-len, ".") < 0) goto exit; len = ipcom_strlen(rwp->buf); if(len) rwp->buf[len-1] = '\0'; lex = ipsnmp_util_lexcmp_oid(rwp->buf, rwp->id); if(rwp->cmd == IPSNMP_MIB_COMMAND_NEXT) { if(lex > 0) { if(rwp->bestrt == IP_NULL || ipsnmp_util_lexcmp_oid(rwp->buf, rwp->best) < 0) { ipcom_strcpy(rwp->best, rwp->buf); rwp->bestrt = rt; } } } else { if(lex == 0) { ipcom_strcpy(rwp->best, rwp->buf); rwp->bestrt = rt; } } exit: /* Do not delete the entry */ return IP_FALSE; }