enum {
IP_NOHEADERS = 1 << 0,
IP_MCAST = 1 << 1,
+ IP_NOADDRESS = 1 << 2,
};
struct split_ip_msg {
enum {
/* how many timer tics to stay in TIME_WAIT */
- TCPLIB_TIMEWAIT_LEN = 12,
+ TCPLIB_TIMEWAIT_LEN = 1,
/* how many un-acked retransmissions before we give up the connection */
TCPLIB_GIVEUP = 6,
};
msg.headers = NULL;
msg.data = payload;
msg.data_len = len;
- if (iph->ip6_src.s6_addr[0] == 0xfe) {
- call IPAddress.getLLAddr(&msg.hdr.ip6_src);
- } else {
- call IPAddress.getIPAddr(&msg.hdr.ip6_src);
- }
+
memcpy(&msg.hdr.ip6_dst, &iph->ip6_src, 16);
+ call IPAddress.setSource(&msg.hdr);
req->type = ICMP_TYPE_ECHO_REPLY;
req->code = 0;
return globalPrefix;
}
+ command void IPAddress.setSource(struct ip6_hdr *hdr) {
+ enum { LOCAL, GLOBAL } type = GLOBAL;
+
+ if (hdr->ip6_dst.s6_addr[0] == 0xff) {
+ // link-local multicast sent from local address
+ if ((hdr->ip6_dst.s6_addr[1] & 0x0f) <= 0x2) {
+ type = LOCAL;
+ }
+ } else if (hdr->ip6_dst.s6_addr[0] == 0xfe) {
+ // link-local destinations sent from link-local
+ if ((hdr->ip6_dst.s6_addr[1] & 0xf0) <= 0x80) {
+ type = LOCAL;
+ }
+ }
+
+ if (type == GLOBAL && call IPAddress.haveAddress()) {
+ call IPAddress.getIPAddr(&hdr->ip6_src);
+ } else {
+ call IPAddress.getLLAddr(&hdr->ip6_src);
+ }
+
+ }
+
+
#ifndef SIM
async event void ActiveMessageAddress.changed() {
#include "circ.c"
#include "tcplib.c"
- void setSrcAddr(struct split_ip_msg *msg) {
- if (msg->hdr.ip6_dst.s6_addr16[0] == htons(0xff02) ||
- msg->hdr.ip6_dst.s6_addr16[0] == htons(0xfe80)) {
- call IPAddress.getLLAddr(&msg->hdr.ip6_src);
- } else {
- call IPAddress.getIPAddr(&msg->hdr.ip6_src);
- }
- }
-
struct tcplib_sock socks[uniqueCount("TCP_CLIENT")];
struct tcplib_sock *tcplib_accept(struct tcplib_sock *conn,
void tcplib_send_out(struct split_ip_msg *msg, struct tcp_hdr *tcph) {
printfUART("tcp output\n");
- setSrcAddr(msg);
+ call IPAddress.setSource(&msg->hdr);
tcph->chksum = htons(msg_cksum(msg, IANA_TCP));
call IP.send(msg);
}
return SUCCESS;
}
- void setSrcAddr(struct split_ip_msg *msg) {
- if (msg->hdr.ip6_dst.s6_addr16[7] == htons(0xff02) ||
- msg->hdr.ip6_dst.s6_addr16[7] == htons(0xfe80)) {
- call IPAddress.getLLAddr(&msg->hdr.ip6_src);
- } else {
- call IPAddress.getIPAddr(&msg->hdr.ip6_src);
- }
- }
-
-
command error_t UDP.bind[uint8_t clnt](uint16_t port) {
int i;
port = htons(port);
ip_memclr((uint8_t *)msg, sizeof(struct split_ip_msg));
ip_memclr((uint8_t *)udp, sizeof(struct udp_hdr));
- setSrcAddr(msg);
+ call IPAddress.setSource(&msg->hdr);
memcpy(&msg->hdr.ip6_dst, dest->sin6_addr.s6_addr, 16);
if (local_ports[clnt] == 0 && (local_ports[clnt] = alloc_lport(clnt)) == 0) {
command void getLLAddr(struct in6_addr *addr);
command void getIPAddr(struct in6_addr *addr);
+ command void setSource(struct ip6_hdr *hdr);
+
command void setPrefix(uint8_t *prefix);
command bool haveAddress();