bool DHCP_option_addrlist ( unsigned char * *optptr, uint32_t *optlen, unsigned char opttype, _ip_address *addrptr, uint32_t addrcount ) { /* Body */ unsigned char *opt = *optptr; _ip_address addr; if ((*optlen) < 4*addrcount+2) return FALSE; mqx_htonc(opt, opttype); opt++; mqx_htonc(opt, 4*addrcount); opt++; while (addrcount--) { addr = *addrptr++; mqx_htonl(opt, addr); opt += 4; } /* Endwhile */ *optlen -= 4*addrcount+2; *optptr = opt; return TRUE; } /* Endbody */
bool DHCP_option_string ( unsigned char * *optptr, uint32_t *optlen, unsigned char opttype, char *optval ) { /* Body */ uint32_t slen = 0; unsigned char *opt; opt = (unsigned char *)optval; while (*opt++) slen++; if ((*optlen) < slen+2) return FALSE; opt = *optptr; mqx_htonc(opt, opttype); opt++; mqx_htonc(opt, slen); opt++; _mem_copy(optval, opt, slen); opt += slen; *optlen -= slen+2; *optptr = opt; return TRUE; } /* Endbody */
bool DHCP_option_variable ( unsigned char * *optptr, uint32_t *optlen, unsigned char opttype, unsigned char *options, uint32_t num_options ) { /* Body */ uint32_t i; unsigned char *opt = *optptr; if ((*optlen) < (num_options + 2)) return FALSE; mqx_htonc(opt, opttype); opt++; mqx_htonc(opt, (unsigned char)num_options); opt++; for ( i = 0; i < num_options; i++ ) { mqx_htonc(opt, options[i]); opt++; } /* Endfor */ *optlen -= (num_options + 2); *optptr = opt; return TRUE; } /* Endbody */
static void RIP_build_header( unsigned char *buf, /* [OUT] the rip header */ uint8_t cmd, /* [IN] the commande */ uint8_t version /* [IN] the version */ ) { /* Body */ RIP_HEADER_PTR hd = (RIP_HEADER_PTR)buf; _mem_zero(buf, sizeof(RIP_HEADER)); mqx_htonc(hd->COMMAND, cmd); mqx_htonc(hd->VERSION, version); mqx_htons(hd->MBZ, 0); } /* Endbody */
void BOOTP_open ( TCPIP_PARM_BOOTP *parms ) { /* Body */ IP_IF_PTR if_ptr = (IP_IF_PTR)parms->handle; BOOTP_CFG_PTR bootp = (BOOTP_CFG_PTR) &parms->config; uint32_t error; error = BOOT_open(BOOT_service); if (error) { RTCSCMD_complete(parms, error); return; } /* Endif */ if_ptr->BOOTFN = BOOTP_service; /* Pick a random transaction ID */ bootp->XID = RTCS_rand(); /* Set initial timeout */ bootp->TIMEOUT = BOOTP_TIMEOUT_MIN; bootp->SECS = 0; /* Build a BOOTREQUEST packet */ mqx_htonc(bootp->PACKET.OP, BOOTPOP_BOOTREQUEST); mqx_htonc(bootp->PACKET.HTYPE, if_ptr->DEV_TYPE); mqx_htonc(bootp->PACKET.HLEN, if_ptr->DEV_ADDRLEN); mqx_htonc(bootp->PACKET.HOPS, 0); mqx_htonl(bootp->PACKET.XID, bootp->XID); mqx_htons(bootp->PACKET.FLAGS, 0x8000); mqx_htonl(bootp->PACKET.CIADDR, INADDR_ANY); mqx_htonl(bootp->PACKET.YIADDR, INADDR_ANY); mqx_htonl(bootp->PACKET.SIADDR, INADDR_ANY); mqx_htonl(bootp->PACKET.GIADDR, INADDR_ANY); _mem_zero(bootp->PACKET.CHADDR, sizeof(bootp->PACKET.CHADDR)); _mem_copy(if_ptr->DEV_ADDR, bootp->PACKET.CHADDR, if_ptr->DEV_ADDRLEN); /* Start the retransmission timer to start sending immediately */ bootp->RESEND.TIME = 0; bootp->RESEND.EVENT = BOOTP_send; bootp->RESEND.PRIVATE = if_ptr; TCPIP_Event_add(&bootp->RESEND); if_ptr->BOOT = (void *)parms; } /* Endbody */
bool DHCP_option_int8 ( unsigned char * *optptr, uint32_t *optlen, unsigned char opttype, unsigned char optval ) { /* Body */ unsigned char *opt = *optptr; if ((*optlen) < 3) return FALSE; mqx_htonc(opt, opttype); opt++; mqx_htonc(opt, 1); opt++; mqx_htonc(opt, optval); opt++; *optlen -= 3; *optptr = opt; return TRUE; } /* Endbody */
bool DHCP_option_addr ( unsigned char * *optptr, uint32_t *optlen, unsigned char opttype, _ip_address addr ) { /* Body */ unsigned char *opt = *optptr; if ((*optlen) < 6) return FALSE; mqx_htonc(opt, opttype); opt++; mqx_htonc(opt, 4); opt++; mqx_htonl(opt, addr); opt += 4; *optlen -= 6; *optptr = opt; return TRUE; } /* Endbody */
bool DHCP_option_int16 ( unsigned char * *optptr, uint32_t *optlen, unsigned char opttype, uint16_t optval ) { /* Body */ unsigned char *opt = *optptr; if ((*optlen) < 4) return FALSE; mqx_htonc(opt, opttype); opt++; mqx_htonc(opt, 2); opt++; mqx_htons(opt, optval); opt += 2; *optlen -= 4; *optptr = opt; return TRUE; } /* Endbody */
static uint32_t DNS_append_local_name ( unsigned char *qname_buffer, uint32_t total_length ) { /* Body */ uint32_t local_name_length = 0; uint32_t error; unsigned char *label_length_ptr; unsigned char label_length = 0; if ( DNS_Local_network_name[local_name_length] == '\0' ) { return( RTCSERR_DNS_INVALID_LOCAL_NAME ); }/* Endif */ /* If the Local Network is the ROOT Domain Name */ if ( ( DNS_Local_network_name[local_name_length] == '.' ) && ( DNS_Local_network_name[local_name_length + 1] == '\0' )) { mqx_htonc((qname_buffer + total_length), '\0'); return( DNS_OK ); }/* Endif */ label_length_ptr = qname_buffer + total_length; error = DNS_OK; while ( DNS_Local_network_name[local_name_length] ) { /* ** RFC 1035 says labels must start with a letter, but in practice ** some aren't */ if ( isalnum(DNS_Local_network_name[local_name_length]) ) { mqx_htonc((qname_buffer + total_length + 1), DNS_Local_network_name[local_name_length]); total_length++; local_name_length++; label_length++; } else { error = RTCSERR_DNS_INVALID_LOCAL_NAME; break; } /* Endif */ while ( ( DNS_Local_network_name[local_name_length] != '.' ) && ( DNS_Local_network_name[local_name_length] != '\0' ) ) { /* Domain Name characters can only be letters, hyphens, or numbers */ if ( (isalnum(DNS_Local_network_name[local_name_length]) || DNS_Local_network_name[local_name_length] == '-' ) && total_length < DNS_MAX_CHARS_IN_NAME && label_length <= DNS_MAX_LABEL_LENGTH ) { mqx_htonc((qname_buffer + total_length + 1), DNS_Local_network_name[local_name_length]); total_length++; local_name_length++; label_length++; } else { error = RTCSERR_DNS_INVALID_LOCAL_NAME; break; } /* Endif */ } /* Endwhile */ if ( error == RTCSERR_DNS_INVALID_LOCAL_NAME ) { break; }/* Endif */ mqx_htonc(label_length_ptr, label_length); label_length = 0; total_length++; label_length_ptr = qname_buffer + total_length; local_name_length++; } /* Endwhile */ if ( error == DNS_OK ) { /* ** Need to append '\0' to terminate domain name properly. ** This signifies the ROOT domain */ mqx_htonc(label_length_ptr, '\0'); }/* Endif */ return( error ); } /* Endbody */
bool IGMP_send_report ( ip_mreq *igrp, uint16_t type ) { /* Body */ IGMP_CFG_STRUCT_PTR IGMP_cfg_ptr = RTCS_getcfg(IGMP); uint32_t error; uint16_t checksum; RTCSPCB_PTR pcb; IGMP_HEADER_PTR header; IP_IF_PTR ipif; _ip_address ipdst; IF_IGMP_STATS_ENABLED(IGMP_cfg_ptr->STATS.COMMON.ST_TX_TOTAL++); /* never send a report for the local groups */ if (IN_LOCAL_MULTICAST(igrp->imr_multiaddr.s_addr)) { return TRUE; } /* Endif */ /* get the interface with its ip address */ ipif = IP_find_if(igrp->imr_interface.s_addr); if (ipif == NULL) { IF_IGMP_STATS_ENABLED(IGMP_cfg_ptr->STATS.COMMON.ST_TX_MISSED++); return FALSE; } /* Endif */ pcb = RTCSPCB_alloc_send(); if (pcb == NULL) { IF_IGMP_STATS_ENABLED(IGMP_cfg_ptr->STATS.COMMON.ST_TX_MISSED++); return FALSE; } /* Endif */ //RTCSLOG_PCB_ALLOC(pcb); error = RTCSPCB_insert_header(pcb, sizeof(IGMP_HEADER)); if (error) { RTCSLOG_PCB_FREE(pcb, error); RTCSPCB_free(pcb); IF_IGMP_STATS_ENABLED(IGMP_cfg_ptr->STATS.COMMON.ST_TX_MISSED++); return FALSE; } /* Endif */ RTCSLOG_PCB_WRITE(pcb, RTCS_LOGCTRL_PROTO(IPPROTO_IGMP), 1); #ifdef IGMP_V2 /* check if routers igmpv1 are present or not */ if (type == IGMPTYPE_V2_REPORT && ipif->IGMP_V1_ROUTER_FLAG) { uint32_t curTime = RTCS_time_get(); /* WORK: handle the overflow (see tcp seq) */ if (curTime < ipif->IGMP_V1_ROUTER_TIMEOUT) { type = IGMPTYPE_V1_REPORT; } else { /* if the timeout expired, clear the flag */ ipif->IGMP_V1_ROUTER_FLAG = 0; } /* Endif */ } /* Endif */ #endif /* IGMP_V2 */ /* build the igmp packet */ header = (IGMP_HEADER_PTR)RTCSPCB_DATA(pcb); mqx_htonc(header->TYPE, type); mqx_htonc(header->MAX_RESP_TIME, 0); mqx_htons(header->CHECKSUM, 0); mqx_htonl(header->GROUP_ADDRESS, igrp->imr_multiaddr.s_addr); checksum = _mem_sum_ip(0, sizeof(IGMP_HEADER), header); checksum = IP_Sum_invert(checksum); mqx_htons(header->CHECKSUM, checksum); /* WORK: for IGMP_V2, add a router alert option but currently ip layer doesnt support ip options */ /* send the igmp packet */ ipdst = igrp->imr_multiaddr.s_addr; #ifdef IGMP_V2 if (type == IGMPTYPE_LEAVE) { ipdst = INADDR_ALLROUTERS_GROUP; } /* Endif */ #endif IF_IGMP_STATS_ENABLED(IGMP_cfg_ptr->STATS.ST_TX_REPORT++); /* WORK: not always true for IGMP_V2 */ error = IP_send(pcb, IPPROTO_IGMP | IPTTL(1), igrp->imr_interface.s_addr, ipdst, RTCS_MSG_NOLOOP); return TRUE; } /* Endbody */
uint32_t ENET_send ( /* [IN] the Ethernet state structure */ _enet_handle handle, /* [IN] the packet to send */ PCB_PTR packet, /* [IN] the protocol */ uint16_t type, /* [IN] the destination Ethernet address */ _enet_address dest, /* [IN] optional flags, zero = default */ uint32_t flags ) { ENET_CONTEXT_STRUCT_PTR enet_ptr = (ENET_CONTEXT_STRUCT_PTR)handle; ENET_HEADER_PTR packet_ptr; unsigned char *type_ptr; PCB_FRAGMENT_PTR frag_ptr; uint32_t swhdr, size, frags; uint32_t error; _KLOGM(KERNEL_DATA_STRUCT_PTR kernel_data); _KLOGM(_GET_KERNEL_DATA(kernel_data)); _KLOGE6(KLOG_ENET_send, handle, packet, type, dest, flags); if (flags & ENET_OPT_8021QTAG) { swhdr = ENET_FRAMESIZE_HEAD_VLAN; } else { swhdr = ENET_FRAMESIZE_HEAD; } /* ** Make sure the first fragment is long enough for the Ethernet ** frame header. This isn't strictly necessary, but it's impractical ** to split a 14-26 byte header over multiple fragments. */ #if MQX_CHECK_ERRORS if (packet->FRAG[0].LENGTH < swhdr) { ENET_INC_STATS(COMMON.ST_TX_DISCARDED); error = ENETERR_SEND_SHORT; goto ERROR; } #endif /* ** Make sure that no fragment exceeds a maximum packet length. ** We check every fragment because we want to prevent something ** like FRAG[0].LENGTH = 2000, FRAG[1].LENGTH = -1000. This ** situation would not be detected if we only check the total ** length. */ size = frags = 0; for (frag_ptr = packet->FRAG; frag_ptr->LENGTH; frag_ptr++) { #if MQX_CHECK_ERRORS if (frag_ptr->LENGTH > enet_ptr->MaxTxFrameSize) { ENET_INC_STATS(COMMON.ST_TX_DISCARDED); error = ENETERR_SEND_LONG; goto ERROR; } #endif size += frag_ptr->LENGTH; frags++; } /* ** Make sure that the total sum of the fragments doesn't exceed ** a maximum packet length. */ #if MQX_CHECK_ERRORS if (size > enet_ptr->MaxTxFrameSize) { ENET_INC_STATS(COMMON.ST_TX_DISCARDED); error = ENETERR_SEND_LONG; goto ERROR; } #endif /* ** Everything checks out -- fill in the header. */ packet_ptr = (ENET_HEADER_PTR)packet->FRAG[0].FRAGMENT; htone(packet_ptr->DEST, dest); htone(packet_ptr->SOURCE, enet_ptr->ADDRESS); type_ptr = packet_ptr->TYPE; if (flags & ENET_OPT_8021QTAG) { ENET_8021QTAG_HEADER_PTR tag_ptr = (ENET_8021QTAG_HEADER_PTR)(type_ptr+2); uint16_t tag; tag = ENET_GETOPT_8021QPRIO(flags) << 13; mqx_htons(type_ptr, ENETPROT_8021Q); mqx_htons(tag_ptr->TAG, tag); type_ptr = tag_ptr->TYPE; } if (flags & ENET_OPT_8023) { ENET_8022_HEADER_PTR llc_ptr = (ENET_8022_HEADER_PTR)(type_ptr+2); (void)mqx_htons(type_ptr, size - swhdr); mqx_htonc(llc_ptr->DSAP, 0xAA); mqx_htonc(llc_ptr->SSAP, 0xAA); mqx_htonc(llc_ptr->COMMAND, 0x03); mqx_htonc(&llc_ptr->OUI[0], 0x00); mqx_htonc(&llc_ptr->OUI[1], 0x00); mqx_htonc(&llc_ptr->OUI[2], 0x00); type_ptr = llc_ptr->TYPE; } mqx_htons(type_ptr, type); /* ** This function can be called from any context, and it needs mutual ** exclusion with itself, and with ENET_ISR(). */ ENET_lock_context(enet_ptr); error = (*enet_ptr->PARAM_PTR->ENET_IF->MAC_IF->SEND)(handle, packet, size, frags, flags); ENET_unlock_context(enet_ptr); if (error) { ERROR: PCB_free(packet); } _KLOGX4(KLOG_ENET_send, handle, packet, error); return error; }
void ICMP_service ( RTCSPCB_PTR pcb, /* [IN/OUT] incoming packet */ void *dummy /* [IN] not used */ ) { /* Body */ ICMP_CFG_STRUCT_PTR ICMP_cfg_ptr; ICMP_HEADER_PTR packet; _ip_address source, dest; uint32_t error; uint16_t chksum; unsigned char type; #if BSPCFG_ENET_HW_TX_PROTOCOL_CHECKSUM _ip_address if_addr; IP_IF_PTR if_ptr; #endif ICMP_cfg_ptr = RTCS_getcfg(ICMP); IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.COMMON.ST_RX_TOTAL++); packet = (ICMP_HEADER_PTR)RTCSPCB_DATA(pcb); source = IP_source(pcb); dest = IP_dest(pcb); type = mqx_ntohc(packet->TYPE); /* ** Make sure that ** sizeof(ICMP_HEADER) <= RTCSPCB_SIZE(pcb) */ if (RTCSPCB_SIZE(pcb) < sizeof(ICMP_HEADER)) { IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.COMMON.ST_RX_DISCARDED++); IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.ST_RX_SMALL_DGRAM++); RTCSLOG_PCB_FREE(pcb, RTCSERR_ICMP_BAD_HEADER); RTCSPCB_free(pcb); return; } /* Endif */ #if BSPCFG_ENET_HW_RX_PROTOCOL_CHECKSUM /* HW-offload.*/ if( ((pcb->TYPE & RTCSPCB_TYPE_HW_PROTOCOL_CHECKSUM)==0) #if RTCSCFG_LINKOPT_8023 ||(pcb->LINK_OPTIONS.RX.OPT_8023 == 1) #endif ) #endif { /* Verify the checksum */ if (IP_Sum_PCB(0, pcb) != 0xFFFF) { IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.COMMON.ST_RX_DISCARDED++); IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.ST_RX_BAD_CHECKSUM++); RTCSLOG_PCB_FREE(pcb, RTCSERR_ICMP_BAD_CHECKSUM); RTCSPCB_free(pcb); return; } } RTCSLOG_PCB_READ(pcb, RTCS_LOGCTRL_PROTO(IPPROTO_ICMP), 0); switch (type) { case ICMPTYPE_REDIRECT: #if RTCSCFG_ENABLE_GATEWAYS { /* Scope */ _ip_address origdest, gateway; ICMP_ERR_HEADER_PTR rdpacket = (ICMP_ERR_HEADER_PTR)packet; IPIF_PARM parms; /* ** Make sure that ** sizeof(ICMP_ERR_HEADER) <= RTCSPCB_SIZE(pcb) */ if (RTCSPCB_SIZE(pcb) < sizeof(ICMP_ERR_HEADER)) { IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.COMMON.ST_RX_DISCARDED++); IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.ST_RX_SMALL_DGRAM++); RTCSLOG_PCB_FREE(pcb, RTCSERR_ICMP_BAD_HEADER); RTCSPCB_free(pcb); return; } /* Endif */ gateway = mqx_ntohl(rdpacket->DATA); origdest = mqx_ntohl(rdpacket->IP.DEST); /* If we receive a redirect to ourselves, silently discard it.*/ /* Ignore unasigned address.*/ if( IP_is_local(NULL, gateway) || (gateway == INADDR_ANY)) { IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.COMMON.ST_RX_DISCARDED++); } else if(IP_is_gate(source, origdest)) { parms.address = gateway; parms.network = origdest; parms.netmask = 0xFFFFFFFFL; parms.locmask = 0; RTCSCMD_internal(parms, IPIF_gate_add_redirect); } else { IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.COMMON.ST_RX_DISCARDED++); IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.ST_RX_RD_NOTGATE++); } /* Endif */ } /* Endscope */ #else IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.COMMON.ST_RX_DISCARDED++); #endif break; case ICMPTYPE_ECHO_REQ: /* RFC1122: An ICMP Echo Request destined to an IP broadcast or IP * multicast address MAY be silently discarded.*/ if((dest == INADDR_BROADCAST) || (IN_MULTICAST(dest) && (ip_if_is_joined(pcb->IFSRC, dest) == false)) ) { IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.COMMON.ST_RX_DISCARDED++); } else { error = RTCSPCB_next(pcb, sizeof(ICMP_HEADER)); if (error) { IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.COMMON.ST_RX_ERRORS++); IF_ICMP_STATS_ENABLED(RTCS_seterror(&ICMP_cfg_ptr->STATS.ERR_RX, error, (uint32_t)pcb)); RTCSLOG_PCB_FREE(pcb, error); RTCSPCB_free(pcb); return; } /* Endif */ /* ** RTCSPCB_fork() failing isn't a serious error, so we don't check ** the error code */ RTCSPCB_fork(pcb); IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.COMMON.ST_TX_TOTAL++); RTCSLOG_PCB_WRITE(pcb, RTCS_LOGCTRL_PROTO(IPPROTO_ICMP), 0); error = RTCSPCB_insert_header(pcb, sizeof(ICMP_HEADER)); if (error) { IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.ST_RX_ECHO_REQ++); IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.COMMON.ST_TX_MISSED++); IF_ICMP_STATS_ENABLED(RTCS_seterror(&ICMP_cfg_ptr->STATS.ERR_TX, error, (uint32_t)pcb)); RTCSLOG_PCB_FREE(pcb, error); RTCSPCB_free(pcb); return; } /* Change type from Echo to Echo Reply and recalculate checksum */ packet = (ICMP_HEADER_PTR)RTCSPCB_DATA(pcb); mqx_htonc(packet->TYPE, ICMPTYPE_ECHO_REPLY); mqx_htonc(packet->CODE, 0); mqx_htons(packet->CHECKSUM, 0); pcb->IP_SUM_PTR = NULL; #if BSPCFG_ENET_HW_TX_PROTOCOL_CHECKSUM /* HW-offload.*/ if_addr = IP_route_find(source /* Destination*/, 1); if_ptr = IP_find_if(if_addr); if( (if_ptr && (if_ptr->FEATURES & IP_IF_FEATURE_HW_TX_PROTOCOL_CHECKSUM) && (IP_will_fragment(if_ptr, RTCSPCB_SIZE(pcb)) == FALSE)) #if RTCSCFG_LINKOPT_8023 && (pcb->LINK_OPTIONS.TX.OPT_8023 == 0) #endif ) { pcb->TYPE |= RTCSPCB_TYPE_HW_PROTOCOL_CHECKSUM; } else #endif { chksum = IP_Sum_PCB(0, pcb); chksum = IP_Sum_invert(chksum); mqx_htons(packet->CHECKSUM, chksum); pcb->TYPE &= ~RTCSPCB_TYPE_HW_PROTOCOL_CHECKSUM; } if(IN_MULTICAST(dest) || IP_addr_is_broadcast(pcb, dest) ) { dest = IP_get_ipif_addr(pcb->IFSRC); } /* Send the Echo Reply whence came the Echo */ IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.ST_TX_ECHO_REPLY++); IP_send(pcb, IPPROTO_ICMP, dest /* Source*/, source /* Destination*/, 0); pcb = NULL; } break; case ICMPTYPE_ECHO_REPLY: { /* Scope */ ICMP_ECHO_HEADER_PTR echopacket = (ICMP_ECHO_HEADER_PTR)packet; ICMP_ECHO_PARAM_PTR parms; uint16_t id, seq; /* ** Make sure that ** sizeof(ICMP_ECHO_HEADER) <= RTCSPCB_SIZE(pcb) */ if (RTCSPCB_SIZE(pcb) < sizeof(ICMP_ECHO_HEADER)) { IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.COMMON.ST_RX_DISCARDED++); IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.ST_RX_SMALL_DGRAM++); RTCSLOG_PCB_FREE(pcb, RTCSERR_ICMP_BAD_HEADER); RTCSPCB_free(pcb); return; } /* Endif */ /* ** get the ID and Sequence number from the packet */ id = mqx_ntohs(echopacket->ID); seq = mqx_ntohs(echopacket->SEQ); /* ** Find a match for the ID and sequence number */ for (parms=ICMP_cfg_ptr->ECHO_PARAM_HEAD; parms; parms=parms->NEXT) { if ((parms->ping_param->id == id) && (parms->seq == seq)) { /* received reply for the ping request */ if (parms->NEXT) { parms->NEXT->PREV = parms->PREV; } *parms->PREV = parms->NEXT; TCPIP_Event_cancel(&parms->EXPIRE); /* Calculate round trip time */ parms->ping_param->round_trip_time = RTCS_timer_get_interval(parms->start_time, RTCS_time_get()); /* IP address of echo-reply message.*/ { IP_HEADER_PTR iphead = (IP_HEADER_PTR)RTCSPCB_DATA_NETWORK(pcb); memset(&parms->ping_param->addr, 0, sizeof(parms->ping_param->addr)); parms->ping_param->addr.sa_family = AF_INET; ((sockaddr_in*)(&parms->ping_param->addr))->sin_addr.s_addr = mqx_ntohl(iphead->SOURCE); } RTCSCMD_complete(parms, RTCS_OK); break; } /* Endif */ } /* Endfor */ } /* Endscope */ break; case ICMPTYPE_DESTUNREACH: case ICMPTYPE_TIMEEXCEED: { /* Scope */ IP_HEADER_PTR ip; ICMP_ERR_HEADER_PTR icmp_err = (ICMP_ERR_HEADER_PTR)packet; uint32_t len, remain; bool discard = TRUE; unsigned char code; /* ** Check if the attached IP header is IP over IP, and if so, strip IP ** headers until we find one whose source address is not local. Then we ** forward the ICMP error to that IP address */ remain = RTCSPCB_SIZE(pcb); /* Make sure we have at least a full IP header */ if (remain >= sizeof(ICMP_HEADER) + 4 + sizeof(IP_HEADER)) { ip = (IP_HEADER_PTR)((unsigned char *)packet + sizeof(ICMP_HEADER) + 4); remain -= sizeof(ICMP_HEADER) + 4; do { /* Make sure the IP header is IP over IP */ if (mqx_ntohc(ip->PROTOCOL) != IPPROTO_IPIP) { break; } /* Endif */ /* Make sure we have a full IP header + 8 bytes */ len = (mqx_ntohc(ip->VERSLEN) & 0x0F) << 2; if (remain < len + sizeof(IP_HEADER)) { break; } /* Endif */ /* Get next header */ ip = (IP_HEADER_PTR)((unsigned char *)(ip) + len); remain -= len; source = mqx_ntohl(ip->SOURCE); discard = IP_is_local(NULL, source); } while(discard); len = (mqx_ntohc(ip->VERSLEN) & 0x0F) << 2; /* ** discard is true if we are the originator of the IP packet ** in error, or if there was not enough information to find the ** originator. We make sure discard is false, and there is at ** least a full IP header + 8 bytes of data left */ if (!discard && (len + 8 <= remain)) { if (type == ICMPTYPE_DESTUNREACH) { code = mqx_ntohc(packet->CODE); switch (code) { case ICMPCODE_DU_PROTO_UNREACH: /* ** If we are sending back to the originator, and the ** originator did not use IP over IP, the protocol ** unreachable error is useless. */ code = ICMPCODE_DU_NET_UNREACH; break; case ICMPCODE_DU_PORT_UNREACH: /* It doesn't make sense to receive this */ discard = TRUE; break; case ICMPCODE_DU_SRCROUTE: discard = TRUE; break; } /* Endswitch */ } else { /* ** Type is ICMPTYPE_TIMEEXCEED ** ** Problem with routing loops within tunnel. Originator ** does not need to know about tunnel. */ type = ICMPTYPE_DESTUNREACH; code = ICMPCODE_DU_HOST_UNREACH; } /* Endif */ if (!discard) { ICMP_send_error_internal(type, code, mqx_ntohl(icmp_err->DATA), ip, NULL, remain); } /* Endif */ } /* Endif */ } /* Endif */ } /* Endscope */ break; } /* End Switch */ #if RTCSCFG_ENABLE_ICMP_STATS /* Update the statistics */ switch (type) { case ICMPTYPE_DESTUNREACH: ICMP_cfg_ptr->STATS.ST_RX_DESTUNREACH++; break; case ICMPTYPE_TIMEEXCEED: ICMP_cfg_ptr->STATS.ST_RX_TIMEEXCEED++; break; case ICMPTYPE_PARMPROB: ICMP_cfg_ptr->STATS.ST_RX_PARMPROB++; break; case ICMPTYPE_SRCQUENCH: ICMP_cfg_ptr->STATS.ST_RX_SRCQUENCH++; break; case ICMPTYPE_REDIRECT: ICMP_cfg_ptr->STATS.ST_RX_REDIRECT++; break; case ICMPTYPE_ECHO_REQ: ICMP_cfg_ptr->STATS.ST_RX_ECHO_REQ++; break; case ICMPTYPE_ECHO_REPLY: ICMP_cfg_ptr->STATS.ST_RX_ECHO_REPLY++; break; case ICMPTYPE_TIME_REQ: ICMP_cfg_ptr->STATS.ST_RX_TIME_REQ++; break; case ICMPTYPE_TIME_REPLY: ICMP_cfg_ptr->STATS.ST_RX_TIME_REPLY++; break; case ICMPTYPE_INFO_REQ: ICMP_cfg_ptr->STATS.ST_RX_INFO_REQ++; break; case ICMPTYPE_INFO_REPLY: ICMP_cfg_ptr->STATS.ST_RX_INFO_REPLY++; break; default: ICMP_cfg_ptr->STATS.ST_RX_OTHER++; ICMP_cfg_ptr->STATS.COMMON.ST_RX_DISCARDED++; break; } /* Endswitch */ #endif if (pcb) { RTCSLOG_PCB_FREE(pcb, RTCS_OK); RTCSPCB_free(pcb); } /* Endif */ } /* Endbody */
void ICMP_send_error_internal ( uint8_t type, /* [IN] the type to send */ uint8_t code, /* [IN] the code to send */ uint32_t param, /* [IN] a parameter */ IP_HEADER_PTR iph, /* [IN] the IP header */ RTCSPCB_PTR origpcb, /* [IN] pcb with bad packet */ uint32_t maxlen /* [IN] the max data len to send, 0 = default */ ) { /* Body */ ICMP_CFG_STRUCT_PTR ICMP_cfg_ptr = RTCS_getcfg(ICMP); RTCSPCB_PTR pcb; ICMP_ERR_HEADER_PTR icmph; _ip_address ipsrc = mqx_ntohl(iph->SOURCE); _ip_address ipdst = mqx_ntohl(iph->DEST); uint16_t iphdrlen = (mqx_ntohc(iph->VERSLEN) & 0x0F) << 2; uint16_t ippktlen = mqx_ntohs(iph->LENGTH) - iphdrlen; uint16_t checksum; _ip_address icmpsrc = IP_is_local(NULL,ipdst) ? ipdst : INADDR_ANY; uint32_t error; unsigned char *buffer; uint32_t temp; #if RTCSCFG_ENABLE_NAT TCP_HEADER_PTR tcp_hdr; UDP_HEADER_PTR udp_hdr; IP_HEADER_PTR ip_hdr; uint32_t protocol; uint16_t src_port, dest_port; uint32_t (_CODE_PTR_ *nat_exec)(RTCSPCB_PTR *); #endif #if BSPCFG_ENET_HW_TX_PROTOCOL_CHECKSUM _ip_address if_addr; IP_IF_PTR if_ptr; #endif /* ** Only include up to a maximum of maxlen bytes of data from the ** original IP datagram */ if (!maxlen) { maxlen = IP_DEFAULT_MTU - sizeof(IP_HEADER) - sizeof(ICMP_HEADER) - 4; } /* Endif */ if (origpcb) { temp = RTCSPCB_DATA(origpcb) - RTCSPCB_DATA_NETWORK(origpcb); if (maxlen > origpcb->HEADER_FRAG_USED + temp) { maxlen = origpcb->HEADER_FRAG_USED + temp; } /* Endif */ } /* Endif */ if (ippktlen + iphdrlen > maxlen) { ippktlen = maxlen - iphdrlen; } /* Endif */ /* Don't send an error in response to an ICMP error */ if (mqx_ntohc(iph->PROTOCOL) == IPPROTO_ICMP) { /* Make sure the packet has at least a 'TYPE' field */ if (ippktlen == 0) { return; } /* Endif */ icmph = (ICMP_ERR_HEADER_PTR)((unsigned char *)iph + iphdrlen); if (!ICMPTYPE_ISQUERY(mqx_ntohc(icmph->HEAD.TYPE))) { return; } /* Endif */ } /* Endif */ IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.COMMON.ST_TX_TOTAL++); /* Allocate a PCB */ pcb = RTCSPCB_alloc_send(); if (pcb == NULL) { IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.COMMON.ST_TX_MISSED++); return; } /* Endif */ //RTCSLOG_PCB_ALLOC(pcb); if (origpcb) { /* Add a dependency and a pointer to the ICMP data */ RTCSPCB_depend(pcb, origpcb); error = RTCSPCB_append_fragment(pcb, iphdrlen + ippktlen, (unsigned char *)iph); } else { /* Reserve space for the ICMP data */ buffer = RTCS_mem_alloc_system(iphdrlen + ippktlen); if (!buffer) { IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.COMMON.ST_TX_MISSED++); IF_ICMP_STATS_ENABLED(RTCS_seterror(&ICMP_cfg_ptr->STATS.ERR_TX, RTCSERR_OUT_OF_MEMORY, (uint32_t)pcb)); RTCSLOG_PCB_FREE(pcb, RTCSERR_OUT_OF_MEMORY); RTCSPCB_free(pcb); return; } /* Endif */ _mem_set_type(buffer, MEM_TYPE_ICMP_DATA); _mem_copy(iph, buffer, iphdrlen + ippktlen); error = RTCSPCB_append_fragment_autofree(pcb, iphdrlen + ippktlen, buffer); if (error) { _mem_free(buffer); } /* Endif */ } /* Endif */ if (!error) { error = RTCSPCB_insert_header(pcb, sizeof(ICMP_HEADER) + 4); } /* Endif */ if (error) { IF_ICMP_STATS_ENABLED(ICMP_cfg_ptr->STATS.COMMON.ST_TX_MISSED++); IF_ICMP_STATS_ENABLED(RTCS_seterror(&ICMP_cfg_ptr->STATS.ERR_TX, error, (uint32_t)pcb)); RTCSLOG_PCB_FREE(pcb, error); RTCSPCB_free(pcb); return; } /* Endif */ RTCSLOG_PCB_WRITE(pcb, RTCS_LOGCTRL_PROTO(IPPROTO_ICMP), 0); /* Build the header */ icmph = (ICMP_ERR_HEADER_PTR)RTCSPCB_DATA(pcb); mqx_htonc(icmph->HEAD.TYPE, type); mqx_htonc(icmph->HEAD.CODE, code); mqx_htons(icmph->HEAD.CHECKSUM, 0); mqx_htonl(icmph->DATA, param); #if BSPCFG_ENET_HW_TX_PROTOCOL_CHECKSUM /* HW-offload.*/ if_addr = IP_route_find(ipsrc /* Destination*/, 1); if_ptr = IP_find_if(if_addr); if( (if_ptr && (if_ptr->FEATURES & IP_IF_FEATURE_HW_TX_PROTOCOL_CHECKSUM) && (IP_will_fragment(if_ptr, RTCSPCB_SIZE(pcb)) == FALSE)) #if RTCSCFG_LINKOPT_8023 && (pcb->LINK_OPTIONS.TX.OPT_8023 == 0) #endif ) { pcb->TYPE |= RTCSPCB_TYPE_HW_PROTOCOL_CHECKSUM; } else #endif { checksum = IP_Sum_PCB (0, pcb); checksum = IP_Sum_invert(checksum); mqx_htons(icmph->HEAD.CHECKSUM, checksum); pcb->TYPE &= ~RTCSPCB_TYPE_HW_PROTOCOL_CHECKSUM; } #if RTCSCFG_ENABLE_ICMP_STATS /* Update the statistics */ switch (type) { case ICMPTYPE_DESTUNREACH: ICMP_cfg_ptr->STATS.ST_TX_DESTUNREACH++; break; case ICMPTYPE_TIMEEXCEED: ICMP_cfg_ptr->STATS.ST_TX_TIMEEXCEED++; break; case ICMPTYPE_PARMPROB: ICMP_cfg_ptr->STATS.ST_TX_PARMPROB++; break; case ICMPTYPE_SRCQUENCH: ICMP_cfg_ptr->STATS.ST_TX_SRCQUENCH++; break; case ICMPTYPE_REDIRECT: ICMP_cfg_ptr->STATS.ST_TX_REDIRECT++; break; case ICMPTYPE_ECHO_REQ: ICMP_cfg_ptr->STATS.ST_TX_ECHO_REQ++; break; case ICMPTYPE_ECHO_REPLY: ICMP_cfg_ptr->STATS.ST_TX_ECHO_REPLY++; break; case ICMPTYPE_TIME_REQ: ICMP_cfg_ptr->STATS.ST_TX_TIME_REQ++; break; case ICMPTYPE_TIME_REPLY: ICMP_cfg_ptr->STATS.ST_TX_TIME_REPLY++; break; case ICMPTYPE_INFO_REQ: ICMP_cfg_ptr->STATS.ST_TX_INFO_REQ++; break; case ICMPTYPE_INFO_REPLY: ICMP_cfg_ptr->STATS.ST_TX_INFO_REPLY++; break; default: ICMP_cfg_ptr->STATS.ST_TX_OTHER++; break; } /* Endswitch */ #endif #if RTCSCFG_ENABLE_NAT /* Reverse NAT (if it is installed) on the origpcb, otherwise the icmp error will not get sent to the original src */ nat_exec = RTCS_getcfg(NAT); if (origpcb && nat_exec && *nat_exec) { // swap src and dst IPs and ports so NAT_apply // will process the pcb ip_hdr = (IP_HEADER_PTR)RTCSPCB_DATA(origpcb); protocol = mqx_ntohc(ip_hdr->PROTOCOL); // Swap ports if it is udp or tcp if ((protocol == IPPROTO_TCP) || (protocol == IPPROTO_UDP)) { switch(protocol) { case IPPROTO_TCP: tcp_hdr = (TCP_HEADER_PTR)((unsigned char *)ip_hdr + IPH_LEN(ip_hdr)); dest_port = mqx_ntohs(tcp_hdr->dest_port); src_port = mqx_ntohs(tcp_hdr->source_port); mqx_htons(tcp_hdr->dest_port, src_port); mqx_htons(tcp_hdr->source_port, dest_port); break; case IPPROTO_UDP: udp_hdr = (UDP_HEADER_PTR)((unsigned char *)ip_hdr + IPH_LEN(ip_hdr)); dest_port = mqx_ntohs(udp_hdr->DEST_PORT); src_port = mqx_ntohs(udp_hdr->SRC_PORT); mqx_htons(udp_hdr->DEST_PORT, src_port); mqx_htons(udp_hdr->SRC_PORT, dest_port); break; default: // should not get here break; } } // swap IPs ipsrc = mqx_ntohl(ip_hdr->SOURCE); ipdst = mqx_ntohl(ip_hdr->DEST); mqx_htonl(ip_hdr->SOURCE, ipdst); mqx_htonl(ip_hdr->DEST,ipsrc); // call NAT error = (*nat_exec)(&origpcb); if (!error) { // swap IPs and ports back ip_hdr = (IP_HEADER_PTR)RTCSPCB_DATA(origpcb); protocol = mqx_ntohc(ip_hdr->PROTOCOL); // swap ports if it is udp or tcp if ((protocol == IPPROTO_TCP) || (protocol == IPPROTO_UDP)) { switch(protocol) { case IPPROTO_TCP: tcp_hdr = (TCP_HEADER_PTR)((unsigned char *)ip_hdr + IPH_LEN(ip_hdr)); dest_port = mqx_ntohs(tcp_hdr->dest_port); src_port = mqx_ntohs(tcp_hdr->source_port); mqx_htons(tcp_hdr->dest_port, src_port); mqx_htons(tcp_hdr->source_port, dest_port); break; case IPPROTO_UDP: udp_hdr = (UDP_HEADER_PTR)((unsigned char *)ip_hdr + IPH_LEN(ip_hdr)); dest_port = mqx_ntohs(udp_hdr->DEST_PORT); src_port = mqx_ntohs(udp_hdr->SRC_PORT); mqx_htons(udp_hdr->DEST_PORT, src_port); mqx_htons(udp_hdr->SRC_PORT, dest_port); break; default: // should not get here break; } } // swap IPs ipsrc = mqx_ntohl(ip_hdr->SOURCE); ipdst = mqx_ntohl(ip_hdr->DEST); mqx_htonl(ip_hdr->SOURCE, ipdst); mqx_htonl(ip_hdr->DEST,ipsrc); // Recalculate the cksum mqx_htons(icmph->HEAD.CHECKSUM, 0); checksum = IP_Sum_PCB (0, pcb); checksum = IP_Sum_invert(checksum); mqx_htons(icmph->HEAD.CHECKSUM, checksum); // recalculate icmpsrc, and use new ipsrc. ipdst = mqx_ntohl(ip_hdr->DEST); ipsrc = mqx_ntohl(ip_hdr->SOURCE); icmpsrc = IP_is_local(NULL,ipdst) ? ipdst : INADDR_ANY; } } #endif /* Send it */ IP_send(pcb, IPPROTO_ICMP, icmpsrc, ipsrc, 0); } /* Endbody */
static bool LCP_recvextcode ( PPPFSM_CFG_PTR fsm /* [IN] - State Machine */ ) { /* Body */ PPP_CFG_PTR ppp_ptr = fsm->HANDLE; LCP_CFG_PTR lcp_ptr = fsm->PRIVATE; PPP_CALL_INTERNAL_PTR call_ptr = &ppp_ptr->LCP_CALL[PPP_CALL_ECHO_REPLY]; switch (fsm->CODE) { case LCP_CODE_PROT_REJ: lcp_ptr->ST_LCP_RX_REJECT++; /* ** We should notify the rejected protocol, but there ** currently isn't any way to do this. What we'll do ** instead is to send a STOP message to the Tx task on ** behalf of the protocol. ** ** This will usually be sufficient, since the rejected ** protocol isn't likely to send another packet until ** either it receives a packet (in which case it's OK to ** reply) or the retransmission timer kicks in (which ** we're about to disable). ** ** Thus, this will effectively stop the rejected protocol. */ if (fsm->LENGTH >= 2) { uint16_t protocol = mqx_ntohs(fsm->DATA); PPP_send_stop(ppp_ptr, protocol); } /* Endif */ PCB_free(fsm->PACKET); break; case LCP_CODE_ECHO_REQ: lcp_ptr->ST_LCP_RX_ECHO++; if (fsm->STATE < PPP_STATE_OPENED) { PCB_free(fsm->PACKET); } else { mqx_htonc(fsm->DATA - CP_HDR_LEN, LCP_CODE_ECHO_REP); mqx_htonl(fsm->DATA, 0); /* Set magic field to 0 */ lcp_ptr->ST_LCP_TX_REPLY++; PPP_send_one(ppp_ptr, PPP_PROT_LCP, fsm->PACKET); } /* Endif */ break; case LCP_CODE_ECHO_REP: lcp_ptr->ST_LCP_RX_REPLY++; if (call_ptr->CALLBACK) { call_ptr->CALLBACK(call_ptr->PARAM, fsm->ID, fsm->PACKET); } /* Endif */ PCB_free(fsm->PACKET); break; case LCP_CODE_DISC_REQ: lcp_ptr->ST_LCP_RX_DISCARD++; PCB_free(fsm->PACKET); break; default: return FALSE; } /* Endswitch */ return TRUE; } /* Endbody */
uint32_t DNS_is_dotted_domain_name ( unsigned char *domain_name, unsigned char *qname_buffer ) { /* Body */ uint32_t total_length = 0; uint32_t error; unsigned char *label_length_ptr; unsigned char label_length = 0; if ( domain_name[total_length] == '\0' ) { return( RTCSERR_DNS_INVALID_NAME ); }/* Endif */ /* If the request is for the ROOT Domain Name */ if ( ( domain_name[total_length] == '.' ) && ( domain_name[total_length + 1] == '\0' )) { mqx_htonc(qname_buffer, '\0'); return( DNS_OK ); }/* Endif */ label_length_ptr = qname_buffer; error = DNS_OK; while ( domain_name[total_length] != '\0' ) { /* ** RFC 1035 says labels must start with a letter, but in practice ** some aren't */ if ( isalnum(domain_name[total_length]) ) { mqx_htonc((qname_buffer + total_length + 1), domain_name[total_length]); total_length++; label_length++; } else { error = RTCSERR_DNS_INVALID_NAME; break; } /* Endif */ while ( ( domain_name[total_length] != '.') && ( domain_name[total_length] != '\0' ) ) { /* Domain Name characters can only be letters, hyphens, or numbers */ if ( (isalnum(domain_name[total_length]) || domain_name[total_length] == '-' ) && total_length < DNS_MAX_CHARS_IN_NAME && label_length <= DNS_MAX_LABEL_LENGTH ) { mqx_htonc((qname_buffer + total_length + 1), domain_name[total_length]); total_length++; label_length++; } else { error = RTCSERR_DNS_INVALID_NAME; break; } /* Endif */ } /* Endwhile */ if ( error == RTCSERR_DNS_INVALID_NAME ) { break; }/* Endif */ mqx_htonc(label_length_ptr, label_length); label_length = 0; if ( domain_name[total_length] != '\0' ) { label_length_ptr = qname_buffer + total_length + 1; } else { /* It's NULL, append the local network name */ error = DNS_append_local_name( qname_buffer, total_length + 1 ); return( error ); } /* Endif */ total_length++; } /* Endwhile */ if ( error == DNS_OK ) { /* ** Need to append '\0' to terminate domain name properly. ** This denotes the ROOT domain */ mqx_htonc(label_length_ptr, '\0'); }/* Endif */ return( error ); } /* Endbody */
uint32_t DNS_is_dotted_IP_addr ( unsigned char *name, unsigned char *fill_buffer_ptr ) { /* Body */ uint32_t i; uint32_t j = 0; uint32_t k; uint32_t size = 0; uint32_t digit_count = 0; uint32_t dot_count = 0; int32_t byte_num; uint32_t addr_number = 0; unsigned char number_chars[4]; unsigned char actual_number; unsigned char addr[4][3]; unsigned char *number_buffer_ptr; unsigned char appended_name[12] = {"in-addr.arpa"}; bool leading_zero; /* ** first check to see if name is written in correct dotted decimal ** IP address format */ for (i=0; name[i] != '\0'; ++i ) { if ( name[i] == '.' ) { dot_count++; if ( dot_count > 3 ) { /* invalid IP address */ return( RTCSERR_DNS_INVALID_IP_ADDR ); }/* Endif */ if ( digit_count == 0 ) { /* there are no digits before the '.' */ return( RTCSERR_DNS_INVALID_IP_ADDR ); }/* Endif */ byte_num = byte_num / 10; /* shift back */ if ( (byte_num < 0 ) || (byte_num > 255) ) { /* if the number does fall within this range it's invalid */ return( RTCSERR_DNS_INVALID_IP_ADDR ); } else { addr_number++; number_chars[j] = digit_count; j++; digit_count = 0; } /* Endif */ } else { /* a digit */ if ( digit_count == 0 ) { byte_num = 0; }/* Endif */ ++digit_count; if ( digit_count > 3 ) { /* too many digits between the '.' */ return( RTCSERR_DNS_INVALID_IP_ADDR ); }/* Endif */ if ( isdigit(name[i]) ) { /* number is in range */ addr[addr_number][digit_count - 1] = name[i]; byte_num = byte_num + name[i] - '0'; byte_num = byte_num * 10; } else { /* if the characters are not decimal digits it's invalid */ return( RTCSERR_DNS_INVALID_IP_ADDR ); }/* Endif */ }/* Endif */ } /* Endfor */ if ( digit_count == 0 ) { /* there are no digits after the last '.' */ return( RTCSERR_DNS_INVALID_IP_ADDR ); } /* Endif */ byte_num = byte_num / 10; if ( (byte_num < 0 ) || (byte_num > 255) ) { /* if the number does fall within this range it's invalid */ return( RTCSERR_DNS_INVALID_IP_ADDR ); } else { number_chars[j] = digit_count; } /* Endif */ if ( dot_count != 3 ) { /* the wrong number of dots were found */ return( RTCSERR_DNS_INVALID_IP_ADDR ); }/* Endif */ /* ** If we got this far, it's a legal IP addr, reverse the numbers, ** in the fill_buffer and append "in-addr.arpa" to it. */ for ( i = 0; i < 4; i++) { leading_zero = FALSE; number_buffer_ptr = fill_buffer_ptr; actual_number = number_chars[j]; mqx_htonc(fill_buffer_ptr, number_chars[j]); fill_buffer_ptr++; size++; for ( k = 0; k < number_chars[j]; k++ ) { if ( addr[addr_number][k] == '0' ) { if ( addr[addr_number][k] == '0' && k == 0 ) { leading_zero = TRUE; actual_number--; continue; } /* Endif */ if ( addr[addr_number][k] == '0' && k == 1 && leading_zero == TRUE && k < number_chars[j] ) { actual_number--; continue; } /* Endif */ if ( addr[addr_number][k] == '0' && k == 1 && leading_zero == TRUE && k == number_chars[j] ) { mqx_htonc(fill_buffer_ptr, addr[addr_number][k]); fill_buffer_ptr++; mqx_htonc(number_buffer_ptr, actual_number); number_buffer_ptr++; size++; break; }/* Endif */ } /* Endif */ mqx_htonc(fill_buffer_ptr, addr[addr_number][k]); fill_buffer_ptr++; size++; } /* Endfor */ addr_number--; j--; } /* Endfor */ mqx_htonc(fill_buffer_ptr, 7); fill_buffer_ptr++; for ( i = 0; i < 7; i++) { mqx_htonc(fill_buffer_ptr, appended_name[i]); fill_buffer_ptr++; } /* Endfor */ mqx_htonc(fill_buffer_ptr, 4); fill_buffer_ptr++; i++; for ( ; i < 12; i++) { mqx_htonc(fill_buffer_ptr, appended_name[i]); fill_buffer_ptr++; } /* Endfor */ /* ** Need to append '\0' to terminate a domain name properly. ** This signifies the ROOT domain */ mqx_htonc(fill_buffer_ptr, '\0'); return( DNS_OK ); } /* Endbody */
static uint32_t LCP_buildconfreq ( PPPFSM_CFG_PTR fsm, /* [IN] - State Machine */ unsigned char *outp, /* [IN] - free packet */ uint32_t sizeleft /* [IN] - size of packet */ ) { /* Body */ LCP_CFG_PTR lcp_ptr = fsm->PRIVATE; uint32_t totlen = 0; uint32_t aplen; #define LCP_BREQ(ci,len) \ *outp++ = LCP_CI_ ## ci; \ *outp++ = len; \ totlen += len /* ** Generate configuration information for each option ** we want to negotiate. */ if (lcp_ptr->RECV_NEG.NEG_MRU) { if (sizeleft >= totlen+4) { LCP_BREQ(MRU,4); mqx_htons(outp, lcp_ptr->RECV_NEG.MRU); outp += 2; } /* Endif */ } /* Endif */ if (lcp_ptr->RECV_NEG.NEG_ACCM) { if (sizeleft >= totlen+6) { LCP_BREQ(ACCM,6); mqx_htonl(outp, lcp_ptr->RECV_NEG.ACCM); outp += 4; } /* Endif */ } /* Endif */ if (lcp_ptr->RECV_NEG.NEG_AP) { switch (lcp_ptr->RECV_NEG.AP) { case PPP_PROT_CHAP: aplen = 5; break; default: aplen = 4; break; } /* Endswitch */ if (sizeleft >= totlen+aplen) { LCP_BREQ(AP,aplen); mqx_htons(outp, lcp_ptr->RECV_NEG.AP); outp += 2; switch (lcp_ptr->RECV_NEG.AP) { case PPP_PROT_CHAP: mqx_htonc(outp, 5); outp++; /* Only MD5 supported */ break; } /* Endswitch */ } /* Endif */ } /* Endif */ if (lcp_ptr->RECV_NEG.NEG_PFC) { if (sizeleft >= totlen+2) { LCP_BREQ(PFC,2); } /* Endif */ } /* Endif */ if (lcp_ptr->RECV_NEG.NEG_ACFC) { if (sizeleft >= totlen+2) { LCP_BREQ(ACFC,2); } /* Endif */ } /* Endif */ return totlen; } /* Endbody */