mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2025-08-11 17:04:37 +08:00
ip_forward() returns netif on which packet was forwarded.
This commit is contained in:
parent
d11fcafad8
commit
31c1e72b8c
@ -101,7 +101,7 @@ ip_route(struct ip_addr *dest)
|
|||||||
* checksum and outputs the packet on the appropriate interface.
|
* checksum and outputs the packet on the appropriate interface.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void
|
static struct netif *
|
||||||
ip_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
|
ip_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
|
||||||
{
|
{
|
||||||
struct netif *netif;
|
struct netif *netif;
|
||||||
@ -113,14 +113,14 @@ ip_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
|
|||||||
LWIP_DEBUGF(IP_DEBUG, ("ip_forward: no forwarding route for 0x%lx found\n",
|
LWIP_DEBUGF(IP_DEBUG, ("ip_forward: no forwarding route for 0x%lx found\n",
|
||||||
iphdr->dest.addr));
|
iphdr->dest.addr));
|
||||||
snmp_inc_ipnoroutes();
|
snmp_inc_ipnoroutes();
|
||||||
return;
|
return (struct netif *)NULL;
|
||||||
}
|
}
|
||||||
/* Do not forward packets onto the same network interface on which
|
/* Do not forward packets onto the same network interface on which
|
||||||
* they arrived. */
|
* they arrived. */
|
||||||
if (netif == inp) {
|
if (netif == inp) {
|
||||||
LWIP_DEBUGF(IP_DEBUG, ("ip_forward: not bouncing packets back on incoming interface.\n"));
|
LWIP_DEBUGF(IP_DEBUG, ("ip_forward: not bouncing packets back on incoming interface.\n"));
|
||||||
snmp_inc_ipnoroutes();
|
snmp_inc_ipnoroutes();
|
||||||
return;
|
return (struct netif *)NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* decrement TTL */
|
/* decrement TTL */
|
||||||
@ -132,7 +132,7 @@ ip_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
|
|||||||
icmp_time_exceeded(p, ICMP_TE_TTL);
|
icmp_time_exceeded(p, ICMP_TE_TTL);
|
||||||
snmp_inc_icmpouttimeexcds();
|
snmp_inc_icmpouttimeexcds();
|
||||||
}
|
}
|
||||||
return;
|
return (struct netif *)NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Incrementally update the IP checksum. */
|
/* Incrementally update the IP checksum. */
|
||||||
@ -152,6 +152,7 @@ ip_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
|
|||||||
PERF_STOP("ip_forward");
|
PERF_STOP("ip_forward");
|
||||||
/* transmit pbuf on chosen interface */
|
/* transmit pbuf on chosen interface */
|
||||||
netif->output(netif, p, (struct ip_addr *)&(iphdr->dest));
|
netif->output(netif, p, (struct ip_addr *)&(iphdr->dest));
|
||||||
|
return netif;
|
||||||
}
|
}
|
||||||
#endif /* IP_FORWARD */
|
#endif /* IP_FORWARD */
|
||||||
|
|
||||||
@ -163,13 +164,16 @@ ip_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
|
|||||||
* forwarded (using ip_forward). The IP checksum is always checked.
|
* forwarded (using ip_forward). The IP checksum is always checked.
|
||||||
*
|
*
|
||||||
* Finally, the packet is sent to the upper layer protocol input function.
|
* Finally, the packet is sent to the upper layer protocol input function.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
err_t
|
err_t
|
||||||
ip_input(struct pbuf *p, struct netif *inp) {
|
ip_input(struct pbuf *p, struct netif *inp) {
|
||||||
static struct ip_hdr *iphdr;
|
struct ip_hdr *iphdr;
|
||||||
static struct netif *netif;
|
struct netif *netif;
|
||||||
static u16_t iphdrlen;
|
u16_t iphdrlen;
|
||||||
|
|
||||||
IP_STATS_INC(ip.recv);
|
IP_STATS_INC(ip.recv);
|
||||||
snmp_inc_ipinreceives();
|
snmp_inc_ipinreceives();
|
||||||
@ -220,8 +224,8 @@ ip_input(struct pbuf *p, struct netif *inp) {
|
|||||||
* but we'll do it anyway just to be sure that its done. */
|
* but we'll do it anyway just to be sure that its done. */
|
||||||
pbuf_realloc(p, ntohs(IPH_LEN(iphdr)));
|
pbuf_realloc(p, ntohs(IPH_LEN(iphdr)));
|
||||||
|
|
||||||
/* is this packet for us? */
|
/* match packet against an interface, i.e. is this packet for us? */
|
||||||
for(netif = netif_list; netif != NULL; netif = netif->next) {
|
for (netif = netif_list; netif != NULL; netif = netif->next) {
|
||||||
|
|
||||||
LWIP_DEBUGF(IP_DEBUG, ("ip_input: iphdr->dest 0x%lx netif->ip_addr 0x%lx (0x%lx, 0x%lx, 0x%lx)\n",
|
LWIP_DEBUGF(IP_DEBUG, ("ip_input: iphdr->dest 0x%lx netif->ip_addr 0x%lx (0x%lx, 0x%lx, 0x%lx)\n",
|
||||||
iphdr->dest.addr, netif->ip_addr.addr,
|
iphdr->dest.addr, netif->ip_addr.addr,
|
||||||
@ -229,8 +233,8 @@ ip_input(struct pbuf *p, struct netif *inp) {
|
|||||||
netif->ip_addr.addr & netif->netmask.addr,
|
netif->ip_addr.addr & netif->netmask.addr,
|
||||||
iphdr->dest.addr & ~(netif->netmask.addr)));
|
iphdr->dest.addr & ~(netif->netmask.addr)));
|
||||||
|
|
||||||
/* interface configured? */
|
/* interface is up and configured? */
|
||||||
if (!ip_addr_isany(&(netif->ip_addr)))
|
if ((netif_is_up(netif)) && (!ip_addr_isany(&(netif->ip_addr))))
|
||||||
{
|
{
|
||||||
/* unicast to this interface address? */
|
/* unicast to this interface address? */
|
||||||
if (ip_addr_cmp(&(iphdr->dest), &(netif->ip_addr)) ||
|
if (ip_addr_cmp(&(iphdr->dest), &(netif->ip_addr)) ||
|
||||||
@ -249,7 +253,8 @@ ip_input(struct pbuf *p, struct netif *inp) {
|
|||||||
#if LWIP_DHCP
|
#if LWIP_DHCP
|
||||||
/* Pass DHCP messages regardless of destination address. DHCP traffic is addressed
|
/* Pass DHCP messages regardless of destination address. DHCP traffic is addressed
|
||||||
* using link layer addressing (such as Ethernet MAC) so we must not filter on IP.
|
* using link layer addressing (such as Ethernet MAC) so we must not filter on IP.
|
||||||
* According to RFC 1542 section 3.1.1, referred by RFC 2131). */
|
* According to RFC 1542 section 3.1.1, referred by RFC 2131).
|
||||||
|
*/
|
||||||
if (netif == NULL) {
|
if (netif == NULL) {
|
||||||
/* remote port is DHCP server? */
|
/* remote port is DHCP server? */
|
||||||
if (IPH_PROTO(iphdr) == IP_PROTO_UDP) {
|
if (IPH_PROTO(iphdr) == IP_PROTO_UDP) {
|
||||||
@ -375,8 +380,8 @@ ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
|
|||||||
u8_t ttl, u8_t tos,
|
u8_t ttl, u8_t tos,
|
||||||
u8_t proto, struct netif *netif)
|
u8_t proto, struct netif *netif)
|
||||||
{
|
{
|
||||||
static struct ip_hdr *iphdr;
|
struct ip_hdr *iphdr;
|
||||||
static u16_t ip_id = 0;
|
u16_t ip_id = 0;
|
||||||
|
|
||||||
snmp_inc_ipoutrequests();
|
snmp_inc_ipoutrequests();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user