static Iface_DEFUN incomingFromUpperDistributorIf(struct Message* msg, struct Iface* upperDistributorIf) { struct TUNAdapter_pvt* ud = Identity_containerOf(upperDistributorIf, struct TUNAdapter_pvt, pub.upperDistributorIf); Assert_true(msg->length >= RouteHeader_SIZE + DataHeader_SIZE); struct RouteHeader* hdr = (struct RouteHeader*) msg->bytes; struct DataHeader* dh = (struct DataHeader*) &hdr[1]; enum ContentType type = DataHeader_getContentType(dh); Assert_true(type <= ContentType_IP6_RAW); // Shift ip address into destination slot. Bits_memmoveConst(&hdr->ip6[DataHeader_SIZE - 16], hdr->ip6, 16); // put my address as destination. Bits_memcpyConst(&hdr->ip6[DataHeader_SIZE], ud->myIp6, 16); Message_shift(msg, Headers_IP6Header_SIZE - DataHeader_SIZE - RouteHeader_SIZE, NULL); struct Headers_IP6Header* ip6 = (struct Headers_IP6Header*) msg->bytes; Bits_memset(ip6, 0, Headers_IP6Header_SIZE - 32); Headers_setIpVersion(ip6); ip6->payloadLength_be = Endian_bigEndianToHost16(msg->length - Headers_IP6Header_SIZE); ip6->nextHeader = type; ip6->hopLimit = 42; TUNMessageType_push(msg, Ethernet_TYPE_IP6, NULL); return sendToTunIf(msg, ud); }
static Iface_DEFUN incomingFromSessionManagerIf(struct Message* msg, struct Iface* sessionManagerIf) { struct UpperDistributor_pvt* ud = Identity_containerOf(sessionManagerIf, struct UpperDistributor_pvt, pub.sessionManagerIf); Assert_true(msg->length >= RouteHeader_SIZE + DataHeader_SIZE); struct RouteHeader* hdr = (struct RouteHeader*) msg->bytes; struct DataHeader* dh = (struct DataHeader*) &hdr[1]; enum ContentType type = DataHeader_getContentType(dh); if (type <= ContentType_IP6_RAW) { return Iface_next(&ud->pub.tunAdapterIf, msg); } if (type == ContentType_CJDHT) { Message_push32(msg, 0xffffffff, NULL); Message_push32(msg, PFChan_Core_MSG, NULL); return Iface_next(&ud->eventIf, msg); } if (type == ContentType_IPTUN) { return Iface_next(&ud->pub.ipTunnelIf, msg); } Log_debug(ud->log, "DROP message with unknown type [%d]", type); return NULL; }