1/*- 2 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 16 unchanged lines hidden (view full) --- 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * @(#)tcp_subr.c 8.2 (Berkeley) 5/24/95 30 */ 31 32#include <sys/cdefs.h> |
33__FBSDID("$FreeBSD: head/sys/netinet/tcp_subr.c 254889 2013-08-25 21:54:41Z markj $"); |
34 35#include "opt_compat.h" 36#include "opt_inet.h" 37#include "opt_inet6.h" 38#include "opt_ipsec.h" |
39#include "opt_kdtrace.h" |
40#include "opt_tcpdebug.h" 41 42#include <sys/param.h> 43#include <sys/systm.h> 44#include <sys/callout.h> 45#include <sys/hhook.h> 46#include <sys/kernel.h> 47#include <sys/khelp.h> 48#include <sys/sysctl.h> 49#include <sys/jail.h> 50#include <sys/malloc.h> 51#include <sys/mbuf.h> 52#ifdef INET6 53#include <sys/domain.h> 54#endif 55#include <sys/priv.h> 56#include <sys/proc.h> |
57#include <sys/sdt.h> |
58#include <sys/socket.h> 59#include <sys/socketvar.h> 60#include <sys/protosw.h> 61#include <sys/random.h> 62 63#include <vm/uma.h> 64 65#include <net/route.h> 66#include <net/if.h> 67#include <net/vnet.h> 68 69#include <netinet/cc.h> 70#include <netinet/in.h> |
71#include <netinet/in_kdtrace.h> |
72#include <netinet/in_pcb.h> 73#include <netinet/in_systm.h> 74#include <netinet/in_var.h> 75#include <netinet/ip.h> 76#include <netinet/ip_icmp.h> 77#include <netinet/ip_var.h> 78#ifdef INET6 79#include <netinet/ip6.h> --- 550 unchanged lines hidden (view full) --- 630 xchg(nth->th_dport, nth->th_sport, uint16_t); 631#undef xchg 632 } 633#ifdef INET6 634 if (isipv6) { 635 ip6->ip6_flow = 0; 636 ip6->ip6_vfc = IPV6_VERSION; 637 ip6->ip6_nxt = IPPROTO_TCP; |
638 tlen += sizeof (struct ip6_hdr) + sizeof (struct tcphdr); |
639 ip6->ip6_plen = htons(tlen - sizeof(*ip6)); |
640 } 641#endif 642#if defined(INET) && defined(INET6) 643 else 644#endif 645#ifdef INET 646 { 647 tlen += sizeof (struct tcpiphdr); --- 52 unchanged lines hidden (view full) --- 700 nth->th_sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr, 701 htons((u_short)(tlen - sizeof(struct ip) + ip->ip_p))); 702 } 703#endif /* INET */ 704#ifdef TCPDEBUG 705 if (tp == NULL || (inp->inp_socket->so_options & SO_DEBUG)) 706 tcp_trace(TA_OUTPUT, 0, tp, mtod(m, void *), th, 0); 707#endif |
708 if (flags & TH_RST) 709 TCP_PROBE5(accept_refused, NULL, NULL, m->m_data, tp, nth); 710 711 TCP_PROBE5(send, NULL, tp, m->m_data, tp, nth); |
712#ifdef INET6 713 if (isipv6) 714 (void) ip6_output(m, NULL, NULL, ipflags, NULL, NULL, inp); 715#endif /* INET6 */ 716#if defined(INET) && defined(INET6) 717 else 718#endif 719#ifdef INET --- 164 unchanged lines hidden (view full) --- 884tcp_drop(struct tcpcb *tp, int errno) 885{ 886 struct socket *so = tp->t_inpcb->inp_socket; 887 888 INP_INFO_WLOCK_ASSERT(&V_tcbinfo); 889 INP_WLOCK_ASSERT(tp->t_inpcb); 890 891 if (TCPS_HAVERCVDSYN(tp->t_state)) { |
892 tcp_state_change(tp, TCPS_CLOSED); |
893 (void) tcp_output(tp); 894 TCPSTAT_INC(tcps_drops); 895 } else 896 TCPSTAT_INC(tcps_conndrops); 897 if (errno == ETIMEDOUT && tp->t_softerror) 898 errno = tp->t_softerror; 899 so->so_error = errno; 900 return (tcp_close(tp)); --- 1477 unchanged lines hidden (view full) --- 2378 } 2379 sp = s + strlen(s); 2380 if (th) 2381 sprintf(sp, " tcpflags 0x%b", th->th_flags, PRINT_TH_FLAGS); 2382 if (*(s + size - 1) != '\0') 2383 panic("%s: string too long", __func__); 2384 return (s); 2385} |
2386 2387/* 2388 * A subroutine which makes it easy to track TCP state changes with DTrace. 2389 * This function shouldn't be called for t_state initializations that don't 2390 * correspond to actual TCP state transitions. 2391 */ 2392void 2393tcp_state_change(struct tcpcb *tp, int newstate) 2394{ 2395#if defined(KDTRACE_HOOKS) 2396 int pstate = tp->t_state; 2397#endif 2398 2399 tp->t_state = newstate; 2400 TCP_PROBE6(state_change, NULL, tp, NULL, tp, NULL, pstate); 2401} |