ip_input.c (62e1a437f3285e785d9b35a476d36a469a90028d) ip_input.c (c8ee75f2315e8267ad814dc5b4645ef205f0e0e1)
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1982, 1986, 1988, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 88 unchanged lines hidden (view full) ---

97/* IP reassembly functions are defined in ip_reass.c. */
98extern void ipreass_init(void);
99extern void ipreass_drain(void);
100extern void ipreass_slowtimo(void);
101#ifdef VIMAGE
102extern void ipreass_destroy(void);
103#endif
104
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1982, 1986, 1988, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 88 unchanged lines hidden (view full) ---

97/* IP reassembly functions are defined in ip_reass.c. */
98extern void ipreass_init(void);
99extern void ipreass_drain(void);
100extern void ipreass_slowtimo(void);
101#ifdef VIMAGE
102extern void ipreass_destroy(void);
103#endif
104
105struct rmlock in_ifaddr_lock;
106RM_SYSINIT(in_ifaddr_lock, &in_ifaddr_lock, "in_ifaddr_lock");
107
108VNET_DEFINE(int, rsvp_on);
109
110VNET_DEFINE(int, ipforwarding);
111SYSCTL_INT(_net_inet_ip, IPCTL_FORWARDING, forwarding, CTLFLAG_VNET | CTLFLAG_RW,
112 &VNET_NAME(ipforwarding), 0,
113 "Enable IP forwarding between interfaces");
114
115/*

--- 59 unchanged lines hidden (view full) ---

175
176extern struct domain inetdomain;
177extern struct protosw inetsw[];
178u_char ip_protox[IPPROTO_MAX];
179VNET_DEFINE(struct in_ifaddrhead, in_ifaddrhead); /* first inet address */
180VNET_DEFINE(struct in_ifaddrhashhead *, in_ifaddrhashtbl); /* inet addr hash table */
181VNET_DEFINE(u_long, in_ifaddrhmask); /* mask for hash table */
182
105VNET_DEFINE(int, rsvp_on);
106
107VNET_DEFINE(int, ipforwarding);
108SYSCTL_INT(_net_inet_ip, IPCTL_FORWARDING, forwarding, CTLFLAG_VNET | CTLFLAG_RW,
109 &VNET_NAME(ipforwarding), 0,
110 "Enable IP forwarding between interfaces");
111
112/*

--- 59 unchanged lines hidden (view full) ---

172
173extern struct domain inetdomain;
174extern struct protosw inetsw[];
175u_char ip_protox[IPPROTO_MAX];
176VNET_DEFINE(struct in_ifaddrhead, in_ifaddrhead); /* first inet address */
177VNET_DEFINE(struct in_ifaddrhashhead *, in_ifaddrhashtbl); /* inet addr hash table */
178VNET_DEFINE(u_long, in_ifaddrhmask); /* mask for hash table */
179
180/* Make sure it is safe to use hashinit(9) on CK_LIST. */
181CTASSERT(sizeof(struct in_ifaddrhashhead) == sizeof(LIST_HEAD(, in_addr)));
182
183#ifdef IPCTL_DEFMTU
184SYSCTL_INT(_net_inet_ip, IPCTL_DEFMTU, mtu, CTLFLAG_RW,
185 &ip_mtu, 0, "Default MTU");
186#endif
187
188#ifdef IPSTEALTH
189VNET_DEFINE(int, ipstealth);
190SYSCTL_INT(_net_inet_ip, OID_AUTO, stealth, CTLFLAG_VNET | CTLFLAG_RW,

--- 257 unchanged lines hidden (view full) ---

448/*
449 * Ip input routine. Checksum and byte swap header. If fragmented
450 * try to reassemble. Process options. Pass to next level.
451 */
452void
453ip_input(struct mbuf *m)
454{
455 MROUTER_RLOCK_TRACKER;
183#ifdef IPCTL_DEFMTU
184SYSCTL_INT(_net_inet_ip, IPCTL_DEFMTU, mtu, CTLFLAG_RW,
185 &ip_mtu, 0, "Default MTU");
186#endif
187
188#ifdef IPSTEALTH
189VNET_DEFINE(int, ipstealth);
190SYSCTL_INT(_net_inet_ip, OID_AUTO, stealth, CTLFLAG_VNET | CTLFLAG_RW,

--- 257 unchanged lines hidden (view full) ---

448/*
449 * Ip input routine. Checksum and byte swap header. If fragmented
450 * try to reassemble. Process options. Pass to next level.
451 */
452void
453ip_input(struct mbuf *m)
454{
455 MROUTER_RLOCK_TRACKER;
456 struct rm_priotracker in_ifa_tracker;
457 struct ip *ip = NULL;
458 struct in_ifaddr *ia = NULL;
459 struct ifaddr *ifa;
460 struct ifnet *ifp;
461 int checkif, hlen = 0;
462 uint16_t sum, ip_len;
463 int dchg = 0; /* dest changed after fw */
464 struct in_addr odst; /* original dst address */

--- 219 unchanged lines hidden (view full) ---

684 */
685 checkif = V_ip_checkinterface && (V_ipforwarding == 0) &&
686 ifp != NULL && ((ifp->if_flags & IFF_LOOPBACK) == 0) &&
687 ifp->if_carp == NULL && (dchg == 0);
688
689 /*
690 * Check for exact addresses in the hash bucket.
691 */
456 struct ip *ip = NULL;
457 struct in_ifaddr *ia = NULL;
458 struct ifaddr *ifa;
459 struct ifnet *ifp;
460 int checkif, hlen = 0;
461 uint16_t sum, ip_len;
462 int dchg = 0; /* dest changed after fw */
463 struct in_addr odst; /* original dst address */

--- 219 unchanged lines hidden (view full) ---

683 */
684 checkif = V_ip_checkinterface && (V_ipforwarding == 0) &&
685 ifp != NULL && ((ifp->if_flags & IFF_LOOPBACK) == 0) &&
686 ifp->if_carp == NULL && (dchg == 0);
687
688 /*
689 * Check for exact addresses in the hash bucket.
690 */
692 IN_IFADDR_RLOCK(&in_ifa_tracker);
693 LIST_FOREACH(ia, INADDR_HASH(ip->ip_dst.s_addr), ia_hash) {
691 CK_LIST_FOREACH(ia, INADDR_HASH(ip->ip_dst.s_addr), ia_hash) {
694 /*
695 * If the address matches, verify that the packet
696 * arrived via the correct interface if checking is
697 * enabled.
698 */
699 if (IA_SIN(ia)->sin_addr.s_addr == ip->ip_dst.s_addr &&
700 (!checkif || ia->ia_ifp == ifp)) {
701 counter_u64_add(ia->ia_ifa.ifa_ipackets, 1);
702 counter_u64_add(ia->ia_ifa.ifa_ibytes,
703 m->m_pkthdr.len);
692 /*
693 * If the address matches, verify that the packet
694 * arrived via the correct interface if checking is
695 * enabled.
696 */
697 if (IA_SIN(ia)->sin_addr.s_addr == ip->ip_dst.s_addr &&
698 (!checkif || ia->ia_ifp == ifp)) {
699 counter_u64_add(ia->ia_ifa.ifa_ipackets, 1);
700 counter_u64_add(ia->ia_ifa.ifa_ibytes,
701 m->m_pkthdr.len);
704 IN_IFADDR_RUNLOCK(&in_ifa_tracker);
705 goto ours;
706 }
707 }
702 goto ours;
703 }
704 }
708 IN_IFADDR_RUNLOCK(&in_ifa_tracker);
709
710 /*
711 * Check for broadcast addresses.
712 *
713 * Only accept broadcast packets that arrive via the matching
714 * interface. Reception of forwarded directed broadcasts would
715 * be handled via ip_forward() and ether_output() with the loopback
716 * into the stack for SIMPLEX interfaces handled by ether_output().

--- 723 unchanged lines hidden ---
705
706 /*
707 * Check for broadcast addresses.
708 *
709 * Only accept broadcast packets that arrive via the matching
710 * interface. Reception of forwarded directed broadcasts would
711 * be handled via ip_forward() and ether_output() with the loopback
712 * into the stack for SIMPLEX interfaces handled by ether_output().

--- 723 unchanged lines hidden ---