net: support some control messages for udp recv
This commit is contained in:
parent
60bd809a40
commit
335bdf1e72
@ -162,6 +162,20 @@ int net_ipv4_send(struct ipv4_packet * response, fs_node_t * nic) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void sock_ipv4_control_common(sock_t * sock, struct msghdr * msg, struct ipv4_packet * src, int proto) {
|
||||||
|
/* TODO Other options; priv32[2] should be for flags? */
|
||||||
|
if (sock->priv32[2] && msg->msg_controllen > sizeof(struct cmsghdr) + 1) {
|
||||||
|
struct cmsghdr * out = msg->msg_control;
|
||||||
|
out->cmsg_len = sizeof(struct cmsghdr) + 1;
|
||||||
|
out->cmsg_level = IPPROTO_IP;
|
||||||
|
out->cmsg_type = IP_RECVTTL;
|
||||||
|
out->cmsg_data[0] = src->ttl;
|
||||||
|
msg->msg_controllen = sizeof(struct cmsghdr) + 1;
|
||||||
|
} else {
|
||||||
|
msg->msg_controllen = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void icmp_handle(struct ipv4_packet * packet, const char * src, const char * dest, fs_node_t * nic) {
|
static void icmp_handle(struct ipv4_packet * packet, const char * src, const char * dest, fs_node_t * nic) {
|
||||||
struct icmp_header * header = (void*)&packet->payload;
|
struct icmp_header * header = (void*)&packet->payload;
|
||||||
|
|
||||||
@ -236,17 +250,7 @@ static long sock_icmp_recv(sock_t * sock, struct msghdr * msg, int flags) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO should check flag IP_RECVTTL ? Also this should be common to all IPPROTO_IP sockets */
|
sock_ipv4_control_common(sock,msg,src,IPPROTO_ICMP);
|
||||||
if (sock->priv32[2] && msg->msg_controllen > sizeof(struct cmsghdr) + 1) {
|
|
||||||
struct cmsghdr * out = msg->msg_control;
|
|
||||||
out->cmsg_len = sizeof(struct cmsghdr) + 1;
|
|
||||||
out->cmsg_level = IPPROTO_IP;
|
|
||||||
out->cmsg_type = IP_RECVTTL;
|
|
||||||
out->cmsg_data[0] = src->ttl;
|
|
||||||
msg->msg_controllen = sizeof(struct cmsghdr) + 1;
|
|
||||||
} else {
|
|
||||||
msg->msg_controllen = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(msg->msg_iov[0].iov_base, src->payload, packet_size);
|
memcpy(msg->msg_iov[0].iov_base, src->payload, packet_size);
|
||||||
free(packet);
|
free(packet);
|
||||||
@ -574,6 +578,8 @@ static long sock_udp_recv(sock_t * sock, struct msghdr * msg, int flags) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sock_ipv4_control_common(sock,msg,data,IPPROTO_UDP);
|
||||||
|
|
||||||
printf("udp: data copied to iov 0, return length?\n");
|
printf("udp: data copied to iov 0, return length?\n");
|
||||||
|
|
||||||
long resp = ntohs(data->length) - sizeof(struct ipv4_packet) - sizeof(struct udp_packet);
|
long resp = ntohs(data->length) - sizeof(struct ipv4_packet) - sizeof(struct udp_packet);
|
||||||
|
Loading…
Reference in New Issue
Block a user