Changeset 15768 in vbox
- Timestamp:
- Dec 29, 2008 8:16:06 AM (16 years ago)
- Location:
- trunk/src/VBox/Devices/Network/slirp
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/slirp/if.c
r15765 r15768 225 225 226 226 /* Encapsulate the packet for sending */ 227 if_encap(pData, (const uint8_t *)ifm->m_data, ifm->m_len);227 if_encap(pData, ETH_P_IP, (const uint8_t *)ifm->m_data, ifm->m_len); 228 228 229 229 m_free(pData, ifm); -
trunk/src/VBox/Devices/Network/slirp/if.h
r14964 r15768 30 30 #define ifs_init(ifm) ((ifm)->ifs_next = (ifm)->ifs_prev = (ifm)) 31 31 32 #ifdef ETH_P_ARP 33 # undef ETH_P_ARP 34 #endif /* ETH_P_ARP*/ 35 #define ETH_P_ARP 0x0806 /* Address Resolution packet */ 36 37 #ifdef ETH_P_IP 38 # undef ETH_P_IP 39 #endif /* ETH_P_IP */ 40 #define ETH_P_IP 0x0800 /* Internet Protocol packet */ 41 32 42 #endif -
trunk/src/VBox/Devices/Network/slirp/main.h
r14964 r15768 10 10 #endif 11 11 12 void if_encap(PNATState pData, const uint8_t *ip_data, int ip_data_len);12 void if_encap(PNATState pData, uint16_t eth_proto, const uint8_t *ip_data, int ip_data_len); -
trunk/src/VBox/Devices/Network/slirp/slirp.c
r15765 r15768 932 932 #define ETH_HLEN 14 933 933 934 #define ETH_P_IP 0x0800 /* Internet Protocol packet */935 #define ETH_P_ARP 0x0806 /* Address Resolution packet */936 937 934 #define ARPOP_REQUEST 1 /* ARP request */ 938 935 #define ARPOP_REPLY 2 /* ARP reply */ … … 963 960 964 961 static 965 void arp_input(PNATState pData, const uint8_t *pkt, int pkt_len) 966 { 967 struct ethhdr *eh = (struct ethhdr *)pkt; 968 struct arphdr *ah = (struct arphdr *)(pkt + ETH_HLEN); 969 #ifdef VBOX_WITH_SIMPLIFIED_SLIRP_SYNC 970 size_t arp_reply_size = ETH_HLEN + sizeof(struct arphdr); 971 uint8_t *arp_reply = malloc(arp_reply_size); /*XXX: temporal solution, here should be mbuf used*/ 972 #else 973 uint8_t arp_reply[ETH_HLEN + sizeof(struct arphdr)]; 974 #endif 975 struct ethhdr *reh = (struct ethhdr *)arp_reply; 976 struct arphdr *rah = (struct arphdr *)(arp_reply + ETH_HLEN); 962 void arp_input(PNATState pData, struct mbuf *m) 963 { 964 struct ethhdr *eh = mtod(m, struct ethhdr *); 965 struct arphdr *ah = (struct arphdr *)&eh[1]; 966 uint8_t arp_reply[sizeof(struct arphdr)]; 967 struct arphdr *rah; 977 968 int ar_op; 978 969 struct ex_list *ex_ptr; 979 970 uint32_t htip = ntohl(*(uint32_t*)ah->ar_tip); 971 972 rah = (struct arphdr *)arp_reply; 980 973 981 974 ar_op = ntohs(ah->ar_op); … … 995 988 return; 996 989 arp_ok: 997 /* XXX: make an ARP request to have the client address */998 memcpy(client_ethaddr, eh->h_source, ETH_ALEN);999 1000 /* ARP request for alias/dns mac address */1001 memcpy(reh->h_dest, pkt + ETH_ALEN, ETH_ALEN);1002 memcpy(reh->h_source, special_ethaddr, ETH_ALEN - 1);1003 reh->h_source[5] = ah->ar_tip[3];1004 reh->h_proto = htons(ETH_P_ARP);1005 990 1006 991 rah->ar_hrd = htons(1); … … 1009 994 rah->ar_pln = 4; 1010 995 rah->ar_op = htons(ARPOP_REPLY); 1011 memcpy(rah->ar_sha, reh->h_source, ETH_ALEN); 996 memcpy(rah->ar_sha, special_ethaddr, ETH_ALEN); 997 switch (htip & ~pData->netmask) 998 { 999 case CTL_DNS: 1000 case CTL_ALIAS: 1001 rah->ar_sha[5] = (uint8_t)(htip & ~pData->netmask); 1002 break; 1003 default:; 1004 } 1005 1012 1006 memcpy(rah->ar_sip, ah->ar_tip, 4); 1013 1007 memcpy(rah->ar_tha, ah->ar_sha, ETH_ALEN); 1014 1008 memcpy(rah->ar_tip, ah->ar_sip, 4); 1015 1009 #ifdef VBOX_WITH_SIMPLIFIED_SLIRP_SYNC 1016 slirp_output(pData->pvUser, arp_reply, arp_reply_size); 1010 if_encap(pData, ETH_P_ARP, arp_reply, sizeof(struct arphdr)); 1011 m_free(pData, m); 1017 1012 #else 1018 1013 slirp_output(pData->pvUser, arp_reply, sizeof(arp_reply)); … … 1030 1025 int proto; 1031 1026 1032 if (pkt_len < ETH_HLEN) 1027 if (pkt_len < ETH_HLEN) 1028 { 1029 LogRel(("packet having size %d has been ingnored\n", pkt_len)); 1033 1030 return; 1031 } 1032 1033 m = m_get(pData); 1034 if (m == NULL) 1035 { 1036 LogRel(("can't allocate new mbuf\n")); 1037 } 1038 /* Note: we add to align the IP header */ 1039 1040 #if 0 1041 m->m_data += 2 + ETH_HLEN; 1042 m->m_len -= 2 + ETH_HLEN; 1043 #endif 1034 1044 1035 1045 proto = ntohs(*(uint16_t *)(pkt + 12)); … … 1037 1047 { 1038 1048 case ETH_P_ARP: 1039 arp_input(pData, pkt, pkt_len); 1049 memcpy(m->m_data, pkt, pkt_len); 1050 m->m_len = pkt_len; 1051 arp_input(pData, m); 1040 1052 break; 1041 1053 case ETH_P_IP: … … 1043 1055 * the first outgoing connection gets an incorrect timestamp. */ 1044 1056 updtime(pData); 1045 1046 m = m_get(pData);1047 if (!m)1048 return;1049 /* Note: we add to align the IP header */1050 1057 if (M_FREEROOM(m) < pkt_len + 2) 1051 1058 { 1052 1059 m_inc(m, pkt_len + 2); 1053 1060 } 1054 1061 m->m_len = pkt_len + 2; 1055 1062 memcpy(m->m_data + 2, pkt, pkt_len); 1056 1057 1063 m->m_data += 2 + ETH_HLEN; 1058 1064 m->m_len -= 2 + ETH_HLEN; 1059 1060 1065 ip_input(pData, m); 1061 1066 break; … … 1066 1071 1067 1072 /* output the IP packet to the ethernet device */ 1068 void if_encap(PNATState pData, const uint8_t *ip_data, int ip_data_len)1073 void if_encap(PNATState pData, uint16_t eth_proto, const uint8_t *ip_data, int ip_data_len) 1069 1074 { 1070 1075 #ifdef VBOX_WITH_SIMPLIFIED_SLIRP_SYNC … … 1087 1092 /* XXX: not correct */ 1088 1093 eh->h_source[5] = CTL_ALIAS; 1089 eh->h_proto = htons( ETH_P_IP);1094 eh->h_proto = htons(eth_proto); 1090 1095 memcpy(buf + sizeof(struct ethhdr), ip_data, ip_data_len); 1091 1096 slirp_output(pData->pvUser, buf, ip_data_len + ETH_HLEN);
Note:
See TracChangeset
for help on using the changeset viewer.