X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/316670eb35587141e969394ae8537d66b9211e80..39236c6e673c41db228275375ab7fdb0f837b292:/osfmk/kdp/kdp_udp.c diff --git a/osfmk/kdp/kdp_udp.c b/osfmk/kdp/kdp_udp.c index 4415e10f6..e51c48286 100644 --- a/osfmk/kdp/kdp_udp.c +++ b/osfmk/kdp/kdp_udp.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2008 Apple Inc. All rights reserved. + * Copyright (c) 2000-2013 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * @@ -71,6 +71,10 @@ #include #include +extern int inet_aton(const char *, struct kdp_in_addr *); /* in libkern */ +extern char *inet_ntoa_r(struct kdp_in_addr ina, char *buf, + size_t buflen); /* in libkern */ + #define DO_ALIGN 1 /* align all packet data accesses */ #define KDP_SERIAL_IPADDR 0xABADBABE /* IP address used for serial KDP */ #define LINK_UP_STATUS (IFM_AVALID | IFM_ACTIVE) @@ -93,9 +97,124 @@ static u_short ip_id; /* ip packet ctr, for ids */ * Per RFC 768, August, 1980. */ #define UDP_TTL 60 /* deflt time to live for UDP packets */ -int udp_ttl = UDP_TTL; +static int udp_ttl = UDP_TTL; static unsigned char exception_seq; +struct kdp_ipovly { + uint32_t ih_next, ih_prev; /* for protocol sequence q's */ + u_char ih_x1; /* (unused) */ + u_char ih_pr; /* protocol */ + short ih_len; /* protocol length */ + struct kdp_in_addr ih_src; /* source internet address */ + struct kdp_in_addr ih_dst; /* destination internet address */ +}; + +struct kdp_udphdr { + u_short uh_sport; /* source port */ + u_short uh_dport; /* destination port */ + short uh_ulen; /* udp length */ + u_short uh_sum; /* udp checksum */ +}; + +struct kdp_udpiphdr { + struct kdp_ipovly ui_i; /* overlaid ip structure */ + struct kdp_udphdr ui_u; /* udp header */ +}; +#define ui_next ui_i.ih_next +#define ui_prev ui_i.ih_prev +#define ui_x1 ui_i.ih_x1 +#define ui_pr ui_i.ih_pr +#define ui_len ui_i.ih_len +#define ui_src ui_i.ih_src +#define ui_dst ui_i.ih_dst +#define ui_sport ui_u.uh_sport +#define ui_dport ui_u.uh_dport +#define ui_ulen ui_u.uh_ulen +#define ui_sum ui_u.uh_sum + +struct kdp_ip { + union { + uint32_t ip_w; + struct { + unsigned int +#ifdef __LITTLE_ENDIAN__ + ip_xhl:4, /* header length */ + ip_xv:4, /* version */ + ip_xtos:8, /* type of service */ + ip_xlen:16; /* total length */ +#endif +#ifdef __BIG_ENDIAN__ + ip_xv:4, /* version */ + ip_xhl:4, /* header length */ + ip_xtos:8, /* type of service */ + ip_xlen:16; /* total length */ +#endif + } ip_x; + } ip_vhltl; + u_short ip_id; /* identification */ + short ip_off; /* fragment offset field */ +#define IP_DF 0x4000 /* dont fragment flag */ +#define IP_MF 0x2000 /* more fragments flag */ +#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ + u_char ip_ttl; /* time to live */ + u_char ip_p; /* protocol */ + u_short ip_sum; /* checksum */ + struct kdp_in_addr ip_src,ip_dst; /* source and dest address */ +}; +#define ip_v ip_vhltl.ip_x.ip_xv +#define ip_hl ip_vhltl.ip_x.ip_xhl +#define ip_tos ip_vhltl.ip_x.ip_xtos +#define ip_len ip_vhltl.ip_x.ip_xlen + +#define IPPROTO_UDP 17 +#define IPVERSION 4 + +#define ETHERTYPE_IP 0x0800 /* IP protocol */ + +/* + * Ethernet Address Resolution Protocol. + * + * See RFC 826 for protocol description. Structure below is adapted + * to resolving internet addresses. Field names used correspond to + * RFC 826. + */ + +#define ETHERTYPE_ARP 0x0806 /* Addr. resolution protocol */ + +struct kdp_arphdr { + u_short ar_hrd; /* format of hardware address */ +#define ARPHRD_ETHER 1 /* ethernet hardware format */ +#define ARPHRD_FRELAY 15 /* frame relay hardware format */ + u_short ar_pro; /* format of protocol address */ + u_char ar_hln; /* length of hardware address */ + u_char ar_pln; /* length of protocol address */ + u_short ar_op; /* one of: */ +#define ARPOP_REQUEST 1 /* request to resolve address */ +#define ARPOP_REPLY 2 /* response to previous request */ +#define ARPOP_REVREQUEST 3 /* request protocol address given hardware */ +#define ARPOP_REVREPLY 4 /* response giving protocol address */ +#define ARPOP_INVREQUEST 8 /* request to identify peer */ +#define ARPOP_INVREPLY 9 /* response identifying peer */ +}; + +struct kdp_ether_arp { + struct kdp_arphdr ea_hdr; /* fixed-size header */ + u_char arp_sha[ETHER_ADDR_LEN]; /* sender hardware address */ + u_char arp_spa[4]; /* sender protocol address */ + u_char arp_tha[ETHER_ADDR_LEN]; /* target hardware address */ + u_char arp_tpa[4]; /* target protocol address */ +}; +#define arp_hrd ea_hdr.ar_hrd +#define arp_pro ea_hdr.ar_pro +#define arp_hln ea_hdr.ar_hln +#define arp_pln ea_hdr.ar_pln +#define arp_op ea_hdr.ar_op + +#define ETHERMTU 1500 +#define ETHERHDRSIZE 14 +#define ETHERCRC 4 +#define KDP_MAXPACKET (ETHERHDRSIZE + ETHERMTU + ETHERCRC) + static struct { unsigned char data[KDP_MAXPACKET]; unsigned int off, len; @@ -106,12 +225,12 @@ struct kdp_manual_pkt manual_pkt; struct { struct { - struct in_addr in; - struct ether_addr ea; + struct kdp_in_addr in; + struct kdp_ether_addr ea; } loc; struct { - struct in_addr in; - struct ether_addr ea; + struct kdp_in_addr in; + struct kdp_ether_addr ea; } rmt; } adr; @@ -141,7 +260,7 @@ static void kdp_serial_send(void *rpkt, unsigned int rpkt_len); #endif static uint32_t kdp_current_ip_address = 0; -static struct ether_addr kdp_current_mac_address = {{0, 0, 0, 0, 0, 0}}; +static struct kdp_ether_addr kdp_current_mac_address = {{0, 0, 0, 0, 0, 0}}; static void *kdp_current_ifp; static void kdp_handler( void *); @@ -158,12 +277,12 @@ static boolean_t router_specified = FALSE; static boolean_t corename_specified = FALSE; static unsigned int panicd_port = CORE_REMOTE_PORT; -static struct ether_addr etherbroadcastaddr = {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}; +static struct kdp_ether_addr etherbroadcastaddr = {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}; -static struct ether_addr router_mac = {{0, 0, 0 , 0, 0, 0}}; -static struct ether_addr destination_mac = {{0, 0, 0 , 0, 0, 0}}; -static struct ether_addr temp_mac = {{0, 0, 0 , 0, 0, 0}}; -static struct ether_addr current_resolved_MAC = {{0, 0, 0 , 0, 0, 0}}; +static struct kdp_ether_addr router_mac = {{0, 0, 0 , 0, 0, 0}}; +static struct kdp_ether_addr destination_mac = {{0, 0, 0 , 0, 0, 0}}; +static struct kdp_ether_addr temp_mac = {{0, 0, 0 , 0, 0, 0}}; +static struct kdp_ether_addr current_resolved_MAC = {{0, 0, 0 , 0, 0, 0}}; static boolean_t flag_panic_dump_in_progress = FALSE; static boolean_t flag_router_mac_initialized = FALSE; @@ -177,7 +296,7 @@ static unsigned int last_panic_port = CORE_REMOTE_PORT; #define KDP_THROTTLE_VALUE (10ULL * NSEC_PER_SEC) uint32_t kdp_crashdump_pkt_size = 512; -#define KDP_LARGE_CRASHDUMP_PKT_SIZE (1440 - 6 - sizeof(struct udpiphdr)) +#define KDP_LARGE_CRASHDUMP_PKT_SIZE (1440 - 6 - sizeof(struct kdp_udpiphdr)) static char panicd_ip_str[20]; static char router_ip_str[20]; static char corename_str[50]; @@ -194,18 +313,15 @@ extern void kdp_call(void); extern boolean_t kdp_call_kdb(void); extern int kern_dump(void); -extern int inet_aton(const char *cp, struct in_addr *pin); -extern int inet_ntoa2(struct in_addr * pin, char * cp, const int len); - void * kdp_get_interface(void); void kdp_set_gateway_mac(void *gatewaymac); -void kdp_set_ip_and_mac_addresses(struct in_addr *ipaddr, struct ether_addr *); -void kdp_set_interface(void *interface, const struct ether_addr *macaddr); +void kdp_set_ip_and_mac_addresses(struct kdp_in_addr *ipaddr, struct kdp_ether_addr *); +void kdp_set_interface(void *interface, const struct kdp_ether_addr *macaddr); void kdp_disable_arp(void); -static void kdp_arp_reply(struct ether_arp *); -static void kdp_process_arp_reply(struct ether_arp *); -static boolean_t kdp_arp_resolve(uint32_t, struct ether_addr *); +static void kdp_arp_reply(struct kdp_ether_arp *); +static void kdp_process_arp_reply(struct kdp_ether_arp *); +static boolean_t kdp_arp_resolve(uint32_t, struct kdp_ether_addr *); static volatile unsigned kdp_reentry_deadline; @@ -437,7 +553,7 @@ enaddr_copy( void *dst ) { - bcopy((char *)src, (char *)dst, sizeof (struct ether_addr)); + bcopy((char *)src, (char *)dst, sizeof (struct kdp_ether_addr)); } static unsigned short @@ -468,26 +584,26 @@ kdp_reply( const boolean_t sideband ) { - struct udpiphdr aligned_ui, *ui = &aligned_ui; - struct ip aligned_ip, *ip = &aligned_ip; - struct in_addr tmp_ipaddr; - struct ether_addr tmp_enaddr; - struct ether_header *eh = NULL; + struct kdp_udpiphdr aligned_ui, *ui = &aligned_ui; + struct kdp_ip aligned_ip, *ip = &aligned_ip; + struct kdp_in_addr tmp_ipaddr; + struct kdp_ether_addr tmp_enaddr; + struct kdp_ether_header *eh = NULL; if (!pkt.input) kdp_panic("kdp_reply"); - pkt.off -= (unsigned int)sizeof (struct udpiphdr); + pkt.off -= (unsigned int)sizeof (struct kdp_udpiphdr); #if DO_ALIGN bcopy((char *)&pkt.data[pkt.off], (char *)ui, sizeof(*ui)); #else - ui = (struct udpiphdr *)&pkt.data[pkt.off]; + ui = (struct kdp_udpiphdr *)&pkt.data[pkt.off]; #endif ui->ui_next = ui->ui_prev = 0; ui->ui_x1 = 0; ui->ui_pr = IPPROTO_UDP; - ui->ui_len = htons((u_short)pkt.len + sizeof (struct udphdr)); + ui->ui_len = htons((u_short)pkt.len + sizeof (struct kdp_udphdr)); tmp_ipaddr = ui->ui_src; ui->ui_src = ui->ui_dst; ui->ui_dst = tmp_ipaddr; @@ -499,12 +615,12 @@ kdp_reply( bcopy((char *)ui, (char *)&pkt.data[pkt.off], sizeof(*ui)); bcopy((char *)&pkt.data[pkt.off], (char *)ip, sizeof(*ip)); #else - ip = (struct ip *)&pkt.data[pkt.off]; + ip = (struct kdp_ip *)&pkt.data[pkt.off]; #endif - ip->ip_len = htons(sizeof (struct udpiphdr) + pkt.len); + ip->ip_len = htons(sizeof (struct kdp_udpiphdr) + pkt.len); ip->ip_v = IPVERSION; ip->ip_id = htons(ip_id++); - ip->ip_hl = sizeof (struct ip) >> 2; + ip->ip_hl = sizeof (struct kdp_ip) >> 2; ip->ip_ttl = udp_ttl; ip->ip_sum = 0; ip->ip_sum = htons(~ip_sum((unsigned char *)ip, ip->ip_hl)); @@ -512,17 +628,17 @@ kdp_reply( bcopy((char *)ip, (char *)&pkt.data[pkt.off], sizeof(*ip)); #endif - pkt.len += (unsigned int)sizeof (struct udpiphdr); + pkt.len += (unsigned int)sizeof (struct kdp_udpiphdr); - pkt.off -= (unsigned int)sizeof (struct ether_header); + pkt.off -= (unsigned int)sizeof (struct kdp_ether_header); - eh = (struct ether_header *)&pkt.data[pkt.off]; + eh = (struct kdp_ether_header *)&pkt.data[pkt.off]; enaddr_copy(eh->ether_shost, &tmp_enaddr); enaddr_copy(eh->ether_dhost, eh->ether_shost); enaddr_copy(&tmp_enaddr, eh->ether_dhost); eh->ether_type = htons(ETHERTYPE_IP); - pkt.len += (unsigned int)sizeof (struct ether_header); + pkt.len += (unsigned int)sizeof (struct kdp_ether_header); // save reply for possible retransmission assert(pkt.len <= KDP_MAXPACKET); @@ -541,24 +657,24 @@ kdp_send( unsigned short remote_port ) { - struct udpiphdr aligned_ui, *ui = &aligned_ui; - struct ip aligned_ip, *ip = &aligned_ip; - struct ether_header *eh; + struct kdp_udpiphdr aligned_ui, *ui = &aligned_ui; + struct kdp_ip aligned_ip, *ip = &aligned_ip; + struct kdp_ether_header *eh; if (pkt.input) kdp_panic("kdp_send"); - pkt.off -= (unsigned int)sizeof (struct udpiphdr); + pkt.off -= (unsigned int)sizeof (struct kdp_udpiphdr); #if DO_ALIGN bcopy((char *)&pkt.data[pkt.off], (char *)ui, sizeof(*ui)); #else - ui = (struct udpiphdr *)&pkt.data[pkt.off]; + ui = (struct kdp_udpiphdr *)&pkt.data[pkt.off]; #endif ui->ui_next = ui->ui_prev = 0; ui->ui_x1 = 0; ui->ui_pr = IPPROTO_UDP; - ui->ui_len = htons((u_short)pkt.len + sizeof (struct udphdr)); + ui->ui_len = htons((u_short)pkt.len + sizeof (struct kdp_udphdr)); ui->ui_src = adr.loc.in; ui->ui_dst = adr.rmt.in; ui->ui_sport = htons(KDP_REMOTE_PORT); @@ -569,12 +685,12 @@ kdp_send( bcopy((char *)ui, (char *)&pkt.data[pkt.off], sizeof(*ui)); bcopy((char *)&pkt.data[pkt.off], (char *)ip, sizeof(*ip)); #else - ip = (struct ip *)&pkt.data[pkt.off]; + ip = (struct kdp_ip *)&pkt.data[pkt.off]; #endif - ip->ip_len = htons(sizeof (struct udpiphdr) + pkt.len); + ip->ip_len = htons(sizeof (struct kdp_udpiphdr) + pkt.len); ip->ip_v = IPVERSION; ip->ip_id = htons(ip_id++); - ip->ip_hl = sizeof (struct ip) >> 2; + ip->ip_hl = sizeof (struct kdp_ip) >> 2; ip->ip_ttl = udp_ttl; ip->ip_sum = 0; ip->ip_sum = htons(~ip_sum((unsigned char *)ip, ip->ip_hl)); @@ -582,16 +698,16 @@ kdp_send( bcopy((char *)ip, (char *)&pkt.data[pkt.off], sizeof(*ip)); #endif - pkt.len += (unsigned int)sizeof (struct udpiphdr); + pkt.len += (unsigned int)sizeof (struct kdp_udpiphdr); - pkt.off -= (unsigned int)sizeof (struct ether_header); + pkt.off -= (unsigned int)sizeof (struct kdp_ether_header); - eh = (struct ether_header *)&pkt.data[pkt.off]; + eh = (struct kdp_ether_header *)&pkt.data[pkt.off]; enaddr_copy(&adr.loc.ea, eh->ether_shost); enaddr_copy(&adr.rmt.ea, eh->ether_dhost); eh->ether_type = htons(ETHERTYPE_IP); - pkt.len += (unsigned int)sizeof (struct ether_header); + pkt.len += (unsigned int)sizeof (struct kdp_ether_header); kdp_send_data(&pkt.data[pkt.off], pkt.len); } @@ -612,10 +728,10 @@ inline static void debugger_if_necessary(void) when the interface gets initialized for real. */ void -kdp_set_interface(void *ifp, const struct ether_addr *macaddr) +kdp_set_interface(void *ifp, const struct kdp_ether_addr *macaddr) { char kdpstr[80]; - struct in_addr addr = { 0 }; + struct kdp_in_addr addr = { 0 }; unsigned int len; kdp_current_ifp = ifp; @@ -662,8 +778,8 @@ kdp_get_interface(void) void kdp_set_ip_and_mac_addresses( - struct in_addr *ipaddr, - struct ether_addr *macaddr) + struct kdp_in_addr *ipaddr, + struct kdp_ether_addr *macaddr) { static uint64_t last_time = (uint64_t) -1; static uint64_t throttle_val = 0; @@ -683,7 +799,7 @@ kdp_set_ip_and_mac_addresses( if (save_ip_in_nvram == FALSE) goto done; - if (inet_ntoa2(ipaddr, addr, sizeof(addr)) == FALSE) + if (inet_ntoa_r(*ipaddr, addr, sizeof(addr)) == NULL) goto done; /* throttle writes if needed */ @@ -705,11 +821,11 @@ done: void kdp_set_gateway_mac(void *gatewaymac) { - router_mac = *(struct ether_addr *)gatewaymac; + router_mac = *(struct kdp_ether_addr *)gatewaymac; flag_router_mac_initialized = TRUE; } -struct ether_addr +struct kdp_ether_addr kdp_get_mac_addr(void) { return kdp_current_mac_address; @@ -730,10 +846,10 @@ kdp_disable_arp(void) static void kdp_arp_dispatch(void) { - struct ether_arp aligned_ea, *ea = &aligned_ea; + struct kdp_ether_arp aligned_ea, *ea = &aligned_ea; unsigned arp_header_offset; - arp_header_offset = (unsigned)sizeof(struct ether_header) + pkt.off; + arp_header_offset = (unsigned)sizeof(struct kdp_ether_header) + pkt.off; memcpy((void *)ea, (void *)&pkt.data[arp_header_offset], sizeof(*ea)); switch(ntohs(ea->arp_op)) { @@ -749,18 +865,18 @@ kdp_arp_dispatch(void) } static void -kdp_process_arp_reply(struct ether_arp *ea) +kdp_process_arp_reply(struct kdp_ether_arp *ea) { /* Are we interested in ARP replies? */ if (flag_arp_resolved == TRUE) return; /* Did we receive a reply from the right source? */ - if (((struct in_addr *)(ea->arp_spa))->s_addr != target_ip) + if (((struct kdp_in_addr *)(ea->arp_spa))->s_addr != target_ip) return; flag_arp_resolved = TRUE; - current_resolved_MAC = *(struct ether_addr *) (ea->arp_sha); + current_resolved_MAC = *(struct kdp_ether_addr *) (ea->arp_sha); return; } @@ -770,15 +886,15 @@ kdp_process_arp_reply(struct ether_arp *ea) */ static void -kdp_arp_reply(struct ether_arp *ea) +kdp_arp_reply(struct kdp_ether_arp *ea) { - struct ether_header *eh; + struct kdp_ether_header *eh; - struct in_addr isaddr, itaddr, myaddr; - struct ether_addr my_enaddr; + struct kdp_in_addr isaddr, itaddr, myaddr; + struct kdp_ether_addr my_enaddr; - eh = (struct ether_header *)&pkt.data[pkt.off]; - pkt.off += (unsigned int)sizeof(struct ether_header); + eh = (struct kdp_ether_header *)&pkt.data[pkt.off]; + pkt.off += (unsigned int)sizeof(struct kdp_ether_header); if(ntohs(ea->arp_op) != ARPOP_REQUEST) return; @@ -812,7 +928,7 @@ kdp_arp_reply(struct ether_arp *ea) (void)memcpy(eh->ether_shost, &my_enaddr, sizeof(eh->ether_shost)); eh->ether_type = htons(ETHERTYPE_ARP); (void)memcpy(&pkt.data[pkt.off], ea, sizeof(*ea)); - pkt.off -= (unsigned int)sizeof (struct ether_header); + pkt.off -= (unsigned int)sizeof (struct kdp_ether_header); /* pkt.len is still the length we want, ether_header+ether_arp */ kdp_send_data(&pkt.data[pkt.off], pkt.len); } @@ -821,9 +937,9 @@ kdp_arp_reply(struct ether_arp *ea) static void kdp_poll(void) { - struct ether_header *eh = NULL; - struct udpiphdr aligned_ui, *ui = &aligned_ui; - struct ip aligned_ip, *ip = &aligned_ip; + struct kdp_ether_header *eh = NULL; + struct kdp_udpiphdr aligned_ui, *ui = &aligned_ui; + struct kdp_ip aligned_ip, *ip = &aligned_ip; static int msg_printed; if (pkt.input) @@ -843,9 +959,9 @@ kdp_poll(void) if (pkt.len == 0) return; - if (pkt.len >= sizeof(struct ether_header)) + if (pkt.len >= sizeof(struct kdp_ether_header)) { - eh = (struct ether_header *)&pkt.data[pkt.off]; + eh = (struct kdp_ether_header *)&pkt.data[pkt.off]; if (kdp_flag & KDP_ARP) { @@ -857,10 +973,10 @@ kdp_poll(void) } } - if (pkt.len < (sizeof (struct ether_header) + sizeof (struct udpiphdr))) + if (pkt.len < (sizeof (struct kdp_ether_header) + sizeof (struct kdp_udpiphdr))) return; - pkt.off += (unsigned int)sizeof (struct ether_header); + pkt.off += (unsigned int)sizeof (struct kdp_ether_header); if (ntohs(eh->ether_type) != ETHERTYPE_IP) { return; } @@ -869,16 +985,16 @@ kdp_poll(void) bcopy((char *)&pkt.data[pkt.off], (char *)ui, sizeof(*ui)); bcopy((char *)&pkt.data[pkt.off], (char *)ip, sizeof(*ip)); #else - ui = (struct udpiphdr *)&pkt.data[pkt.off]; - ip = (struct ip *)&pkt.data[pkt.off]; + ui = (struct kdp_udpiphdr *)&pkt.data[pkt.off]; + ip = (struct kdp_ip *)&pkt.data[pkt.off]; #endif - pkt.off += (unsigned int)sizeof (struct udpiphdr); + pkt.off += (unsigned int)sizeof (struct kdp_udpiphdr); if (ui->ui_pr != IPPROTO_UDP) { return; } - if (ip->ip_hl > (sizeof (struct ip) >> 2)) { + if (ip->ip_hl > (sizeof (struct kdp_ip) >> 2)) { return; } @@ -914,7 +1030,7 @@ kdp_poll(void) /* * Calculate kdp packet length. */ - pkt.len = ntohs((u_short)ui->ui_ulen) - (unsigned int)sizeof (struct udphdr); + pkt.len = ntohs((u_short)ui->ui_ulen) - (unsigned int)sizeof (struct kdp_udphdr); pkt.input = TRUE; } @@ -925,8 +1041,8 @@ kdp_poll(void) static void transmit_ARP_request(uint32_t ip_addr) { - struct ether_header *eh = (struct ether_header *) &pkt.data[0]; - struct ether_arp *ea = (struct ether_arp *) &pkt.data[sizeof(struct ether_header)]; + struct kdp_ether_header *eh = (struct kdp_ether_header *) &pkt.data[0]; + struct kdp_ether_arp *ea = (struct kdp_ether_arp *) &pkt.data[sizeof(struct kdp_ether_header)]; KDP_DEBUG("Transmitting ARP request\n"); /* Populate the ether_header */ @@ -950,13 +1066,13 @@ transmit_ARP_request(uint32_t ip_addr) memcpy(ea->arp_spa, (void *) &kdp_current_ip_address, sizeof(kdp_current_ip_address)); pkt.off = 0; - pkt.len = sizeof(struct ether_header) + sizeof(struct ether_arp); + pkt.len = sizeof(struct kdp_ether_header) + sizeof(struct kdp_ether_arp); /* Transmit */ kdp_send_data(&pkt.data[pkt.off], pkt.len); } static boolean_t -kdp_arp_resolve(uint32_t arp_target_ip, struct ether_addr *resolved_MAC) +kdp_arp_resolve(uint32_t arp_target_ip, struct kdp_ether_addr *resolved_MAC) { int poll_count = 256; /* ~770 ms modulo broadcast/delayed traffic? */ char tretries = 0; @@ -1094,7 +1210,7 @@ static void kdp_connection_wait(void) { unsigned short reply_port; - struct ether_addr kdp_mac_addr = kdp_get_mac_addr(); + struct kdp_ether_addr kdp_mac_addr = kdp_get_mac_addr(); unsigned int ip_addr = ntohl(kdp_get_ip_address()); /* @@ -1216,7 +1332,7 @@ kdp_send_exception( unsigned int poll_timeout; do { - pkt.off = sizeof (struct ether_header) + sizeof (struct udpiphdr); + pkt.off = sizeof (struct kdp_ether_header) + sizeof (struct kdp_udpiphdr); kdp_exception((unsigned char *)&pkt.data[pkt.off], (int *)&pkt.len, (unsigned short *)&remote_port, @@ -1404,28 +1520,28 @@ struct corehdr * create_panic_header(unsigned int request, const char *corename, unsigned length, unsigned int block) { - struct udpiphdr aligned_ui, *ui = &aligned_ui; - struct ip aligned_ip, *ip = &aligned_ip; - struct ether_header *eh; + struct kdp_udpiphdr aligned_ui, *ui = &aligned_ui; + struct kdp_ip aligned_ip, *ip = &aligned_ip; + struct kdp_ether_header *eh; struct corehdr *coreh; const char *mode = "octet"; char modelen = strlen(mode) + 1; size_t fmask_size = sizeof(KDP_FEATURE_MASK_STRING) + sizeof(kdp_crashdump_feature_mask); - pkt.off = sizeof (struct ether_header); + pkt.off = sizeof (struct kdp_ether_header); pkt.len = (unsigned int)(length + ((request == KDP_WRQ) ? modelen + fmask_size : 0) + (corename ? (strlen(corename) + 1 ): 0) + sizeof(struct corehdr)); #if DO_ALIGN bcopy((char *)&pkt.data[pkt.off], (char *)ui, sizeof(*ui)); #else - ui = (struct udpiphdr *)&pkt.data[pkt.off]; + ui = (struct kdp_udpiphdr *)&pkt.data[pkt.off]; #endif ui->ui_next = ui->ui_prev = 0; ui->ui_x1 = 0; ui->ui_pr = IPPROTO_UDP; - ui->ui_len = htons((u_short)pkt.len + sizeof (struct udphdr)); + ui->ui_len = htons((u_short)pkt.len + sizeof (struct kdp_udphdr)); ui->ui_src.s_addr = (uint32_t)kdp_current_ip_address; /* Already in network byte order via inet_aton() */ ui->ui_dst.s_addr = panic_server_ip; @@ -1437,12 +1553,12 @@ create_panic_header(unsigned int request, const char *corename, bcopy((char *)ui, (char *)&pkt.data[pkt.off], sizeof(*ui)); bcopy((char *)&pkt.data[pkt.off], (char *)ip, sizeof(*ip)); #else - ip = (struct ip *)&pkt.data[pkt.off]; + ip = (struct kdp_ip *)&pkt.data[pkt.off]; #endif - ip->ip_len = htons(sizeof (struct udpiphdr) + pkt.len); + ip->ip_len = htons(sizeof (struct kdp_udpiphdr) + pkt.len); ip->ip_v = IPVERSION; ip->ip_id = htons(ip_id++); - ip->ip_hl = sizeof (struct ip) >> 2; + ip->ip_hl = sizeof (struct kdp_ip) >> 2; ip->ip_ttl = udp_ttl; ip->ip_sum = 0; ip->ip_sum = htons(~ip_sum((unsigned char *)ip, ip->ip_hl)); @@ -1450,9 +1566,9 @@ create_panic_header(unsigned int request, const char *corename, bcopy((char *)ip, (char *)&pkt.data[pkt.off], sizeof(*ip)); #endif - pkt.len += (unsigned int)sizeof (struct udpiphdr); + pkt.len += (unsigned int)sizeof (struct kdp_udpiphdr); - pkt.off += (unsigned int)sizeof (struct udpiphdr); + pkt.off += (unsigned int)sizeof (struct kdp_udpiphdr); coreh = (struct corehdr *) &pkt.data[pkt.off]; coreh->th_opcode = htons((u_short)request); @@ -1479,15 +1595,15 @@ create_panic_header(unsigned int request, const char *corename, coreh->th_block = htonl((unsigned int) block); } - pkt.off -= (unsigned int)sizeof (struct udpiphdr); - pkt.off -= (unsigned int)sizeof (struct ether_header); + pkt.off -= (unsigned int)sizeof (struct kdp_udpiphdr); + pkt.off -= (unsigned int)sizeof (struct kdp_ether_header); - eh = (struct ether_header *)&pkt.data[pkt.off]; + eh = (struct kdp_ether_header *)&pkt.data[pkt.off]; enaddr_copy(&kdp_current_mac_address, eh->ether_shost); enaddr_copy(&destination_mac, eh->ether_dhost); eh->ether_type = htons(ETHERTYPE_IP); - pkt.len += (unsigned int)sizeof (struct ether_header); + pkt.len += (unsigned int)sizeof (struct kdp_ether_header); return coreh; } @@ -1690,27 +1806,6 @@ isdigit (char c) { return ((c > 47) && (c < 58)); } -/* From user mode Libc - this ought to be in a library */ -static char * -strnstr(char *s, const char *find, size_t slen) -{ - char c, sc; - size_t len; - - if ((c = *find++) != '\0') { - len = strlen(find); - do { - do { - if ((sc = *s++) == '\0' || slen-- < 1) - return (NULL); - } while (sc != c); - if (len > slen) - return (NULL); - } while (strncmp(s, find, len) != 0); - s--; - } - return (s); -} /* Horrid hack to extract xnu version if possible - a much cleaner approach * would be to have the integrator run a script which would copy the @@ -1918,7 +2013,7 @@ kdp_panic_dump(void) (unsigned int) (abstime & 0xffffffff)); } - if (0 == inet_aton(panicd_ip_str, (struct in_addr *) &panic_server_ip)) { + if (0 == inet_aton(panicd_ip_str, (struct kdp_in_addr *) &panic_server_ip)) { kdb_printf("inet_aton() failed interpreting %s as a panic server IP\n", panicd_ip_str); } else @@ -1933,7 +2028,7 @@ kdp_panic_dump(void) else { if (!flag_panic_dump_in_progress) goto panic_dump_exit; if (router_specified) { - if (0 == inet_aton(router_ip_str, (struct in_addr *) &parsed_router_ip)) + if (0 == inet_aton(router_ip_str, (struct kdp_in_addr *) &parsed_router_ip)) kdb_printf("inet_aton() failed interpreting %s as an IP\n", router_ip_str); else { router_ip = parsed_router_ip; @@ -2098,19 +2193,19 @@ kdp_init(void) strlcpy(kdp_kernelversion_string, version, sizeof(kdp_kernelversion_string)); /* Relies on platform layer calling panic_init() before kdp_init() */ - if (kernel_uuid[0] != '\0') { + if (kernel_uuid_string[0] != '\0') { /* * Update kdp_kernelversion_string with our UUID * generated at link time. */ strlcat(kdp_kernelversion_string, "; UUID=", sizeof(kdp_kernelversion_string)); - strlcat(kdp_kernelversion_string, kernel_uuid, sizeof(kdp_kernelversion_string)); + strlcat(kdp_kernelversion_string, kernel_uuid_string, sizeof(kdp_kernelversion_string)); } -#if defined(__x86_64__) || defined(__arm__) debug_log_init(); +#if defined(__x86_64__) || defined(__arm__) if (vm_kernel_slide) { char KASLR_stext[19]; strlcat(kdp_kernelversion_string, "; stext=", sizeof(kdp_kernelversion_string)); @@ -2130,19 +2225,13 @@ kdp_init(void) #if CONFIG_SERIAL_KDP char kdpname[80]; - struct in_addr ipaddr; - struct ether_addr macaddr; + struct kdp_in_addr ipaddr; + struct kdp_ether_addr macaddr; -#if CONFIG_EMBEDDED - //serial will be the debugger, unless match name is explicitly provided, and it's not "serial" - if(PE_parse_boot_argn("kdp_match_name", kdpname, sizeof(kdpname)) && strncmp(kdpname, "serial", sizeof(kdpname)) != 0) - return; -#else // serial must be explicitly requested if(!PE_parse_boot_argn("kdp_match_name", kdpname, sizeof(kdpname)) || strncmp(kdpname, "serial", sizeof(kdpname)) != 0) return; -#endif kprintf("Initializing serial KDP\n");