aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2020-07-19 04:43:57 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2020-07-19 04:54:20 +0200
commit73ed49ab71998d4288e71e954ef6214b70f23d79 (patch)
tree051e4b5489fa5e7885b5d25e65ece2974913e0df
parenta4e41a7e1d6a3a1aab972b36f8a6cdf570bb82b7 (diff)
downloadslirp-73ed49ab71998d4288e71e954ef6214b70f23d79.zip
slirp-73ed49ab71998d4288e71e954ef6214b70f23d79.tar.gz
slirp-73ed49ab71998d4288e71e954ef6214b70f23d79.tar.bz2
icmp, icmp6: Add icmp_forward_error and icmp6_forward_error
They work like icmp_send_error and icmp6_send_error but allow to specify the source IP address Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
-rw-r--r--src/ip6_icmp.c10
-rw-r--r--src/ip6_icmp.h1
-rw-r--r--src/ip_icmp.c12
-rw-r--r--src/ip_icmp.h2
4 files changed, 20 insertions, 5 deletions
diff --git a/src/ip6_icmp.c b/src/ip6_icmp.c
index d9c872b..119c8be 100644
--- a/src/ip6_icmp.c
+++ b/src/ip6_icmp.c
@@ -69,7 +69,7 @@ static void icmp6_send_echoreply(struct mbuf *m, Slirp *slirp, struct ip6 *ip,
ip6_output(NULL, t, 0);
}
-void icmp6_send_error(struct mbuf *m, uint8_t type, uint8_t code)
+void icmp6_forward_error(struct mbuf *m, uint8_t type, uint8_t code, struct in6_addr *src)
{
Slirp *slirp = m->slirp;
struct mbuf *t;
@@ -88,7 +88,7 @@ void icmp6_send_error(struct mbuf *m, uint8_t type, uint8_t code)
/* IPv6 packet */
struct ip6 *rip = mtod(t, struct ip6 *);
- rip->ip_src = (struct in6_addr)LINKLOCAL_ADDR;
+ rip->ip_src = *src;
rip->ip_dst = ip->ip_src;
inet_ntop(AF_INET6, &rip->ip_dst, addrstr, INET6_ADDRSTRLEN);
DEBUG_ARG("target = %s", addrstr);
@@ -131,6 +131,12 @@ void icmp6_send_error(struct mbuf *m, uint8_t type, uint8_t code)
ip6_output(NULL, t, 0);
}
+void icmp6_send_error(struct mbuf *m, uint8_t type, uint8_t code)
+{
+ struct in6_addr src = LINKLOCAL_ADDR;
+ icmp6_forward_error(m, type, code, &src);
+}
+
/*
* Send NDP Router Advertisement
*/
diff --git a/src/ip6_icmp.h b/src/ip6_icmp.h
index c37e60f..9070999 100644
--- a/src/ip6_icmp.h
+++ b/src/ip6_icmp.h
@@ -212,6 +212,7 @@ struct ndpopt {
void icmp6_init(Slirp *slirp);
void icmp6_cleanup(Slirp *slirp);
void icmp6_input(struct mbuf *);
+void icmp6_forward_error(struct mbuf *m, uint8_t type, uint8_t code, struct in6_addr *src);
void icmp6_send_error(struct mbuf *m, uint8_t type, uint8_t code);
void ndp_send_ra(Slirp *slirp);
void ndp_send_ns(Slirp *slirp, struct in6_addr addr);
diff --git a/src/ip_icmp.c b/src/ip_icmp.c
index 13a0e55..94afba6 100644
--- a/src/ip_icmp.c
+++ b/src/ip_icmp.c
@@ -256,8 +256,8 @@ end_error:
*/
#define ICMP_MAXDATALEN (IP_MSS - 28)
-void icmp_send_error(struct mbuf *msrc, uint8_t type, uint8_t code, int minsize,
- const char *message)
+void icmp_forward_error(struct mbuf *msrc, uint8_t type, uint8_t code, int minsize,
+ const char *message, struct in_addr *src)
{
unsigned hlen, shlen, s_ip_len;
register struct ip *ip;
@@ -372,7 +372,7 @@ void icmp_send_error(struct mbuf *msrc, uint8_t type, uint8_t code, int minsize,
ip->ip_ttl = MAXTTL;
ip->ip_p = IPPROTO_ICMP;
ip->ip_dst = ip->ip_src; /* ip addresses */
- ip->ip_src = m->slirp->vhost_addr;
+ ip->ip_src = *src;
(void)ip_output((struct socket *)NULL, m);
@@ -381,6 +381,12 @@ end_error:
}
#undef ICMP_MAXDATALEN
+void icmp_send_error(struct mbuf *msrc, uint8_t type, uint8_t code, int minsize,
+ const char *message)
+{
+ icmp_forward_error(msrc, type, code, minsize, message, &msrc->slirp->vhost_addr);
+}
+
/*
* Reflect the ip packet back to the source
*/
diff --git a/src/ip_icmp.h b/src/ip_icmp.h
index 84707db..569a083 100644
--- a/src/ip_icmp.h
+++ b/src/ip_icmp.h
@@ -157,6 +157,8 @@ struct icmp {
void icmp_init(Slirp *slirp);
void icmp_cleanup(Slirp *slirp);
void icmp_input(struct mbuf *, int);
+void icmp_forward_error(struct mbuf *msrc, uint8_t type, uint8_t code, int minsize,
+ const char *message, struct in_addr *src);
void icmp_send_error(struct mbuf *msrc, uint8_t type, uint8_t code, int minsize,
const char *message);
void icmp_reflect(struct mbuf *);