From owner-svn-src-user@FreeBSD.ORG Sun Oct 13 19:25:24 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 718363C1; Sun, 13 Oct 2013 19:25:24 +0000 (UTC) (envelope-from andre@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 5DE5F233E; Sun, 13 Oct 2013 19:25:24 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9DJPOa4052852; Sun, 13 Oct 2013 19:25:24 GMT (envelope-from andre@svn.freebsd.org) Received: (from andre@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9DJPN78052845; Sun, 13 Oct 2013 19:25:23 GMT (envelope-from andre@svn.freebsd.org) Message-Id: <201310131925.r9DJPN78052845@svn.freebsd.org> From: Andre Oppermann Date: Sun, 13 Oct 2013 19:25:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256432 - in user/andre/mbuf_staging: kern sys X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Oct 2013 19:25:24 -0000 Author: andre Date: Sun Oct 13 19:25:23 2013 New Revision: 256432 URL: http://svnweb.freebsd.org/changeset/base/256432 Log: Remove unused zone arguments from m_init(). Merge _m_align(), _mh_align(), and _mext_align into m_align() which already handles all these cases. Optimize m_prepend() by testing for sufficient leading space instead of always allocating a new mbuf merge _m_prepend() into it. Move mbuf allocation function prototypes together. Constify a some mbuf functions. [Suggested by: bde] Modified: user/andre/mbuf_staging/kern/kern_mbuf.c user/andre/mbuf_staging/kern/uipc_mbuf.c user/andre/mbuf_staging/sys/mbuf.h Modified: user/andre/mbuf_staging/kern/kern_mbuf.c ============================================================================== --- user/andre/mbuf_staging/kern/kern_mbuf.c Sun Oct 13 19:02:16 2013 (r256431) +++ user/andre/mbuf_staging/kern/kern_mbuf.c Sun Oct 13 19:25:23 2013 (r256432) @@ -440,7 +440,7 @@ mb_ctor_mbuf(void *mem, int size, void * m = (struct mbuf *)mem; flags = args->flags; - error = m_init(m, NULL, size, how, type, flags); + error = m_init(m, size, how, type, flags); return (error); } @@ -641,7 +641,7 @@ mb_ctor_pack(void *mem, int size, void * trash_ctor(m->m_ext.ext_buf, MCLBYTES, arg, how); #endif - error = m_init(m, NULL, size, how, type, flags); + error = m_init(m, size, how, type, flags); /* m_ext is already initialized. */ m->m_data = m->m_ext.ext_buf; @@ -685,7 +685,7 @@ m_getzone(int size) * should go away with constant propagation for !MGETHDR. */ int -m_init(struct mbuf *m, uma_zone_t zone, int size, int how, short type, +m_init(struct mbuf *m, int size, int how, short type, int flags) { int error; Modified: user/andre/mbuf_staging/kern/uipc_mbuf.c ============================================================================== --- user/andre/mbuf_staging/kern/uipc_mbuf.c Sun Oct 13 19:02:16 2013 (r256431) +++ user/andre/mbuf_staging/kern/uipc_mbuf.c Sun Oct 13 19:25:23 2013 (r256432) @@ -295,6 +295,16 @@ m_prepend(struct mbuf *m, int len, int h { struct mbuf *mn; + MBUF_CHECKSLEEP(how); + + if (M_LEADINGSPACE(m) >= len) { + m->m_data -= len; + m->m_len += len; + if (m->m_flags & M_PKTHDR) + m->m_pkthdr.len += len; + return (m); + } + if (m->m_flags & M_PKTHDR) mn = m_gethdr(how, m->m_type); else @@ -1759,79 +1769,49 @@ m_unshare(struct mbuf *m0, int how) } int -_m_writable(struct mbuf *m) +_m_writable(const struct mbuf *m) { - return (!((m)->m_flags & M_RDONLY) && - (!(((m)->m_flags & M_EXT)) || (*((m)->m_ext.ref_cnt) == 1)) ); -} - -void -_m_align(struct mbuf *m, int len) -{ - KASSERT(!((m)->m_flags & (M_PKTHDR|M_EXT)), - ("%s: M_ALIGN not normal mbuf", __func__)); - KASSERT((m)->m_data == (m)->m_dat, - ("%s: M_ALIGN not a virgin mbuf", __func__)); - (m)->m_data += (MLEN - (len)) & ~(sizeof(long) - 1); + if ((m->m_flags & M_RDONLY) || + ((m->m_flags & M_EXT) && (*(m->m_ext.ref_cnt) > 1))) + return (0); + else + return (1); } -void -_mh_align(struct mbuf *m, int len) +int +_m_leadingspace(const struct mbuf *m) { - KASSERT((m)->m_flags & M_PKTHDR && !((m)->m_flags & M_EXT), - ("%s: MH_ALIGN not PKTHDR mbuf", __func__)); - KASSERT((m)->m_data == (m)->m_pktdat, - ("%s: MH_ALIGN not a virgin mbuf", __func__)); - (m)->m_data += (MHLEN - (len)) & ~(sizeof(long) - 1); -} + int space; -void -_mext_align(struct mbuf *m, int len) -{ - KASSERT((m)->m_flags & M_EXT, - ("%s: MEXT_ALIGN not an M_EXT mbuf", __func__)); - KASSERT((m)->m_data == (m)->m_ext.ext_buf, - ("%s: MEXT_ALIGN not a virgin mbuf", __func__)); - (m)->m_data += ((m)->m_ext.ext_size - (len)) & - ~(sizeof(long) - 1); -} + if (m->m_flags & M_EXT) + if (M_WRITABLE(m)) + space = m->m_data - m->m_ext.ext_buf; + else + space = 0; + else if (m->m_flags & M_PKTHDR) + space = m->m_data - m->m_pktdat; + else + space = m->m_data - m->m_dat; -int -_m_leadingspace(struct mbuf *m) -{ - return ((m)->m_flags & M_EXT ? - (M_WRITABLE(m) ? (m)->m_data - (m)->m_ext.ext_buf : 0): - (m)->m_flags & M_PKTHDR ? (m)->m_data - (m)->m_pktdat : - (m)->m_data - (m)->m_dat); + return (space); } int -_m_trailingspace(struct mbuf *m) +_m_trailingspace(const struct mbuf *m) { - return ((m)->m_flags & M_EXT ? - (M_WRITABLE(m) ? (m)->m_ext.ext_buf + (m)->m_ext.ext_size - - ((m)->m_data + (m)->m_len) : 0) : - &(m)->m_dat[MLEN] - ((m)->m_data + (m)->m_len)); -} + int space; -void -_m_prepend(struct mbuf *m, int plen, int how) -{ - struct mbuf **_mmp = &(m); - struct mbuf *_mm = *_mmp; - int _mplen = (plen); - int __mhow = (how); + if (m->m_flags & M_EXT) + if (M_WRITABLE(m)) + space = m->m_ext.ext_buf + m->m_ext.ext_size - + (m->m_data + m->m_len); + else + space = 0; + else + space = &m->m_dat[MLEN] - (m->m_data + m->m_len); - MBUF_CHECKSLEEP(how); - if (M_LEADINGSPACE(_mm) >= _mplen) { - _mm->m_data -= _mplen; - _mm->m_len += _mplen; - } else - _mm = m_prepend(_mm, _mplen, __mhow); - if (_mm != NULL && _mm->m_flags & M_PKTHDR) - _mm->m_pkthdr.len += _mplen; - *_mmp = _mm; + return (space); } #ifdef MBUF_PROFILING Modified: user/andre/mbuf_staging/sys/mbuf.h ============================================================================== --- user/andre/mbuf_staging/sys/mbuf.h Sun Oct 13 19:02:16 2013 (r256431) +++ user/andre/mbuf_staging/sys/mbuf.h Sun Oct 13 19:25:23 2013 (r256432) @@ -509,7 +509,7 @@ int m_pkthdr_init(struct mbuf *, int); int m_gettype(int); void m_extaddref(struct mbuf *, caddr_t, u_int, u_int *, int (*)(struct mbuf *, void *, void *), void *, void *); -int m_init(struct mbuf *, uma_zone_t, int, int, short, int); +int m_init(struct mbuf *, int, int, short, int); struct mbuf *m_get(int, short); struct mbuf *m_getclr(int, short); struct mbuf *m_gethdr(int, short); @@ -517,6 +517,11 @@ struct mbuf *m_getcl(int, short, int); void m_clget(struct mbuf *, int); void *m_cljget(struct mbuf *, int, int); void m_cljset(struct mbuf *, void *, int); +struct mbuf *m_free(struct mbuf *); +void m_freem(struct mbuf *); +struct mbuf *m_get2(int, int, short, int); +struct mbuf *m_getjcl(int, short, int, int); +struct mbuf *m_getm2(struct mbuf *, int, int, short, int); static __inline void m_chtype(struct mbuf *m, short new_type) @@ -560,7 +565,7 @@ m_last(struct mbuf *m) * be both the local data payload, or an external buffer area, depending on * whether M_EXT is set). */ -int _m_writable(struct mbuf *); +int _m_writable(const struct mbuf *); #define M_WRITABLE(m) _m_writable(m) /* Check if the supplied mbuf has a packet header, or else panic. */ @@ -580,40 +585,25 @@ int _m_writable(struct mbuf *); /* * Set the m_data pointer of a newly-allocated mbuf (m_get/MGET) to place an * object of the specified size at the end of the mbuf, longword aligned. - */ -void _m_align(struct mbuf *, int); -#define M_ALIGN(m, len) _m_align(m, len) - -/* * As above, for mbufs allocated with m_gethdr/MGETHDR or initialized by * M_DUP/MOVE_PKTHDR. - */ -void _mh_align(struct mbuf *, int); -#define MH_ALIGN(m, len) _mh_align(m, len) - -/* * As above, for mbuf with external storage. */ -void _mext_align(struct mbuf *, int); -#define MEXT_ALIGN(m, len) _mext_align(m, len) +#define M_ALIGN(m, len) m_align(m, len) +#define MH_ALIGN(m, len) m_align(m, len) +#define MEXT_ALIGN(m, len) m_align(m, len) /* * Compute the amount of space available before the current start of data in * an mbuf. - * - * The M_WRITABLE() is a temporary, conservative safety measure: the burden - * of checking writability of the mbuf data area rests solely with the caller. */ -int _m_leadingspace(struct mbuf *); +int _m_leadingspace(const struct mbuf *); #define M_LEADINGSPACE(m) _m_leadingspace(m) /* * Compute the amount of space available after the end of data in an mbuf. - * - * The M_WRITABLE() is a temporary, conservative safety measure: the burden - * of checking writability of the mbuf data area rests solely with the caller. */ -int _m_trailingspace(struct mbuf *); +int _m_trailingspace(const struct mbuf *); #define M_TRAILINGSPACE(m) _m_trailingspace(m) /* @@ -621,8 +611,7 @@ int _m_trailingspace(struct mbuf *); * allocated, how specifies whether to wait. If the allocation fails, the * original mbuf chain is freed and m is set to NULL. */ -void _m_prepend(struct mbuf *, int, int); -#define M_PREPEND(m, plen, how) _m_prepend(m, plen, how) +#define M_PREPEND(m, plen, how) (m = m_prepend(m, plen, how)) /* * Change mbuf to new type. This is a relatively expensive operation and @@ -670,11 +659,6 @@ struct mbuf *m_dup(struct mbuf *, int); int m_dup_pkthdr(struct mbuf *, struct mbuf *, int); u_int m_fixhdr(struct mbuf *); struct mbuf *m_fragment(struct mbuf *, int, int); -struct mbuf *m_free(struct mbuf *); -void m_freem(struct mbuf *); -struct mbuf *m_get2(int, int, short, int); -struct mbuf *m_getjcl(int, short, int, int); -struct mbuf *m_getm2(struct mbuf *, int, int, short, int); struct mbuf *m_getptr(struct mbuf *, int, int *); u_int m_length(struct mbuf *, struct mbuf **); int m_mbuftouio(struct uio *, struct mbuf *, int); From owner-svn-src-user@FreeBSD.ORG Sun Oct 13 21:46:10 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 8288AD63; Sun, 13 Oct 2013 21:46:10 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id E371B28EF; Sun, 13 Oct 2013 21:46:09 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9DLk9Uq025458; Sun, 13 Oct 2013 21:46:09 GMT (envelope-from glebius@svn.freebsd.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9DLk9UF025453; Sun, 13 Oct 2013 21:46:09 GMT (envelope-from glebius@svn.freebsd.org) Message-Id: <201310132146.r9DLk9UF025453@svn.freebsd.org> From: Gleb Smirnoff Date: Sun, 13 Oct 2013 21:46:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256433 - in user/glebius/course: . 03.processes&threads 04.synchronisation X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Oct 2013 21:46:10 -0000 Author: glebius Date: Sun Oct 13 21:46:08 2013 New Revision: 256433 URL: http://svnweb.freebsd.org/changeset/base/256433 Log: Not yet cooked up slides on threads & processes and on synchronisation. Added: user/glebius/course/03.processes&threads/ user/glebius/course/03.processes&threads/Makefile (contents, props changed) user/glebius/course/03.processes&threads/lection.tex user/glebius/course/04.synchronisation/ user/glebius/course/04.synchronisation/Makefile (contents, props changed) user/glebius/course/04.synchronisation/lection.tex Modified: user/glebius/course/course.tex Added: user/glebius/course/03.processes&threads/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/glebius/course/03.processes&threads/Makefile Sun Oct 13 21:46:08 2013 (r256433) @@ -0,0 +1,13 @@ +NAME?= lection + +TMP= $(NAME).aux $(NAME).log $(NAME).nav $(NAME).out $(NAME).snm \ + $(NAME).toc $(NAME).vrb + +.MAIN: $(NAME).pdf + +.SUFFIXES: .pdf .tex +.tex.pdf: + pdflatex -file-line-error -halt-on-error ${.IMPSRC} + +clean: + rm -f -- $(TMP) texput.log Added: user/glebius/course/03.processes&threads/lection.tex ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/glebius/course/03.processes&threads/lection.tex Sun Oct 13 21:46:08 2013 (r256433) @@ -0,0 +1,246 @@ +\documentclass{beamer} + +\usepackage[utf8]{inputenc} +\usepackage[russian]{babel} +\usepackage{tikz} +\usepackage{url} +\usepackage{xcolor} +\usepackage{listings} +\usepackage{verbatim} +\usepackage{ifthen} + +\usetikzlibrary{positioning} +\usetikzlibrary{shapes} +\usetikzlibrary{calc} + +\input{../course.tex} + +\title{Processes and threads} + +\begin{document} + +\begin{frame} +\titlepage +\end{frame} + +\FootReferences{}{sys/sys/proc.h} +\begin{frame} +\frametitle{Process structure} +\note { + - A process is a virtual machine that kernel creates for + an application. It provides VM and CPU resources.\\ + - The slide is a minimal layout of a UNIX process. Actual + size of struct proc is > 1Kb. +} +\begin{tikzpicture}[every node/.style={draw, node distance=10mm}] + \node [name=proc, struct, inner sep=2mm, rectangle split parts = 8] { + \textbf{struct proc} + \nodepart{two} struct vmspace *p\_vmspace + \nodepart{three} struct sysentvec *p\_sysent + \nodepart{four} struct filedesc *p\_fd + \nodepart{five} struct ucred *p\_ucred + \nodepart{six} struct plimit *p\_limit + \nodepart{seven} \ldots + \nodepart{eight} TAILQ\_HEAD() p\_threads + }; + + \node[name=vm, right=of proc.two east, rounded corners] + { VM space }; + \draw [->] (proc.two east) -- (vm); + \node[name=sysent, right=of proc.three east, rounded corners] + { syscall vector }; + \draw [->] (proc.three east) -- (sysent); + \node[name=fdesc, right=of proc.four east, rounded corners] + { file descriptor table }; + \draw [->] (proc.four east) -- (fdesc); + \node[name=rlim, right=of proc.five east, rounded corners] + { resource limits }; + \draw [->] (proc.five east) -- (rlim); + \node[name=cred, right=of proc.six east, rounded corners] + { credentials }; + \draw [->] (proc.six east) -- (cred); + + % threads + \node [name=thread1, struct, rectangle split parts = 1, + node distance=5mm, below right=of proc] + { \textbf{struct thread} }; + \node [name=thread2, struct, rectangle split parts = 1, + node distance=5mm, right=of thread1] + { \textbf{struct thread} }; + \draw [->] (proc.eight east) to [out=0, in=180] (thread1.west); + \draw [->] (thread1) -- (thread2); +\end{tikzpicture} +\end{frame} + + +\begin{frame} +\frametitle{p\_state - the process state} +\begin{itemize} + \item{PRS\_NEW} + \item{PRS\_NORMAL} + \item{PRS\_ZOMBIE} +\end{itemize} +\end{frame} + + +\begin{frame} +\frametitle{Thread structure} +\note { + - Thread is a executing entity within a process. It includes all + the data that can't be shared.\\ + - A minimal struct thread layout. Actual size > 1 Kb. +} +\begin{tikzpicture}[every node/.style={draw, node distance=10mm}] + \node [name=thread, struct, inner sep=2mm, rectangle split parts = 6] { + \textbf{struct thread} + \nodepart{two} struct proc *td\_proc + \nodepart{three} struct proc *td\_sched + \nodepart{four} struct pcb *td\_pcb + \nodepart{five} struct vm\_object *td\_kstack\_obj + \nodepart{six} \ldots + }; + + \node [name=proc, right=of thread.two east, struct, rectangle split parts = 1] + { \textbf{struct proc} }; + \draw [->] (thread.two east) -- (proc); + \node [name=sched, right=of thread.three east, rounded corners] + { scheduling info }; + \draw [->] (thread.three east) -- (sched); + \node [name=pcb, right=of thread.four east, rounded corners] + { thread control block (MD) }; + \draw [->] (thread.four east) -- (pcb); + \node [name=kstack, right=of thread.five east, rounded corners] + { kernel stack }; + \draw [->] (thread.five east) -- (kstack); +\end{tikzpicture} +\end{frame} + + +\FootReferences{}{sys/sys/proc.h, sys/kern/kern\_thread.c, + sys/kern/sched\_ule.c} +\begin{frame} +\frametitle{td\_state - the thread state} +\begin{itemize} + \item{TDS\_INACTIVE} + \item{TDS\_CAN\_RUN} + \item{TDS\_RUNQ} + \item{TDS\_RUNNING} + \item{ + TDS\_INHIBITED\\ + \onslide<2> { + Combination of inhibitors in td\_inhibitors: + \begin{itemize} + \item{TDI\_SUSPENDED} + \item{TDI\_SLEEPING} + \item{TDI\_SWAPPED} + \item{TDI\_LOCK} + \item{TDI\_IWAIT} + \end{itemize} + } + } +\end{itemize} +\end{frame} + + +\FootReferences{}{} +\begin{frame} +\frametitle{Historic note: M:N vs 1:1} +\begin{columns}[c] + \begin{column}{.46\paperwidth} + \begin{figure}\begin{tikzpicture} + \node [name=thread, struct, rectangle split parts = 1] + { \textbf{struct thread} }; + \draw ($(thread) + (-.33\paperwidth, 2cm)$) -- + node[very near end, above] { process } + node[very near end, below] { kernel } + ($(thread) + (.13\paperwidth, 2cm)$); + \node [name=uthr1, draw, ellipse, fill=white, + node distance=0, anchor=center, + above left=.3\paperheight and -.08\paperwidth of thread.center, + text width=2cm, align=center] + { user space scheduling entity }; + \draw [->] (uthr1) -- (thread); + \node [name=uthr2, draw, ellipse, fill=white, + node distance=0, anchor=center, + above left=.25\paperheight and .1\paperwidth of thread.center, + text width=2cm, align=center] + { user space scheduling entity }; + \node [name=thread2, struct, rectangle split parts = 1, + node distance=0, above left=3mm and -10mm of thread] + { \textbf{struct thread} }; + \draw [->] (uthr2) -- (thread2); + + \node [name=pthread1, node distance=.6\paperheight, above=of thread] + { pthread\_t }; + \node [name=pthread2, node distance=0, left=.1\paperwidth of pthread1] + { pthread\_t }; + \node [name=pthread21, node distance=0, below right=of pthread2] + { pthread\_t }; + \node [name=pthread22, node distance=0, below right=of pthread21] + { pthread\_t }; + \node [name=pthread23, node distance=0, below left=of pthread21] + { pthread\_t }; + + \draw [->] (pthread23) -- (uthr2); + \draw [->] (pthread22) -- (uthr1); + \draw [->] (pthread21) -- (uthr1); + \draw [->] (pthread1) to [out=270,in=100] + (node cs:name=uthr1,angle=100); + \draw [->] (pthread2.south) to [out=350,in=80] + (node cs:name=uthr2,angle=80); + \end{tikzpicture}\end{figure} + \end{column} + \begin{column}{.08\paperwidth} + \LARGE{VS} + \end{column} + \begin{column}{.46\paperwidth} + \begin{figure}\begin{tikzpicture} + \node [name=thread, struct, rectangle split parts = 1] + { \textbf{struct thread} }; + \draw ($(thread) + (-.23\paperwidth, 2cm)$) -- + node[very near end, above] { process } + node[very near end, below] { kernel } + ($(thread) + (.23\paperwidth, 2cm)$); + \node [name=pthread, node distance=.6\paperheight, above=of thread] + { pthread\_t }; + \draw [->] (pthread) -- (thread); + \end{tikzpicture}\end{figure} + \end{column} +\end{columns} +\end{frame} + + +\begin{frame} +\frametitle{Historic note: M:N vs 1:1} +\only<1> { + \begin{itemize} + \item{1993 Solaris 2.2 introduces multithreading via non-standard API} + \item{1995 Solaris 2.5 supports POSIX threads API, \textbf{M:N model}} + \item{2000 FreeBSD starts SMPng project targeted at \textbf{M:N}} + \item{2000 Solaris 8 provides \textbf{1:1} threading as option} + \item{2001 Linux starts multithreading project targeted at \textbf{1:1} + with \textbf{M:N} as experimental option} + \item{2001 Mac OS X released with \textbf{1:1} threading} + \item{2002 Solaris 9 uses \textbf{1:1} threading as default} + \item{2003 Linux abandons experimental \textbf{M:N} project} + \item{2004 FreeBSD 5.3 released with Kernel Scheduling Entities + (\textbf{M:N}) threading as default, \textbf{1:1} optional} + \item{2004 NetBSD 2.0 released with Scheduler Activations (\textbf{M:N})} + \item{2004 Linux 2.6 released with \textbf{1:1} threading} + \end{itemize} +} +\only<2-> { + \begin{itemize} + \item{2005 FreeBSD moves focus to \textbf{1:1}} + \item{2007 NetBSD abandons SA (\textbf{M:N})} + \item{2008 FreeBSD abandons KSE (\textbf{M:N})} + \item{2008 FreeBSD 7.0 released with \textbf(1:1) as default, + \textbf{M:N} optional} + \item{2009 NetBSD 5.0 released with \textbf{1:1} as only option} + \item{2009 FreeBSD 8.0 released with \textbf{1:1} as only option} + \onslide<3>\item{2009 Windows 7 introduces User-Mode Scheduling} + \end{itemize} +} +\end{frame} + +\end{document} Added: user/glebius/course/04.synchronisation/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/glebius/course/04.synchronisation/Makefile Sun Oct 13 21:46:08 2013 (r256433) @@ -0,0 +1,13 @@ +NAME?= lection + +TMP= $(NAME).aux $(NAME).log $(NAME).nav $(NAME).out $(NAME).snm \ + $(NAME).toc $(NAME).vrb + +.MAIN: $(NAME).pdf + +.SUFFIXES: .pdf .tex +.tex.pdf: + pdflatex -file-line-error -halt-on-error ${.IMPSRC} + +clean: + rm -f -- $(TMP) texput.log Added: user/glebius/course/04.synchronisation/lection.tex ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/glebius/course/04.synchronisation/lection.tex Sun Oct 13 21:46:08 2013 (r256433) @@ -0,0 +1,222 @@ +\documentclass{beamer} + +\usepackage[utf8]{inputenc} +\usepackage[russian]{babel} +\usepackage{tikz} +\usepackage{url} +\usepackage{xcolor} +\usepackage{listings} +\usepackage{verbatim} +\usepackage{ifthen} +\usepackage{bytefield} + +\usetikzlibrary{positioning} +\usetikzlibrary{shapes} +\usetikzlibrary{calc} + +\input{../course.tex} + +\title{Synchronisation in FreeBSD kernel} + +\begin{document} + +\begin{frame} +\titlepage +\end{frame} + +\begin{frame}[fragile] +\frametitle{Data consistency problem} +\begin{beamercolorbox}[rounded=true,shadow=true]{source} +\lstset{language=C} +\begin{lstlisting} +elm1->elm_next = elm2; +elm2->elm_next = elm3; +elm3->elm_prev = elm2; +elm2->elm_prev = elm1; +\end{lstlisting} +\end{beamercolorbox} +\begin{figure} +\begin{tikzpicture}[every node/.style={draw, node distance=20mm}] + \node [name=elm1, struct, rectangle split parts = 3] { + \textbf{elm1} + \nodepart{two} *elm\_prev + \nodepart{three} *elm\_next + }; + \node [name=elm2, below right=of elm1, struct, rectangle split parts = 3] { + \textbf{elm2} + \nodepart{two} *elm\_prev + \nodepart{three} *elm\_next + }; + \node [name=elm3, above right=of elm2, struct, rectangle split parts = 3] { + \textbf{elm3} + \nodepart{two} *elm\_prev + \nodepart{three} *elm\_next + }; + \onslide<1> { + \draw [->] (elm1.three east) to [out=0,in=180] (elm3.one west); + } + \onslide<-3> { + \draw [->] (elm3.two west) to [out=180,in=0] (elm1.one east); + } + \onslide<2-> { + \draw [->] (elm1.three east) to [out=0,in=180] (elm2.one west); + } + \onslide<3-> { + \draw [->] (elm2.three east) to [out=0,in=180] (elm3.one west); + } + \onslide<4-> { + \draw [->] (elm3.two west) to [out=180,in=0] (elm2.one east); + } + \onslide<5-> { + \draw [->] (elm2.two west) to [out=180,in=0] (elm1.one east); + } +\end{tikzpicture} +\end{figure} +\end{frame} + + +\FootReferences{critical(9)}{sys/kern/kern\_switch.c} +\begin{frame}[fragile] +\frametitle{Critical section} +{\Large{Solution for uniprocessor: enter \emph{critical section}, marking current thread as non-preemptable.}} +\begin{beamercolorbox}[rounded=true,shadow=true]{source} +\lstset{language=C} +\begin{lstlisting} +critical_enter(); +elm1->elm_next = elm2; +elm2->elm_next = elm3; +elm3->elm_prev = elm2; +elm2->elm_prev = elm1; +critical_exit(); +\end{lstlisting} +\end{beamercolorbox} +\end{frame} + + +\begin{frame}[fragile] +\frametitle{Critical section (implementation)} +\emph{Hard} critical sections disable interrupts. +\emph{Soft} ones advice mark thread as non-preemptable. +\Man{critical}{9} is \emph{soft}. +\begin{beamercolorbox}[rounded=true,shadow=true]{source} +\lstset{language=C} +\begin{lstlisting} +void +critical_enter(void) +{ + struct thread *td; + + td = curthread; + td->td_critnest++; +} +\end{lstlisting} +\end{beamercolorbox} +\end{frame} + + +\begin{frame} +\frametitle{Maintaining data consistency on SMP} +\begin{tabular}{cc} + {\Large CPU 1, thread A} & {\Large CPU 2, thread B}\\ +\only<1> { & \\ } +\only<2> { tdA->td\_critnest++ & tdB->td\_critnest++ \\ } +\only<1-2> { + elm1->elm\_next = elm2; & elm1->elm\_next = elm2;\\ + elm2->elm\_next = elm3; & elm2->elm\_next = elm3;\\ + elm3->elm\_prev = elm2; & elm3->elm\_prev = elm2;\\ + elm2->elm\_prev = elm1; & elm2->elm\_prev = elm1;\\ +} +\only<3> { + lock(elm\_lock); & lock(elm\_lock);\\ + elm1->elm\_next = elm2; & \emph{blocked}\\ + elm2->elm\_next = elm3; & \emph{blocked}\\ + elm3->elm\_prev = elm2; & \emph{blocked}\\ + elm2->elm\_prev = elm1; & \emph{blocked}\\ + unlock(elm\_lock); & elm1->elm\_next = elm2;\\ + \ldots & elm2->elm\_next = elm3;\\ +} +\end{tabular} +\end{frame} + + +\FootReferences{mutex(9)}{} +\begin{frame}[fragile] +\frametitle{Naive idea of mutual exclusion lock (mutex)} +\begin{beamercolorbox}[rounded=true,shadow=true]{source} +\lstset{language=C} +\begin{lstlisting} +void +lock(lock_t l) +{ + struct thread *td; + + td = curthread; + +spin: + if (l == NULL) + l = (lock_t )td; + else + goto spin; +} +\end{lstlisting} +\end{beamercolorbox} +\end{frame} + + +\FootReferences{atomic(9)}{sys/amd64/include/atomic.h} +\begin{frame}[fragile] +\frametitle{Working idea of a minimal mutual exclusion lock (mutex)} +\begin{beamercolorbox}[rounded=true,shadow=true]{source} +\lstset{language=C} +\begin{lstlisting} +void +lock(lock_t l) +{ + struct thread *td; + + td = curthread; + +spin: + if (atomic_cmpset(&l, NULL, td) == 0) + goto spin; +} +\end{lstlisting} +\end{beamercolorbox} +\end{frame} + + +\FootReferences{mutex(9), atomic(9)}{sys/kern/mutex.h} +\begin{frame}[fragile] +\frametitle{mutex(9) implementation} +\begin{verbatim} +struct mtx { + /* Common lock properties. */ + struct lock_object lock_object; + /* Owner and flags. */ + volatile uintptr_t mtx_lock; +}; +\end{verbatim} +mtx\_lock:\\ +\begin{bytefield}{32} +\bitheader[endianness=big]{0,1,2,3,10,11} \\ +\bitbox{21}{thread pointer} & \bitbox{8}{unused} & +\bitbox{1}{U} & \bitbox{1}{C} & \bitbox{1}{R} +\end{bytefield} +\begin{verbatim} +#define MTX_RECURSED 0x00000001 /* lock recursed */ +#define MTX_CONTESTED 0x00000002 /* lock contested */ +#define MTX_UNOWNED 0x00000004 /* free mutex */ + +atomic_cmpset_acq_ptr(&(mp)->mtx_lock, MTX_UNOWNED, (tid)) +\end{verbatim} +\end{frame} + + +\FootReferences{mutex(9)}{sys/kern/mutex.h, sys/kern/kern_mutex.c} +\begin{frame} +\frametitle{mutex(9) implementation} + +\end{frame} + + +\end{document} Modified: user/glebius/course/course.tex ============================================================================== --- user/glebius/course/course.tex Sun Oct 13 19:25:23 2013 (r256432) +++ user/glebius/course/course.tex Sun Oct 13 21:46:08 2013 (r256433) @@ -6,9 +6,14 @@ \definecolor{Dgrey}{HTML}{DDDDDD} \definecolor{Egrey}{HTML}{EEEEEE} +\definecolor{struct}{HTML}{999999} + % trace \setbeamercolor{trace}{fg=black,bg=Cgrey} +% source +\setbeamercolor{source}{fg=black,bg=Cgrey} + % terminal \setbeamercolor{terminal}{fg=white,bg=black} @@ -19,9 +24,9 @@ \newcommand{\Man}[2]{ \colorbox{white}{\color{man}#1(#2)} } -\setbeamercolor{manlabel}{fg=black,bg=man} +\setbeamercolor{manref}{fg=black,bg=man} \newcommand{\manlabel}[1]{ - \begin{beamercolorbox}[rounded=true,shadow=true,sep=0pt,colsep=0pt]{manlabel} + \begin{beamercolorbox}[rounded=true,shadow=true,sep=0pt,colsep=0pt]{manref} \small{#1} \end{beamercolorbox} } @@ -40,3 +45,40 @@ \small{#1} \end{beamercolorbox} } + +\tikzset { struct/.style = { + draw, thick, + rectangle split, + rectangle split part fill={struct!50, white!50}, +} } + +% +% Footnotes for source/manual references. +% +\newcommand\ManRefSw{} +\newcommand\SrcRefSw{} +\makeatletter +\newcommand*\FootReferences[2]{ + \renewcommand\ManRefSw{#1} + \renewcommand\SrcRefSw{#2} + \beamer@calculateheadfoot +} +\makeatother +\setbeamertemplate{footline}{% +\ifthenelse{\NOT \equal{\ManRefSw}{}} { + \begin{beamercolorbox} + [wd=\paperwidth,ht=2.25ex,dp=1ex,left]{manref}% + \hspace*{1em}Manual page(s): \ManRefSw + \end{beamercolorbox} + } + % else + {} +\ifthenelse{\NOT \equal{\SrcRefSw}{}} { + \begin{beamercolorbox} + [wd=\paperwidth,ht=2.25ex,dp=1ex,left]{srcref}% + \hspace*{1em}Source code reference: \SrcRefSw + \end{beamercolorbox} + } + % else + {} +} From owner-svn-src-user@FreeBSD.ORG Mon Oct 14 12:09:06 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id C91EB518; Mon, 14 Oct 2013 12:09:06 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 9C9BE21F8; Mon, 14 Oct 2013 12:09:06 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9EC96Ie073311; Mon, 14 Oct 2013 12:09:06 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9EC96cO073310; Mon, 14 Oct 2013 12:09:06 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310141209.r9EC96cO073310@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Mon, 14 Oct 2013 12:09:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256441 - user/ae/inet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Oct 2013 12:09:06 -0000 Author: ae Date: Mon Oct 14 12:09:06 2013 New Revision: 256441 URL: http://svnweb.freebsd.org/changeset/base/256441 Log: Cleanup. Deleted: user/ae/inet6/ From owner-svn-src-user@FreeBSD.ORG Mon Oct 14 12:11:20 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 40580A0B; Mon, 14 Oct 2013 12:11:20 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 164B32250; Mon, 14 Oct 2013 12:11:20 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9ECBJE5076613; Mon, 14 Oct 2013 12:11:19 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9ECBJpA076612; Mon, 14 Oct 2013 12:11:19 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310141211.r9ECBJpA076612@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Mon, 14 Oct 2013 12:11:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256442 - user/ae/inet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Oct 2013 12:11:20 -0000 Author: ae Date: Mon Oct 14 12:11:19 2013 New Revision: 256442 URL: http://svnweb.freebsd.org/changeset/base/256442 Log: Copy fresh head/ to my inet6 branch. Added: - copied from r256441, head/ Directory Properties: user/ae/inet6/ (props changed) From owner-svn-src-user@FreeBSD.ORG Mon Oct 14 22:42:14 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 19E69458; Mon, 14 Oct 2013 22:42:14 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id E0E2A2D69; Mon, 14 Oct 2013 22:42:13 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9EMgD7r008614; Mon, 14 Oct 2013 22:42:13 GMT (envelope-from eadler@svn.freebsd.org) Received: (from eadler@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9EMgDo0008613; Mon, 14 Oct 2013 22:42:13 GMT (envelope-from eadler@svn.freebsd.org) Message-Id: <201310142242.r9EMgDo0008613@svn.freebsd.org> From: Eitan Adler Date: Mon, 14 Oct 2013 22:42:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256468 - user/glebius/course/01.intro X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Oct 2013 22:42:14 -0000 Author: eadler Date: Mon Oct 14 22:42:13 2013 New Revision: 256468 URL: http://svnweb.freebsd.org/changeset/base/256468 Log: Fix minor English issues. Approved by: glebius Modified: user/glebius/course/01.intro/lection.tex Modified: user/glebius/course/01.intro/lection.tex ============================================================================== --- user/glebius/course/01.intro/lection.tex Mon Oct 14 22:39:08 2013 (r256467) +++ user/glebius/course/01.intro/lection.tex Mon Oct 14 22:42:13 2013 (r256468) @@ -60,7 +60,7 @@ \begin{frame} -\frametitle{Where it runs?} +\frametitle{Where does it run?} \begin{center} \begin{tabular}{ c c c } \includegraphics[width=3cm]{img/yahoo.png} & @@ -80,7 +80,7 @@ \begin{frame} -\frametitle{Where it runs?} +\frametitle{Where does it run?} \begin{center} \includegraphics[width=11cm]{img/pie.png} \end{center} @@ -157,7 +157,7 @@ % OS #1 \begin{frame} -\frametitle{What an OS actually is?} +\frametitle{What is an OS?} \begin{figure} \begin{tikzpicture}[font=\Large, node distance = 0.1 cm, block/.style = { rectangle, draw=black, thick, fill=white, @@ -178,7 +178,7 @@ % OS #2 \begin{frame} -\frametitle{What an OS actually is?} +\frametitle{What is an OS?} \begin{figure} \begin{tikzpicture}[font=\Large, node distance = 0.1 cm, block/.style = { rectangle, draw=black, thick, fill=white, @@ -201,7 +201,7 @@ % OS #3 \begin{frame} -\frametitle{What an OS actually is?} +\frametitle{What is an OS?} \begin{figure} \begin{tikzpicture}[font=\Large, node distance = 0.1 cm, block/.style = { rectangle, draw=black, thick, fill=white, @@ -226,7 +226,7 @@ % OS #4 \begin{frame} -\frametitle{What an OS actually is?} +\frametitle{What is an OS?} \begin{figure} \begin{tikzpicture}[font=\Large, node distance = 0.1 cm, block/.style = { rectangle, draw=black, thick, fill=white, @@ -255,7 +255,7 @@ % OS #5 \begin{frame} -\frametitle{What an OS actually is?} +\frametitle{What is an OS?} \begin{figure} \begin{tikzpicture}[font=\Large, node distance = 0.1 cm, block/.style = { rectangle, draw=black, thick, fill=white, From owner-svn-src-user@FreeBSD.ORG Tue Oct 15 08:04:26 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 322213BA; Tue, 15 Oct 2013 08:04:26 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 1FFB72B07; Tue, 15 Oct 2013 08:04:26 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9F84Pka013390; Tue, 15 Oct 2013 08:04:25 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9F84Pma013389; Tue, 15 Oct 2013 08:04:25 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310150804.r9F84Pma013389@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Tue, 15 Oct 2013 08:04:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256507 - user/ae/inet6/sys/netinet X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 08:04:26 -0000 Author: ae Date: Tue Oct 15 08:04:25 2013 New Revision: 256507 URL: http://svnweb.freebsd.org/changeset/base/256507 Log: Add scope zone id to the in_endpoints structure. Modified: user/ae/inet6/sys/netinet/in_pcb.h Modified: user/ae/inet6/sys/netinet/in_pcb.h ============================================================================== --- user/ae/inet6/sys/netinet/in_pcb.h Tue Oct 15 07:37:30 2013 (r256506) +++ user/ae/inet6/sys/netinet/in_pcb.h Tue Oct 15 08:04:25 2013 (r256507) @@ -94,6 +94,7 @@ struct in_endpoints { struct in_addr_4in6 ie46_local; struct in6_addr ie6_local; } ie_dependladdr; + u_int32_t ie6_zoneid; /* scope zone id */ }; #define ie_faddr ie_dependfaddr.ie46_foreign.ia46_addr4 #define ie_laddr ie_dependladdr.ie46_local.ia46_addr4 @@ -124,6 +125,7 @@ struct in_conninfo { #define inc_laddr inc_ie.ie_laddr #define inc6_faddr inc_ie.ie6_faddr #define inc6_laddr inc_ie.ie6_laddr +#define inc6_zoneid inc_ie.ie6_zoneid struct icmp6_filter; @@ -227,6 +229,7 @@ struct inpcb { #define in6p_faddr inp_inc.inc6_faddr #define in6p_laddr inp_inc.inc6_laddr +#define in6p_zoneid inp_inc.inc6_zoneid #define in6p_hops inp_depend6.inp6_hops /* default hop limit */ #define in6p_flowinfo inp_flow #define in6p_options inp_depend6.inp6_options From owner-svn-src-user@FreeBSD.ORG Tue Oct 15 08:20:21 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id D16766ED; Tue, 15 Oct 2013 08:20:21 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id A559F2BDA; Tue, 15 Oct 2013 08:20:21 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9F8KL5U024273; Tue, 15 Oct 2013 08:20:21 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9F8KLD5024265; Tue, 15 Oct 2013 08:20:21 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310150820.r9F8KLD5024265@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Tue, 15 Oct 2013 08:20:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256508 - user/ae/inet6/sys/netinet X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 08:20:21 -0000 Author: ae Date: Tue Oct 15 08:20:20 2013 New Revision: 256508 URL: http://svnweb.freebsd.org/changeset/base/256508 Log: It is possible, that many remote hosts have equal link-local addresses, but from different scope zones. Thus, they can have different tcp-specific metrics. Add ip6_zoneid field in addition to ip6 address to hc_metrics structure to be able handle this case. Modified: user/ae/inet6/sys/netinet/tcp_hostcache.c user/ae/inet6/sys/netinet/tcp_hostcache.h Modified: user/ae/inet6/sys/netinet/tcp_hostcache.c ============================================================================== --- user/ae/inet6/sys/netinet/tcp_hostcache.c Tue Oct 15 08:04:25 2013 (r256507) +++ user/ae/inet6/sys/netinet/tcp_hostcache.c Tue Oct 15 08:20:20 2013 (r256508) @@ -295,7 +295,8 @@ tcp_hc_lookup(struct in_conninfo *inc) TAILQ_FOREACH(hc_entry, &hc_head->hch_bucket, rmx_q) { if (inc->inc_flags & INC_ISIPV6) { if (memcmp(&inc->inc6_faddr, &hc_entry->ip6, - sizeof(inc->inc6_faddr)) == 0) + sizeof(inc->inc6_faddr)) == 0 && + hc_entry->ip6_zoneid == inc->inc6_zoneid) return hc_entry; } else { if (memcmp(&inc->inc_faddr, &hc_entry->ip4, @@ -385,9 +386,10 @@ tcp_hc_insert(struct in_conninfo *inc) * Initialize basic information of hostcache entry. */ bzero(hc_entry, sizeof(*hc_entry)); - if (inc->inc_flags & INC_ISIPV6) - bcopy(&inc->inc6_faddr, &hc_entry->ip6, sizeof(hc_entry->ip6)); - else + if (inc->inc_flags & INC_ISIPV6) { + hc_entry->ip6 = inc->inc6_faddr; + hc_entry->ip6_zoneid = inc->inc6_zoneid; + } else hc_entry->ip4 = inc->inc_faddr; hc_entry->rmx_head = hc_head; hc_entry->rmx_expire = V_tcp_hostcache.expire; Modified: user/ae/inet6/sys/netinet/tcp_hostcache.h ============================================================================== --- user/ae/inet6/sys/netinet/tcp_hostcache.h Tue Oct 15 08:04:25 2013 (r256507) +++ user/ae/inet6/sys/netinet/tcp_hostcache.h Tue Oct 15 08:20:20 2013 (r256508) @@ -51,6 +51,7 @@ struct hc_metrics { struct hc_head *rmx_head; /* head of bucket tail queue */ struct in_addr ip4; /* IP address */ struct in6_addr ip6; /* IP6 address */ + uint32_t ip6_zoneid; /* IPv6 scope zone id */ /* endpoint specific values for tcp */ u_long rmx_mtu; /* MTU for this path */ u_long rmx_ssthresh; /* outbound gateway buffer limit */ From owner-svn-src-user@FreeBSD.ORG Tue Oct 15 09:12:19 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 92563606; Tue, 15 Oct 2013 09:12:19 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 8037E2F08; Tue, 15 Oct 2013 09:12:19 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9F9CJw4057367; Tue, 15 Oct 2013 09:12:19 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9F9CIKA057363; Tue, 15 Oct 2013 09:12:18 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310150912.r9F9CIKA057363@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Tue, 15 Oct 2013 09:12:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256509 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 09:12:19 -0000 Author: ae Date: Tue Oct 15 09:12:18 2013 New Revision: 256509 URL: http://svnweb.freebsd.org/changeset/base/256509 Log: * Replace hardcoded number of scopes count with macro. * Simplify in6_addrscope() function. * Add several new scope related functions: in6_getlinkifnet() returns pointer to struct ifnet, corresponding to given link-local scope zone id. in6_getscopezone() returns zone id for given scope. sa6_checkzone() checks given sockaddr_in6 structure for correctness of sin6_scope_id field. Modified: user/ae/inet6/sys/netinet6/in6.h user/ae/inet6/sys/netinet6/scope6.c user/ae/inet6/sys/netinet6/scope6_var.h Modified: user/ae/inet6/sys/netinet6/in6.h ============================================================================== --- user/ae/inet6/sys/netinet6/in6.h Tue Oct 15 08:20:20 2013 (r256508) +++ user/ae/inet6/sys/netinet6/in6.h Tue Oct 15 09:12:18 2013 (r256509) @@ -638,7 +638,7 @@ int in6_cksum_pseudo(struct ip6_hdr *, u int in6_cksum(struct mbuf *, u_int8_t, u_int32_t, u_int32_t); int in6_localaddr(struct in6_addr *); int in6_localip(struct in6_addr *); -int in6_addrscope(struct in6_addr *); +int in6_addrscope(const struct in6_addr *); struct in6_ifaddr *in6_ifawithifp(struct ifnet *, struct in6_addr *); extern void in6_if_up(struct ifnet *); struct sockaddr; Modified: user/ae/inet6/sys/netinet6/scope6.c ============================================================================== --- user/ae/inet6/sys/netinet6/scope6.c Tue Oct 15 08:20:20 2013 (r256508) +++ user/ae/inet6/sys/netinet6/scope6.c Tue Oct 15 09:12:18 2013 (r256509) @@ -207,62 +207,15 @@ scope6_get(struct ifnet *ifp, struct sco * Get a scope of the address. Node-local, link-local, site-local or global. */ int -in6_addrscope(struct in6_addr *addr) +in6_addrscope(const struct in6_addr *addr) { - int scope; - - if (addr->s6_addr[0] == 0xfe) { - scope = addr->s6_addr[1] & 0xc0; - - switch (scope) { - case 0x80: - return IPV6_ADDR_SCOPE_LINKLOCAL; - break; - case 0xc0: - return IPV6_ADDR_SCOPE_SITELOCAL; - break; - default: - return IPV6_ADDR_SCOPE_GLOBAL; /* just in case */ - break; - } - } - - - if (addr->s6_addr[0] == 0xff) { - scope = addr->s6_addr[1] & 0x0f; - - /* - * due to other scope such as reserved, - * return scope doesn't work. - */ - switch (scope) { - case IPV6_ADDR_SCOPE_INTFACELOCAL: - return IPV6_ADDR_SCOPE_INTFACELOCAL; - break; - case IPV6_ADDR_SCOPE_LINKLOCAL: - return IPV6_ADDR_SCOPE_LINKLOCAL; - break; - case IPV6_ADDR_SCOPE_SITELOCAL: - return IPV6_ADDR_SCOPE_SITELOCAL; - break; - default: - return IPV6_ADDR_SCOPE_GLOBAL; - break; - } - } - - /* - * Regard loopback and unspecified addresses as global, since - * they have no ambiguity. - */ - if (bcmp(&in6addr_loopback, addr, sizeof(*addr) - 1) == 0) { - if (addr->s6_addr[15] == 1) /* loopback */ - return IPV6_ADDR_SCOPE_LINKLOCAL; - if (addr->s6_addr[15] == 0) /* unspecified */ - return IPV6_ADDR_SCOPE_GLOBAL; /* XXX: correct? */ - } - return IPV6_ADDR_SCOPE_GLOBAL; + if (IN6_IS_ADDR_MULTICAST(addr)) + return (IPV6_ADDR_MC_SCOPE(addr)); + if (IN6_IS_ADDR_LINKLOCAL(addr) || + IN6_IS_ADDR_LOOPBACK(addr)) + return (IPV6_ADDR_SCOPE_LINKLOCAL); + return (IPV6_ADDR_SCOPE_GLOBAL); } /* @@ -477,3 +430,72 @@ in6_getscope(struct in6_addr *in6) return (0); } + +/* + * Return pointer to ifnet structure, corresponding to the + * link-local scope zone id. + */ +struct ifnet* +in6_getlinkifnet(uint32_t zoneid) +{ + + return (ifnet_byindex((u_short)zoneid)); +} + +/* + * Return zone id for the specified scope. + * XXX: currently we don't take any locks. + */ +uint32_t +in6_getscopezone(const struct ifnet *ifp, int scope) +{ + + if (scope == IPV6_ADDR_SCOPE_INTFACELOCAL || + scope == IPV6_ADDR_SCOPE_LINKLOCAL) + return (ifp->if_index); + if (scope >= 0 && scope < IPV6_ADDR_SCOPES_COUNT) + return (SID(ifp)->s6id_list[scope]); + return (0); +} + +/* + * This function is for checking sockaddr_in6 structure passed + * from the application level (usually). + * + * sin6_scope_id should be set for link-local unicast addresses and for + * any multicast addresses. + * If it is zero, then look into default zone ids. If default zone id is + * not set or disabled, then return error. + */ +int +sa6_checkzone(struct sockaddr_in6 *sa6) +{ + int scope; + + scope = in6_addrscope(&sa6->sin6_addr); + if (!IN6_IS_ADDR_MULTICAST(&sa6->sin6_addr)) { + if (scope == IPV6_ADDR_SCOPE_GLOBAL) + return (sa6->sin6_scope_id ? EINVAL: 0); + /* + * Since ::1 address always configured on the lo0, we can + * automatically set its zone id, when it is not specified. + * Return error, when specified zone id doesn't match with + * actual value. + */ + if (IN6_IS_ADDR_LOOPBACK(&sa6->sin6_addr)) { + if (sa6->sin6_scope_id == 0) + sa6->sin6_scope_id = in6_getscopezone( + V_loif, IPV6_ADDR_SCOPE_LINKLOCAL); + else if (sa6->sin6_scope_id != in6_getscopezone( + V_loif, IPV6_ADDR_SCOPE_LINKLOCAL)) + return (EADDRNOTAVAIL); + } + } + /* Any multicast and link-local addresses. */ + if (sa6->sin6_scope_id != 0) + return (0); + if (V_ip6_use_defzone != 0) + sa6->sin6_scope_id = V_sid_default.s6id_list[scope]; + /* Return error if we can't determine zone id */ + return (sa6->sin6_scope_id ? 0: EADDRNOTAVAIL); +} Modified: user/ae/inet6/sys/netinet6/scope6_var.h ============================================================================== --- user/ae/inet6/sys/netinet6/scope6_var.h Tue Oct 15 08:20:20 2013 (r256508) +++ user/ae/inet6/sys/netinet6/scope6_var.h Tue Oct 15 09:12:18 2013 (r256509) @@ -35,13 +35,14 @@ #ifdef _KERNEL #include +#define IPV6_ADDR_SCOPES_COUNT 16 struct scope6_id { /* * 16 is correspondent to 4bit multicast scope field. * i.e. from node-local to global with some reserved/unassigned types. */ - u_int32_t s6id_list[16]; + uint32_t s6id_list[IPV6_ADDR_SCOPES_COUNT]; }; VNET_DECLARE(int, deembed_scopeid); @@ -57,9 +58,12 @@ int scope6_get_default(struct scope6_id u_int32_t scope6_addr2default(struct in6_addr *); int sa6_embedscope(struct sockaddr_in6 *, int); int sa6_recoverscope(struct sockaddr_in6 *); +int sa6_checkzone(struct sockaddr_in6 *); int in6_setscope(struct in6_addr *, struct ifnet *, u_int32_t *); int in6_clearscope(struct in6_addr *); uint16_t in6_getscope(struct in6_addr *); +uint32_t in6_getscopezone(const struct ifnet *, int); +struct ifnet* in6_getlinkifnet(uint32_t); #endif /* _KERNEL */ #endif /* _NETINET6_SCOPE6_VAR_H_ */ From owner-svn-src-user@FreeBSD.ORG Tue Oct 15 10:01:16 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 507B153C; Tue, 15 Oct 2013 10:01:16 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 2E90821B1; Tue, 15 Oct 2013 10:01:16 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9FA1GaN088621; Tue, 15 Oct 2013 10:01:16 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9FA1FcZ088610; Tue, 15 Oct 2013 10:01:15 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310151001.r9FA1FcZ088610@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Tue, 15 Oct 2013 10:01:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256513 - in user/ae/inet6/sys: netinet netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 10:01:16 -0000 Author: ae Date: Tue Oct 15 10:01:15 2013 New Revision: 256513 URL: http://svnweb.freebsd.org/changeset/base/256513 Log: Simplify tcp6_connect(). Also make in6_pcblookup_hash_locked() and in6_pcbladdr() functions static. Modified: user/ae/inet6/sys/netinet/tcp_usrreq.c user/ae/inet6/sys/netinet6/in6_pcb.c user/ae/inet6/sys/netinet6/in6_pcb.h Modified: user/ae/inet6/sys/netinet/tcp_usrreq.c ============================================================================== --- user/ae/inet6/sys/netinet/tcp_usrreq.c Tue Oct 15 09:55:07 2013 (r256512) +++ user/ae/inet6/sys/netinet/tcp_usrreq.c Tue Oct 15 10:01:15 2013 (r256513) @@ -1168,10 +1168,7 @@ out: static int tcp6_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td) { - struct inpcb *inp = tp->t_inpcb, *oinp; - struct socket *so = inp->inp_socket; - struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)nam; - struct in6_addr addr6; + struct inpcb *inp = tp->t_inpcb; int error; INP_WLOCK_ASSERT(inp); @@ -1182,39 +1179,9 @@ tcp6_connect(struct tcpcb *tp, struct so if (error) goto out; } - - /* - * Cannot simply call in_pcbconnect, because there might be an - * earlier incarnation of this same connection still in - * TIME_WAIT state, creating an ADDRINUSE error. - * in6_pcbladdr() also handles scope zone IDs. - * - * XXXRW: We wouldn't need to expose in6_pcblookup_hash_locked() - * outside of in6_pcb.c if there were an in6_pcbconnect_setup(). - */ - error = in6_pcbladdr(inp, nam, &addr6); - if (error) - goto out; - oinp = in6_pcblookup_hash_locked(inp->inp_pcbinfo, - &sin6->sin6_addr, sin6->sin6_port, - IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr) - ? &addr6 - : &inp->in6p_laddr, - inp->inp_lport, 0, NULL); - if (oinp) { - error = EADDRINUSE; + error = in6_pcbconnect(inp, nam, td->td_ucred); + if (error != 0) goto out; - } - if (IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)) - inp->in6p_laddr = addr6; - inp->in6p_faddr = sin6->sin6_addr; - inp->inp_fport = sin6->sin6_port; - /* update flowinfo - draft-itojun-ipv6-flowlabel-api-00 */ - inp->inp_flow &= ~IPV6_FLOWLABEL_MASK; - if (inp->inp_flags & IN6P_AUTOFLOWLABEL) - inp->inp_flow |= - (htonl(ip6_randomflowlabel()) & IPV6_FLOWLABEL_MASK); - in_pcbrehash(inp); INP_HASH_WUNLOCK(&V_tcbinfo); /* Compute window scaling to request. */ @@ -1222,7 +1189,7 @@ tcp6_connect(struct tcpcb *tp, struct so (TCP_MAXWIN << tp->request_r_scale) < sb_max) tp->request_r_scale++; - soisconnecting(so); + soisconnecting(inp->inp_socket); TCPSTAT_INC(tcps_connattempt); tcp_state_change(tp, TCPS_SYN_SENT); tp->iss = tcp_new_isn(tp); Modified: user/ae/inet6/sys/netinet6/in6_pcb.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6_pcb.c Tue Oct 15 09:55:07 2013 (r256512) +++ user/ae/inet6/sys/netinet6/in6_pcb.c Tue Oct 15 10:01:15 2013 (r256513) @@ -106,6 +106,9 @@ __FBSDID("$FreeBSD$"); #include #include +static struct inpcb *in6_pcblookup_hash_locked(struct inpcbinfo *, + struct in6_addr *, u_int, struct in6_addr *, u_int, int, struct ifnet *); + int in6_pcbbind(register struct inpcb *inp, struct sockaddr *nam, struct ucred *cred) @@ -302,7 +305,7 @@ in6_pcbbind(register struct inpcb *inp, * a bit of a kludge, but cleaning up the internal interfaces would * have forced minor changes in every protocol). */ -int +static int in6_pcbladdr(register struct inpcb *inp, struct sockaddr *nam, struct in6_addr *plocal_addr6) { @@ -975,7 +978,7 @@ found: /* * Lookup PCB in hash list. */ -struct inpcb * +static struct inpcb * in6_pcblookup_hash_locked(struct inpcbinfo *pcbinfo, struct in6_addr *faddr, u_int fport_arg, struct in6_addr *laddr, u_int lport_arg, int lookupflags, struct ifnet *ifp) Modified: user/ae/inet6/sys/netinet6/in6_pcb.h ============================================================================== --- user/ae/inet6/sys/netinet6/in6_pcb.h Tue Oct 15 09:55:07 2013 (r256512) +++ user/ae/inet6/sys/netinet6/in6_pcb.h Tue Oct 15 10:01:15 2013 (r256513) @@ -86,7 +86,6 @@ int in6_pcbconnect(struct inpcb *, struc int in6_pcbconnect_mbuf(struct inpcb *, struct sockaddr *, struct ucred *, struct mbuf *); void in6_pcbdisconnect(struct inpcb *); -int in6_pcbladdr(struct inpcb *, struct sockaddr *, struct in6_addr *); struct inpcb * in6_pcblookup_local(struct inpcbinfo *, struct in6_addr *, u_short, int, @@ -96,10 +95,6 @@ struct inpcb * u_int, struct in6_addr *, u_int, int, struct ifnet *); struct inpcb * - in6_pcblookup_hash_locked(struct inpcbinfo *, struct in6_addr *, - u_int, struct in6_addr *, u_int, int, - struct ifnet *); -struct inpcb * in6_pcblookup_mbuf(struct inpcbinfo *, struct in6_addr *, u_int, struct in6_addr *, u_int, int, struct ifnet *ifp, struct mbuf *); From owner-svn-src-user@FreeBSD.ORG Tue Oct 15 10:37:51 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 569AC5D8; Tue, 15 Oct 2013 10:37:51 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 435DF23C4; Tue, 15 Oct 2013 10:37:51 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9FAbpW0010476; Tue, 15 Oct 2013 10:37:51 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9FAboTS010471; Tue, 15 Oct 2013 10:37:50 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310151037.r9FAboTS010471@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Tue, 15 Oct 2013 10:37:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256520 - in user/ae/inet6/sys: netinet netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 10:37:51 -0000 Author: ae Date: Tue Oct 15 10:37:50 2013 New Revision: 256520 URL: http://svnweb.freebsd.org/changeset/base/256520 Log: Add zoneid argument to the in6_sockaddr() function. Modified: user/ae/inet6/sys/netinet/tcp_usrreq.c user/ae/inet6/sys/netinet6/in6_pcb.c user/ae/inet6/sys/netinet6/in6_pcb.h Modified: user/ae/inet6/sys/netinet/tcp_usrreq.c ============================================================================== --- user/ae/inet6/sys/netinet/tcp_usrreq.c Tue Oct 15 10:31:42 2013 (r256519) +++ user/ae/inet6/sys/netinet/tcp_usrreq.c Tue Oct 15 10:37:50 2013 (r256520) @@ -663,12 +663,13 @@ out: static int tcp6_usr_accept(struct socket *so, struct sockaddr **nam) { + struct in6_addr addr6; + struct in_addr addr; struct inpcb *inp = NULL; - int error = 0; struct tcpcb *tp = NULL; - struct in_addr addr; - struct in6_addr addr6; + uint32_t zoneid = 0; in_port_t port = 0; + int error = 0; int v4 = 0; TCPDEBUG0; @@ -698,6 +699,7 @@ tcp6_usr_accept(struct socket *so, struc } else { port = inp->inp_fport; addr6 = inp->in6p_faddr; + zoneid = inp->in6p_zoneid; } out: @@ -708,9 +710,9 @@ out: if (v4) *nam = in6_v4mapsin6_sockaddr(port, &addr); else - *nam = in6_sockaddr(port, &addr6); + *nam = in6_sockaddr(port, &addr6, zoneid); } - return error; + return (error); } #endif /* INET6 */ Modified: user/ae/inet6/sys/netinet6/in6_pcb.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6_pcb.c Tue Oct 15 10:31:42 2013 (r256519) +++ user/ae/inet6/sys/netinet6/in6_pcb.c Tue Oct 15 10:37:50 2013 (r256520) @@ -445,19 +445,19 @@ in6_pcbdisconnect(struct inpcb *inp) } struct sockaddr * -in6_sockaddr(in_port_t port, struct in6_addr *addr_p) +in6_sockaddr(in_port_t port, const struct in6_addr *addr_p, uint32_t zoneid) { struct sockaddr_in6 *sin6; - sin6 = malloc(sizeof *sin6, M_SONAME, M_WAITOK); - bzero(sin6, sizeof *sin6); + sin6 = malloc(sizeof *sin6, M_SONAME, M_WAITOK | M_ZERO); sin6->sin6_family = AF_INET6; sin6->sin6_len = sizeof(*sin6); sin6->sin6_port = port; sin6->sin6_addr = *addr_p; - (void)sa6_recoverscope(sin6); /* XXX: should catch errors */ - - return (struct sockaddr *)sin6; + if (IN6_IS_ADDR_LINKLOCAL(addr_p) || + IN6_IS_ADDR_MULTICAST(addr_p)) + sin6->sin6_scope_id = zoneid; + return ((struct sockaddr *)sin6); } struct sockaddr * @@ -482,8 +482,9 @@ in6_v4mapsin6_sockaddr(in_port_t port, s int in6_getsockaddr(struct socket *so, struct sockaddr **nam) { - register struct inpcb *inp; struct in6_addr addr; + struct inpcb *inp; + uint32_t zoneid; in_port_t port; inp = sotoinpcb(so); @@ -492,17 +493,19 @@ in6_getsockaddr(struct socket *so, struc INP_RLOCK(inp); port = inp->inp_lport; addr = inp->in6p_laddr; + zoneid = inp->in6p_zoneid; INP_RUNLOCK(inp); - *nam = in6_sockaddr(port, &addr); - return 0; + *nam = in6_sockaddr(port, &addr, zoneid); + return (0); } int in6_getpeeraddr(struct socket *so, struct sockaddr **nam) { - struct inpcb *inp; struct in6_addr addr; + struct inpcb *inp; + uint32_t zoneid; in_port_t port; inp = sotoinpcb(so); @@ -511,10 +514,11 @@ in6_getpeeraddr(struct socket *so, struc INP_RLOCK(inp); port = inp->inp_fport; addr = inp->in6p_faddr; + zoneid = inp->in6p_zoneid; INP_RUNLOCK(inp); - *nam = in6_sockaddr(port, &addr); - return 0; + *nam = in6_sockaddr(port, &addr, zoneid); + return (0); } int Modified: user/ae/inet6/sys/netinet6/in6_pcb.h ============================================================================== --- user/ae/inet6/sys/netinet6/in6_pcb.h Tue Oct 15 10:31:42 2013 (r256519) +++ user/ae/inet6/sys/netinet6/in6_pcb.h Tue Oct 15 10:37:50 2013 (r256520) @@ -104,7 +104,7 @@ void in6_pcbnotify(struct inpcbinfo *, s struct inpcb * in6_rtchange(struct inpcb *, int); struct sockaddr * - in6_sockaddr(in_port_t port, struct in6_addr *addr_p); + in6_sockaddr(in_port_t, const struct in6_addr *, uint32_t); struct sockaddr * in6_v4mapsin6_sockaddr(in_port_t port, struct in_addr *addr_p); int in6_getpeeraddr(struct socket *so, struct sockaddr **nam); From owner-svn-src-user@FreeBSD.ORG Tue Oct 15 11:18:37 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id D7D26241; Tue, 15 Oct 2013 11:18:37 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id C63F92620; Tue, 15 Oct 2013 11:18:37 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9FBIbIa040815; Tue, 15 Oct 2013 11:18:37 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9FBIbLK040814; Tue, 15 Oct 2013 11:18:37 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310151118.r9FBIbLK040814@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Tue, 15 Oct 2013 11:18:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256523 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 11:18:37 -0000 Author: ae Date: Tue Oct 15 11:18:37 2013 New Revision: 256523 URL: http://svnweb.freebsd.org/changeset/base/256523 Log: Constify argument of in6_addrhash(). Modified: user/ae/inet6/sys/netinet6/in6_var.h Modified: user/ae/inet6/sys/netinet6/in6_var.h ============================================================================== --- user/ae/inet6/sys/netinet6/in6_var.h Tue Oct 15 10:43:26 2013 (r256522) +++ user/ae/inet6/sys/netinet6/in6_var.h Tue Oct 15 11:18:37 2013 (r256523) @@ -530,7 +530,7 @@ VNET_DECLARE(u_long, in6_ifaddrhmask); (&V_in6_ifaddrhashtbl[IN6ADDR_HASHVAL(x) & V_in6_ifaddrhmask]) static __inline uint32_t -in6_addrhash(struct in6_addr *in6) +in6_addrhash(const struct in6_addr *in6) { uint32_t x; From owner-svn-src-user@FreeBSD.ORG Tue Oct 15 11:25:12 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id F09C13D3; Tue, 15 Oct 2013 11:25:12 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id C323C268E; Tue, 15 Oct 2013 11:25:12 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9FBPClJ045641; Tue, 15 Oct 2013 11:25:12 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9FBPCiS045639; Tue, 15 Oct 2013 11:25:12 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310151125.r9FBPCiS045639@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Tue, 15 Oct 2013 11:25:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256524 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 11:25:13 -0000 Author: ae Date: Tue Oct 15 11:25:12 2013 New Revision: 256524 URL: http://svnweb.freebsd.org/changeset/base/256524 Log: Add in6ifa_ifwithaddr() function. It is similar to ifa_ifwithaddr, but uses in6_addr hash for fast lookup. Modified: user/ae/inet6/sys/netinet6/in6.c user/ae/inet6/sys/netinet6/in6_var.h Modified: user/ae/inet6/sys/netinet6/in6.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6.c Tue Oct 15 11:18:37 2013 (r256523) +++ user/ae/inet6/sys/netinet6/in6.c Tue Oct 15 11:25:12 2013 (r256524) @@ -1976,6 +1976,29 @@ in6ifa_ifpforlinklocal(struct ifnet *ifp /* + * find the internet address corresponding to a given address. + * ifaddr is returned referenced. + */ +struct in6_ifaddr * +in6ifa_ifwithaddr(const struct in6_addr *addr, uint32_t zoneid) +{ + struct in6_ifaddr *ia; + + IN6_IFADDR_RLOCK(); + LIST_FOREACH(ia, IN6ADDR_HASH(addr), ia6_hash) { + if (IN6_ARE_ADDR_EQUAL(IA6_IN6(ia), addr)) { + if (zoneid != 0 && + zoneid != ia->ia_addr.sin6_scope_id) + continue; + ifa_ref(&ia->ia_ifa); + break; + } + } + IN6_IFADDR_RUNLOCK(); + return (ia); +} + +/* * find the internet address corresponding to a given interface and address. * ifaddr is returned referenced. */ Modified: user/ae/inet6/sys/netinet6/in6_var.h ============================================================================== --- user/ae/inet6/sys/netinet6/in6_var.h Tue Oct 15 11:18:37 2013 (r256523) +++ user/ae/inet6/sys/netinet6/in6_var.h Tue Oct 15 11:25:12 2013 (r256524) @@ -814,6 +814,7 @@ void in6_setmaxmtu(void); int in6_if2idlen(struct ifnet *); struct in6_ifaddr *in6ifa_ifpforlinklocal(struct ifnet *, int); struct in6_ifaddr *in6ifa_ifpwithaddr(struct ifnet *, struct in6_addr *); +struct in6_ifaddr *in6ifa_ifwithaddr(const struct in6_addr *, uint32_t); struct in6_ifaddr *in6ifa_llaonifp(struct ifnet *); char *ip6_sprintf(char *, const struct in6_addr *); int in6_addr2zoneid(struct ifnet *, struct in6_addr *, u_int32_t *); From owner-svn-src-user@FreeBSD.ORG Tue Oct 15 12:02:06 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 51DEAFE; Tue, 15 Oct 2013 12:02:06 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 2EF0E2B4A; Tue, 15 Oct 2013 12:02:06 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9FC26Zb069616; Tue, 15 Oct 2013 12:02:06 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9FC26ZU069615; Tue, 15 Oct 2013 12:02:06 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310151202.r9FC26ZU069615@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Tue, 15 Oct 2013 12:02:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256526 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 12:02:06 -0000 Author: ae Date: Tue Oct 15 12:02:05 2013 New Revision: 256526 URL: http://svnweb.freebsd.org/changeset/base/256526 Log: Some cleanups in in6_pcbbind(): * remove register keyword; * sort variables declarations; * use sa6_checkzone() to check sockaddr_in6 structure; * use in6ifa_ifwithaddr() function; * remove sa6_embedscope() call. Modified: user/ae/inet6/sys/netinet6/in6_pcb.c Modified: user/ae/inet6/sys/netinet6/in6_pcb.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6_pcb.c Tue Oct 15 11:37:57 2013 (r256525) +++ user/ae/inet6/sys/netinet6/in6_pcb.c Tue Oct 15 12:02:05 2013 (r256526) @@ -110,21 +110,18 @@ static struct inpcb *in6_pcblookup_hash_ struct in6_addr *, u_int, struct in6_addr *, u_int, int, struct ifnet *); int -in6_pcbbind(register struct inpcb *inp, struct sockaddr *nam, - struct ucred *cred) +in6_pcbbind(struct inpcb *inp, struct sockaddr *nam, struct ucred *cred) { struct socket *so = inp->inp_socket; - struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)NULL; + struct sockaddr_in6 *sin6 = NULL; struct inpcbinfo *pcbinfo = inp->inp_pcbinfo; - u_short lport = 0; int error, lookupflags = 0; int reuseport = (so->so_options & SO_REUSEPORT); + u_short lport = 0; INP_WLOCK_ASSERT(inp); INP_HASH_WLOCK_ASSERT(pcbinfo); - if (TAILQ_EMPTY(&V_in6_ifaddrhead)) /* XXX broken! */ - return (EADDRNOTAVAIL); if (inp->inp_lport || !IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)) return (EINVAL); if ((so->so_options & (SO_REUSEADDR|SO_REUSEPORT)) == 0) @@ -137,14 +134,11 @@ in6_pcbbind(register struct inpcb *inp, sin6 = (struct sockaddr_in6 *)nam; if (nam->sa_len != sizeof(*sin6)) return (EINVAL); - /* - * family check. - */ if (nam->sa_family != AF_INET6) return (EAFNOSUPPORT); - - if ((error = sa6_embedscope(sin6, V_ip6_use_defzone)) != 0) - return(error); + /* Check sin6_scope_id. The caller must set it properly. */ + if ((error = sa6_checkzone(sin6)) != 0) + return (error); if ((error = prison_local_ip6(cred, &sin6->sin6_addr, ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0))) != 0) @@ -162,11 +156,11 @@ in6_pcbbind(register struct inpcb *inp, if ((so->so_options & (SO_REUSEADDR|SO_REUSEPORT)) != 0) reuseport = SO_REUSEADDR|SO_REUSEPORT; } else if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { - struct ifaddr *ifa; + struct in6_ifaddr *ifa; - sin6->sin6_port = 0; /* yech... */ - if ((ifa = ifa_ifwithaddr((struct sockaddr *)sin6)) == - NULL && + ifa = in6ifa_ifwithaddr(&sin6->sin6_addr, + sin6->sin6_scope_id); + if (ifa != NULL && (inp->inp_flags & INP_BINDANY) == 0) { return (EADDRNOTAVAIL); } @@ -177,14 +171,13 @@ in6_pcbbind(register struct inpcb *inp, * We should allow to bind to a deprecated address, since * the application dares to use it. */ - if (ifa != NULL && - ((struct in6_ifaddr *)ifa)->ia6_flags & - (IN6_IFF_ANYCAST|IN6_IFF_NOTREADY|IN6_IFF_DETACHED)) { - ifa_free(ifa); + if (ifa != NULL && (ifa->ia6_flags & (IN6_IFF_ANYCAST | + IN6_IFF_NOTREADY | IN6_IFF_DETACHED))) { + ifa_free(&ifa->ia_ifa); return (EADDRNOTAVAIL); } if (ifa != NULL) - ifa_free(ifa); + ifa_free(&ifa->ia_ifa); } if (lport) { struct inpcb *t; From owner-svn-src-user@FreeBSD.ORG Tue Oct 15 12:28:25 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id D9878FB2; Tue, 15 Oct 2013 12:28:25 +0000 (UTC) (envelope-from ray@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id C610D2DCF; Tue, 15 Oct 2013 12:28:25 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9FCSPUl085211; Tue, 15 Oct 2013 12:28:25 GMT (envelope-from ray@svn.freebsd.org) Received: (from ray@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9FCSO8o085202; Tue, 15 Oct 2013 12:28:24 GMT (envelope-from ray@svn.freebsd.org) Message-Id: <201310151228.r9FCSO8o085202@svn.freebsd.org> From: Aleksandr Rybalko Date: Tue, 15 Oct 2013 12:28:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256527 - in user/ed/newcons/sys/dev/vt: . hw/intel hw/ofwfb hw/vga hw/xboxfb X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 12:28:25 -0000 Author: ray Date: Tue Oct 15 12:28:24 2013 New Revision: 256527 URL: http://svnweb.freebsd.org/changeset/base/256527 Log: o Rename bitblt method to bitbltchr, since it used to copy char with bg/fg colors from font table, but not bitmap copy. o Fix small mistake in comment. Sponsored by: The FreeBSD Foundation Modified: user/ed/newcons/sys/dev/vt/hw/intel/intel.c user/ed/newcons/sys/dev/vt/hw/ofwfb/ofwfb.c user/ed/newcons/sys/dev/vt/hw/vga/vga.c user/ed/newcons/sys/dev/vt/hw/xboxfb/xboxfb.c user/ed/newcons/sys/dev/vt/vt.h user/ed/newcons/sys/dev/vt/vt_core.c Modified: user/ed/newcons/sys/dev/vt/hw/intel/intel.c ============================================================================== --- user/ed/newcons/sys/dev/vt/hw/intel/intel.c Tue Oct 15 12:02:05 2013 (r256526) +++ user/ed/newcons/sys/dev/vt/hw/intel/intel.c Tue Oct 15 12:28:24 2013 (r256527) @@ -60,11 +60,11 @@ static device_method_t intel_methods[] = }; static vd_init_t intel_vtinit; -static vd_bitblt_t intel_vtbitblt; +static vd_bitbltchr_t intel_vtbitbltchr; static struct vt_driver intel_vtops = { .vd_init = intel_vtinit, - .vd_bitblt = intel_vtbitblt, + .vd_bitbltchr = intel_vtbitbltchr, /* Prefer to use KMS, so GENERIC - 10 */ .vd_priority = VD_PRIORITY_GENERIC - 10, }; @@ -150,7 +150,7 @@ intel_vtinit(struct vt_device *vd) } static void -intel_vtbitblt(struct vt_device *vd, const uint8_t *src, +intel_vtbitbltchr(struct vt_device *vd, const uint8_t *src, vt_axis_t top, vt_axis_t left, unsigned int width, unsigned int height, term_color_t fg, term_color_t bg) { Modified: user/ed/newcons/sys/dev/vt/hw/ofwfb/ofwfb.c ============================================================================== --- user/ed/newcons/sys/dev/vt/hw/ofwfb/ofwfb.c Tue Oct 15 12:02:05 2013 (r256526) +++ user/ed/newcons/sys/dev/vt/hw/ofwfb/ofwfb.c Tue Oct 15 12:28:24 2013 (r256527) @@ -59,12 +59,12 @@ struct ofwfb_softc { static vd_init_t ofwfb_init; static vd_blank_t ofwfb_blank; -static vd_bitblt_t ofwfb_bitblt; +static vd_bitbltchr_t ofwfb_bitbltchr; static const struct vt_driver vt_ofwfb_driver = { .vd_init = ofwfb_init, .vd_blank = ofwfb_blank, - .vd_bitblt = ofwfb_bitblt, + .vd_bitbltchr = ofwfb_bitbltchr, .vd_priority = VD_PRIORITY_GENERIC, }; @@ -116,7 +116,7 @@ ofwfb_blank(struct vt_device *vd, term_c } static void -ofwfb_bitblt(struct vt_device *vd, const uint8_t *src, +ofwfb_bitbltchr(struct vt_device *vd, const uint8_t *src, vt_axis_t top, vt_axis_t left, unsigned int width, unsigned int height, term_color_t fg, term_color_t bg) { Modified: user/ed/newcons/sys/dev/vt/hw/vga/vga.c ============================================================================== --- user/ed/newcons/sys/dev/vt/hw/vga/vga.c Tue Oct 15 12:02:05 2013 (r256526) +++ user/ed/newcons/sys/dev/vt/hw/vga/vga.c Tue Oct 15 12:28:24 2013 (r256527) @@ -73,13 +73,13 @@ struct vga_softc { static vd_init_t vga_init; static vd_blank_t vga_blank; -static vd_bitblt_t vga_bitblt; +static vd_bitbltchr_t vga_bitbltchr; static vd_putchar_t vga_putchar; static const struct vt_driver vt_vga_driver = { .vd_init = vga_init, .vd_blank = vga_blank, - .vd_bitblt = vga_bitblt, + .vd_bitbltchr = vga_bitbltchr, .vd_putchar = vga_putchar, .vd_priority = VD_PRIORITY_GENERIC, }; @@ -169,7 +169,7 @@ vga_bitblt_draw(struct vt_device *vd, co } static void -vga_bitblt(struct vt_device *vd, const uint8_t *src, +vga_bitbltchr(struct vt_device *vd, const uint8_t *src, vt_axis_t top, vt_axis_t left, unsigned int width, unsigned int height, term_color_t fg, term_color_t bg) { Modified: user/ed/newcons/sys/dev/vt/hw/xboxfb/xboxfb.c ============================================================================== --- user/ed/newcons/sys/dev/vt/hw/xboxfb/xboxfb.c Tue Oct 15 12:02:05 2013 (r256526) +++ user/ed/newcons/sys/dev/vt/hw/xboxfb/xboxfb.c Tue Oct 15 12:28:24 2013 (r256527) @@ -61,12 +61,12 @@ struct xbox_softc { static vd_init_t xbox_init; static vd_blank_t xbox_blank; -static vd_bitblt_t xbox_bitblt; +static vd_bitbltchr_t xbox_bitbltchr; static const struct vt_driver vt_xbox_driver = { .vd_init = xbox_init, .vd_blank = xbox_blank, - .vd_bitblt = xbox_bitblt, + .vd_bitbltchr = xbox_bitbltchr, .vd_priority = VD_PRIORITY_GENERIC, }; @@ -106,7 +106,7 @@ xbox_blank(struct vt_device *vd, term_co } static void -xbox_bitblt(struct vt_device *vd, const uint8_t *src, +xbox_bitbltchr(struct vt_device *vd, const uint8_t *src, vt_axis_t top, vt_axis_t left, unsigned int width, unsigned int height, term_color_t fg, term_color_t bg) { Modified: user/ed/newcons/sys/dev/vt/vt.h ============================================================================== --- user/ed/newcons/sys/dev/vt/vt.h Tue Oct 15 12:02:05 2013 (r256526) +++ user/ed/newcons/sys/dev/vt/vt.h Tue Oct 15 12:28:24 2013 (r256527) @@ -204,7 +204,7 @@ struct vt_window { /* * Per-device driver routines. * - * vd_bitblt is used when the driver operates in graphics mode, while + * vd_bitbltchr is used when the driver operates in graphics mode, while * vd_putchar is used when the driver operates in text mode * (VDF_TEXTMODE). */ @@ -212,7 +212,7 @@ struct vt_window { typedef int vd_init_t(struct vt_device *vd); typedef void vd_postswitch_t(struct vt_device *vd); typedef void vd_blank_t(struct vt_device *vd, term_color_t color); -typedef void vd_bitblt_t(struct vt_device *vd, const uint8_t *src, +typedef void vd_bitbltchr_t(struct vt_device *vd, const uint8_t *src, vt_axis_t top, vt_axis_t left, unsigned int width, unsigned int height, term_color_t fg, term_color_t bg); typedef void vd_putchar_t(struct vt_device *vd, term_char_t, @@ -224,7 +224,7 @@ struct vt_driver { /* Drawing. */ vd_blank_t *vd_blank; - vd_bitblt_t *vd_bitblt; + vd_bitbltchr_t *vd_bitbltchr; /* Text mode operation. */ vd_putchar_t *vd_putchar; Modified: user/ed/newcons/sys/dev/vt/vt_core.c ============================================================================== --- user/ed/newcons/sys/dev/vt/vt_core.c Tue Oct 15 12:02:05 2013 (r256526) +++ user/ed/newcons/sys/dev/vt/vt_core.c Tue Oct 15 12:28:24 2013 (r256527) @@ -585,7 +585,7 @@ vt_bitblt_char(struct vt_device *vd, str left = col * vf->vf_width + (vd->vd_width % vf->vf_width) / 2; - vd->vd_driver->vd_bitblt(vd, src, top, left, + vd->vd_driver->vd_bitbltchr(vd, src, top, left, vf->vf_width, vf->vf_height, fg, bg); } else { vd->vd_driver->vd_putchar(vd, TCHAR_CHARACTER(c), @@ -692,7 +692,7 @@ vtterm_splash(struct vt_device *vd) switch (vt_logo_depth) { case 1: /* XXX: Unhardcode colors! */ - vd->vd_driver->vd_bitblt(vd, vt_logo_image, top, left, + vd->vd_driver->vd_bitbltchr(vd, vt_logo_image, top, left, vt_logo_width, vt_logo_height, 0xf, 0x0); } vd->vd_flags |= VDF_SPLASH; @@ -1395,7 +1395,7 @@ vt_allocate(struct vt_driver *drv, void } vd = main_vd; - /* Stop vd_flash periodic task. */ + /* Stop vt_flush periodic task. */ if (vd->vd_curwindow != NULL) callout_drain(&vd->vd_timer); From owner-svn-src-user@FreeBSD.ORG Tue Oct 15 12:29:37 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 09C2020A; Tue, 15 Oct 2013 12:29:37 +0000 (UTC) (envelope-from ray@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id D1DF32DDE; Tue, 15 Oct 2013 12:29:36 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9FCTabh085896; Tue, 15 Oct 2013 12:29:36 GMT (envelope-from ray@svn.freebsd.org) Received: (from ray@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9FCTaDd085894; Tue, 15 Oct 2013 12:29:36 GMT (envelope-from ray@svn.freebsd.org) Message-Id: <201310151229.r9FCTaDd085894@svn.freebsd.org> From: Aleksandr Rybalko Date: Tue, 15 Oct 2013 12:29:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256528 - user/ed/newcons/sys/dev/drm2 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 12:29:37 -0000 Author: ray Date: Tue Oct 15 12:29:36 2013 New Revision: 256528 URL: http://svnweb.freebsd.org/changeset/base/256528 Log: Rename bitblt method to bitbltchr. Sponsored by: The FreeBSD Foundation Modified: user/ed/newcons/sys/dev/drm2/drm_fb_helper.c Modified: user/ed/newcons/sys/dev/drm2/drm_fb_helper.c ============================================================================== --- user/ed/newcons/sys/dev/drm2/drm_fb_helper.c Tue Oct 15 12:28:24 2013 (r256527) +++ user/ed/newcons/sys/dev/drm2/drm_fb_helper.c Tue Oct 15 12:29:36 2013 (r256528) @@ -51,14 +51,16 @@ struct vt_kms_softc { static vd_init_t vt_kms_init; static vd_blank_t vt_kms_blank; -static vd_bitblt_t vt_kms_bitblt; +static vd_bitbltchr_t vt_kms_bitbltchr; static vd_postswitch_t vt_kms_postswitch; +#if 0 static void vt_restore_fbdev_mode(void *, int); +#endif static struct vt_driver vt_vt_kms_driver = { .vd_init = vt_kms_init, .vd_blank = vt_kms_blank, - .vd_bitblt = vt_kms_bitblt, + .vd_bitbltchr = vt_kms_bitbltchr, .vd_postswitch = vt_kms_postswitch, }; @@ -112,7 +114,7 @@ vt_kms_blank(struct vt_device *vd, term_ } static void -vt_kms_bitblt(struct vt_device *vd, const uint8_t *src, +vt_kms_bitbltchr(struct vt_device *vd, const uint8_t *src, vt_axis_t top, vt_axis_t left, unsigned int width, unsigned int height, term_color_t fg, term_color_t bg) { @@ -165,11 +167,14 @@ vt_kms_init(struct vt_device *vd) /* Clear the screen. */ vt_kms_blank(vd, TC_BLACK); +#if 0 TASK_INIT(&sc->fb_mode_task, 0, vt_restore_fbdev_mode, vd); +#endif return (CN_INTERNAL); } +#if 0 /* Call restore out of vt(9) locks. */ static void vt_restore_fbdev_mode(void *arg, int pending) @@ -181,6 +186,7 @@ vt_restore_fbdev_mode(void *arg, int pen sc = vd->vd_softc; drm_fb_helper_restore_fbdev_mode(sc->fb_helper); } +#endif static void vt_kms_postswitch(struct vt_device *vd) @@ -188,7 +194,11 @@ vt_kms_postswitch(struct vt_device *vd) struct vt_kms_softc *sc; sc = vd->vd_softc; +#if 0 taskqueue_enqueue_fast(taskqueue_thread, &sc->fb_mode_task); +#else + drm_fb_helper_restore_fbdev_mode(sc->fb_helper); +#endif } static DRM_LIST_HEAD(kernel_fb_helper_list); From owner-svn-src-user@FreeBSD.ORG Tue Oct 15 12:31:31 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 965B033F; Tue, 15 Oct 2013 12:31:31 +0000 (UTC) (envelope-from ray@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 841B02E31; Tue, 15 Oct 2013 12:31:31 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9FCVVKt089122; Tue, 15 Oct 2013 12:31:31 GMT (envelope-from ray@svn.freebsd.org) Received: (from ray@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9FCVVxS089121; Tue, 15 Oct 2013 12:31:31 GMT (envelope-from ray@svn.freebsd.org) Message-Id: <201310151231.r9FCVVxS089121@svn.freebsd.org> From: Aleksandr Rybalko Date: Tue, 15 Oct 2013 12:31:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256529 - user/ed/newcons/sys/arm/freescale/imx X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 12:31:31 -0000 Author: ray Date: Tue Oct 15 12:31:31 2013 New Revision: 256529 URL: http://svnweb.freebsd.org/changeset/base/256529 Log: Rename bitblt method to bitbltchr. Sponsored by: The FreeBSD Foundation Modified: user/ed/newcons/sys/arm/freescale/imx/imx51_ipuv3_newcons.c Modified: user/ed/newcons/sys/arm/freescale/imx/imx51_ipuv3_newcons.c ============================================================================== --- user/ed/newcons/sys/arm/freescale/imx/imx51_ipuv3_newcons.c Tue Oct 15 12:29:36 2013 (r256528) +++ user/ed/newcons/sys/arm/freescale/imx/imx51_ipuv3_newcons.c Tue Oct 15 12:31:31 2013 (r256529) @@ -145,12 +145,12 @@ static uint32_t colors_24[16] = { static vd_init_t vt_imx_init; static vd_blank_t vt_imx_blank; -static vd_bitblt_t vt_imx_bitblt; +static vd_bitbltchr_t vt_imx_bitbltchr; static struct vt_driver vt_imx_driver = { .vd_init = vt_imx_init, .vd_blank = vt_imx_blank, - .vd_bitblt = vt_imx_bitblt, + .vd_bitbltchr = vt_imx_bitbltchr, }; static const uint32_t colormap[] = { @@ -452,7 +452,7 @@ vt_imx_blank(struct vt_device *vd, term_ } static void -vt_imx_bitblt(struct vt_device *vd, const uint8_t *src, +vt_imx_bitbltchr(struct vt_device *vd, const uint8_t *src, vt_axis_t top, vt_axis_t left, unsigned int width, unsigned int height, term_color_t fg, term_color_t bg) { From owner-svn-src-user@FreeBSD.ORG Tue Oct 15 12:54:48 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id DDBE7D92; Tue, 15 Oct 2013 12:54:47 +0000 (UTC) (envelope-from ray@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id BBC162056; Tue, 15 Oct 2013 12:54:47 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9FCslq6003093; Tue, 15 Oct 2013 12:54:47 GMT (envelope-from ray@svn.freebsd.org) Received: (from ray@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9FCslUs003090; Tue, 15 Oct 2013 12:54:47 GMT (envelope-from ray@svn.freebsd.org) Message-Id: <201310151254.r9FCslUs003090@svn.freebsd.org> From: Aleksandr Rybalko Date: Tue, 15 Oct 2013 12:54:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256530 - user/ed/newcons/sys/dev/vt/colors X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 12:54:48 -0000 Author: ray Date: Tue Oct 15 12:54:47 2013 New Revision: 256530 URL: http://svnweb.freebsd.org/changeset/base/256530 Log: Add helper to generate color map. Sponsored by: The FreeBSD Foundation Added: user/ed/newcons/sys/dev/vt/colors/ user/ed/newcons/sys/dev/vt/colors/vt_termcolors.c (contents, props changed) user/ed/newcons/sys/dev/vt/colors/vt_termcolors.h (contents, props changed) Added: user/ed/newcons/sys/dev/vt/colors/vt_termcolors.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/ed/newcons/sys/dev/vt/colors/vt_termcolors.c Tue Oct 15 12:54:47 2013 (r256530) @@ -0,0 +1,80 @@ +/*- + * Copyright (c) 2013 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Aleksandr Rybalko under sponsorship from the + * FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include + +#include + +static struct { + unsigned char r; /* Red percentage value. */ + unsigned char g; /* Green percentage value. */ + unsigned char b; /* Blue percentage value. */ +} color_def[16] = { + {0, 0, 0}, /* black */ + {0, 0, 50}, /* dark blue */ + {0, 50, 0}, /* dark green */ + {0, 50, 50}, /* dark cyan */ + {50, 0, 0}, /* dark red */ + {50, 0, 50}, /* dark magenta */ + {50, 50, 0}, /* brown */ + {75, 75, 75}, /* light gray */ + {50, 50, 50}, /* dark gray */ + {0, 0, 100}, /* light blue */ + {0, 100, 0}, /* light green */ + {0, 100, 100}, /* light cyan */ + {100, 0, 0}, /* light red */ + {100, 0, 100}, /* light magenta */ + {100, 100, 0}, /* yellow */ + {100, 100, 100}, /* white */ +}; + +int +vt_generate_vga_palette(uint32_t *palette, int format, uint32_t rmax, int roffset, + uint32_t gmax, int goffset, uint32_t bmax, int boffset) +{ + int i; + +#define CF(_f, _i) ((_f ## max * color_def[(_i)]._f / 100) << _f ## offset) + for (i = 0; i < 16; i++) { + switch (format) { + case COLOR_FORMAT_VGA: + palette[i] = i; + break; + case COLOR_FORMAT_RGB: + palette[i] = CF(r, i) | CF(g, i) | CF(b, i); + break; + default: + return (ENODEV); + } + } +#undef CF + return (0); +} Added: user/ed/newcons/sys/dev/vt/colors/vt_termcolors.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/ed/newcons/sys/dev/vt/colors/vt_termcolors.h Tue Oct 15 12:54:47 2013 (r256530) @@ -0,0 +1,50 @@ +/*- + * Copyright (c) 2013 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Aleksandr Rybalko under sponsorship from the + * FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +enum vt_color_format { + COLOR_FORMAT_BW = 0, + COLOR_FORMAT_GRAY, + COLOR_FORMAT_VGA, /* Color Index. */ + COLOR_FORMAT_RGB, + COLOR_FORMAT_ARGB, + COLOR_FORMAT_CMYK, + COLOR_FORMAT_HSL, + COLOR_FORMAT_YUV, + COLOR_FORMAT_YCbCr, + COLOR_FORMAT_YPbPr, + + COLOR_FORMAT_MAX = 15, +}; + +/* Helper to fill color map used by driver */ +int vt_generate_vga_palette(uint32_t *palette, int format, uint32_t rmax, + int roffset, uint32_t gmax, int goffset, uint32_t bmax, int boffset); + From owner-svn-src-user@FreeBSD.ORG Tue Oct 15 12:56:57 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 1C60DF84; Tue, 15 Oct 2013 12:56:57 +0000 (UTC) (envelope-from ray@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 0ABC82078; Tue, 15 Oct 2013 12:56:57 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9FCuu6b004422; Tue, 15 Oct 2013 12:56:56 GMT (envelope-from ray@svn.freebsd.org) Received: (from ray@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9FCuuhK004421; Tue, 15 Oct 2013 12:56:56 GMT (envelope-from ray@svn.freebsd.org) Message-Id: <201310151256.r9FCuuhK004421@svn.freebsd.org> From: Aleksandr Rybalko Date: Tue, 15 Oct 2013 12:56:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256531 - user/ed/newcons/sys/conf X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 12:56:57 -0000 Author: ray Date: Tue Oct 15 12:56:56 2013 New Revision: 256531 URL: http://svnweb.freebsd.org/changeset/base/256531 Log: Enable vt_termcolors.c to build with vt(9). Sponsored by: The FreeBSD Foundation Modified: user/ed/newcons/sys/conf/files Modified: user/ed/newcons/sys/conf/files ============================================================================== --- user/ed/newcons/sys/conf/files Tue Oct 15 12:54:47 2013 (r256530) +++ user/ed/newcons/sys/conf/files Tue Oct 15 12:56:56 2013 (r256531) @@ -2457,6 +2457,7 @@ dev/vge/if_vge.c optional vge dev/vkbd/vkbd.c optional vkbd dev/vr/if_vr.c optional vr pci +dev/vt/colors/vt_termcolors.c optional vt dev/vt/font/font_default.c optional vt dev/vt/hw/intel/intel.c optional vt vt_intel dev/vt/hw/vga/vga.c optional vt vt_vga From owner-svn-src-user@FreeBSD.ORG Tue Oct 15 12:58:42 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id D9D83227; Tue, 15 Oct 2013 12:58:41 +0000 (UTC) (envelope-from ray@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id C7A4B20A6; Tue, 15 Oct 2013 12:58:41 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9FCwfBa005470; Tue, 15 Oct 2013 12:58:41 GMT (envelope-from ray@svn.freebsd.org) Received: (from ray@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9FCwfGI005469; Tue, 15 Oct 2013 12:58:41 GMT (envelope-from ray@svn.freebsd.org) Message-Id: <201310151258.r9FCwfGI005469@svn.freebsd.org> From: Aleksandr Rybalko Date: Tue, 15 Oct 2013 12:58:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256532 - user/ed/newcons/sys/arm/freescale/imx X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 12:58:42 -0000 Author: ray Date: Tue Oct 15 12:58:41 2013 New Revision: 256532 URL: http://svnweb.freebsd.org/changeset/base/256532 Log: Use generated color map. Sponsored by: The FreeBSD Foundation Modified: user/ed/newcons/sys/arm/freescale/imx/imx51_ipuv3_newcons.c Modified: user/ed/newcons/sys/arm/freescale/imx/imx51_ipuv3_newcons.c ============================================================================== --- user/ed/newcons/sys/arm/freescale/imx/imx51_ipuv3_newcons.c Tue Oct 15 12:56:56 2013 (r256531) +++ user/ed/newcons/sys/arm/freescale/imx/imx51_ipuv3_newcons.c Tue Oct 15 12:58:41 2013 (r256532) @@ -65,6 +65,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include @@ -85,6 +86,7 @@ struct ipu3sc_softc { int sc_stride; int sc_width; int sc_height; + uint32_t sc_cmap[16]; bus_space_tag_t iot; bus_space_handle_t ioh; @@ -101,48 +103,6 @@ struct ipu3sc_softc { static struct ipu3sc_softc *ipu3sc_softc; -#if 0 -/* FIXME: not only 2 bytes color supported */ -static uint16_t colors[16] = { - 0x0000, /* black */ - 0x001f, /* blue */ - 0x07e0, /* green */ - 0x07ff, /* cyan */ - 0xf800, /* red */ - 0xf81f, /* magenta */ - 0x3800, /* brown */ - 0xc618, /* light grey */ - 0xc618, /* XXX: dark grey */ - 0x001f, /* XXX: light blue */ - 0x07e0, /* XXX: light green */ - 0x07ff, /* XXX: light cyan */ - 0xf800, /* XXX: light red */ - 0xf81f, /* XXX: light magenta */ - 0xffe0, /* yellow */ - 0xffff, /* white */ -}; -static uint32_t colors_24[16] = { - 0x000000,/* Black */ - 0x000080,/* Blue */ - 0x008000,/* Green */ - 0x008080,/* Cyan */ - 0x800000,/* Red */ - 0x800080,/* Magenta */ - 0xcc6600,/* brown */ - 0xC0C0C0,/* Silver */ - 0x808080,/* Gray */ - 0x0000FF,/* Light Blue */ - 0x00FF00,/* Light Green */ - 0x00FFFF,/* Light Cyan */ - 0xFF0000,/* Light Red */ - 0xFF00FF,/* Light Magenta */ - 0xFFFF00,/* Yellow */ - 0xFFFFFF,/* White */ - - -}; -#endif - static vd_init_t vt_imx_init; static vd_blank_t vt_imx_blank; static vd_bitbltchr_t vt_imx_bitbltchr; @@ -153,25 +113,6 @@ static struct vt_driver vt_imx_driver = .vd_bitbltchr = vt_imx_bitbltchr, }; -static const uint32_t colormap[] = { - 0x00000000, /* Black */ - 0x00ff0000, /* Red */ - 0x0000ff00, /* Green */ - 0x00c0c000, /* Brown */ - 0x000000ff, /* Blue */ - 0x00c000c0, /* Magenta */ - 0x0000c0c0, /* Cyan */ - 0x00c0c0c0, /* Light grey */ - 0x00808080, /* Dark grey */ - 0x00ff8080, /* Light red */ - 0x0080ff80, /* Light green */ - 0x00ffff80, /* Yellow */ - 0x008080ff, /* Light blue */ - 0x00ff80ff, /* Light magenta */ - 0x0080ffff, /* Light cyan */ - 0x00ffffff, /* White */ -}; - #define IPUV3_READ(ipuv3, module, reg) \ bus_space_read_4((ipuv3)->iot, (ipuv3)->module##_ioh, (reg)) #define IPUV3_WRITE(ipuv3, module, reg, val) \ @@ -365,6 +306,11 @@ ipu3_fb_attach(device_t dev) * Mailbox relies on it to get data from VideoCore */ ipu3_fb_init(sc); + err = vt_generate_vga_palette(sc->sc_cmap, COLOR_FORMAT_RGB, 0xff, 16, + 0xff, 8, 0xff, 0); + if (err) + goto fail_retarn_dctmpl; + vt_allocate(&vt_imx_driver, sc); @@ -417,7 +363,7 @@ vt_imx_blank(struct vt_device *vd, term_ u_int ofs; uint32_t c; - c = colormap[color]; + c = sc->sc_cmap[color]; switch (sc->sc_bpp) { case 1: for (ofs = 0; ofs < (sc->sc_stride * sc->sc_height); ofs++) @@ -463,8 +409,8 @@ vt_imx_bitbltchr(struct vt_device *vd, c uint8_t b = 0; bpp = sc->sc_bpp; - fgc = colormap[fg]; - bgc = colormap[bg]; + fgc = sc->sc_cmap[fg]; + bgc = sc->sc_cmap[bg]; line = sc->sc_vaddr + (sc->sc_stride * top) + (left * bpp); for (l = 0; l < height; l++) { From owner-svn-src-user@FreeBSD.ORG Tue Oct 15 13:07:25 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 831DC6C5; Tue, 15 Oct 2013 13:07:25 +0000 (UTC) (envelope-from ray@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 715AA2148; Tue, 15 Oct 2013 13:07:25 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9FD7PG0011150; Tue, 15 Oct 2013 13:07:25 GMT (envelope-from ray@svn.freebsd.org) Received: (from ray@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9FD7PnB011149; Tue, 15 Oct 2013 13:07:25 GMT (envelope-from ray@svn.freebsd.org) Message-Id: <201310151307.r9FD7PnB011149@svn.freebsd.org> From: Aleksandr Rybalko Date: Tue, 15 Oct 2013 13:07:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256534 - user/ed/newcons/sys/dev/drm2 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 13:07:25 -0000 Author: ray Date: Tue Oct 15 13:07:24 2013 New Revision: 256534 URL: http://svnweb.freebsd.org/changeset/base/256534 Log: Partially revert accidentally committed #if from r256528. Sponsored by: The FreeBSD Foundation Modified: user/ed/newcons/sys/dev/drm2/drm_fb_helper.c Modified: user/ed/newcons/sys/dev/drm2/drm_fb_helper.c ============================================================================== --- user/ed/newcons/sys/dev/drm2/drm_fb_helper.c Tue Oct 15 12:59:40 2013 (r256533) +++ user/ed/newcons/sys/dev/drm2/drm_fb_helper.c Tue Oct 15 13:07:24 2013 (r256534) @@ -53,9 +53,7 @@ static vd_init_t vt_kms_init; static vd_blank_t vt_kms_blank; static vd_bitbltchr_t vt_kms_bitbltchr; static vd_postswitch_t vt_kms_postswitch; -#if 0 static void vt_restore_fbdev_mode(void *, int); -#endif static struct vt_driver vt_vt_kms_driver = { .vd_init = vt_kms_init, @@ -167,14 +165,11 @@ vt_kms_init(struct vt_device *vd) /* Clear the screen. */ vt_kms_blank(vd, TC_BLACK); -#if 0 TASK_INIT(&sc->fb_mode_task, 0, vt_restore_fbdev_mode, vd); -#endif return (CN_INTERNAL); } -#if 0 /* Call restore out of vt(9) locks. */ static void vt_restore_fbdev_mode(void *arg, int pending) @@ -186,7 +181,6 @@ vt_restore_fbdev_mode(void *arg, int pen sc = vd->vd_softc; drm_fb_helper_restore_fbdev_mode(sc->fb_helper); } -#endif static void vt_kms_postswitch(struct vt_device *vd) @@ -194,11 +188,7 @@ vt_kms_postswitch(struct vt_device *vd) struct vt_kms_softc *sc; sc = vd->vd_softc; -#if 0 taskqueue_enqueue_fast(taskqueue_thread, &sc->fb_mode_task); -#else - drm_fb_helper_restore_fbdev_mode(sc->fb_helper); -#endif } static DRM_LIST_HEAD(kernel_fb_helper_list); From owner-svn-src-user@FreeBSD.ORG Tue Oct 15 13:18:40 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 13D199FA; Tue, 15 Oct 2013 13:18:40 +0000 (UTC) (envelope-from ray@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 015A62242; Tue, 15 Oct 2013 13:18:40 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9FDId6G017900; Tue, 15 Oct 2013 13:18:39 GMT (envelope-from ray@svn.freebsd.org) Received: (from ray@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9FDId8Y017899; Tue, 15 Oct 2013 13:18:39 GMT (envelope-from ray@svn.freebsd.org) Message-Id: <201310151318.r9FDId8Y017899@svn.freebsd.org> From: Aleksandr Rybalko Date: Tue, 15 Oct 2013 13:18:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256535 - user/ed/newcons/sys/dev/drm2 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 13:18:40 -0000 Author: ray Date: Tue Oct 15 13:18:39 2013 New Revision: 256535 URL: http://svnweb.freebsd.org/changeset/base/256535 Log: Use generated color map. Sponsored by: The FreeBSD Foundation Modified: user/ed/newcons/sys/dev/drm2/drm_fb_helper.c Modified: user/ed/newcons/sys/dev/drm2/drm_fb_helper.c ============================================================================== --- user/ed/newcons/sys/dev/drm2/drm_fb_helper.c Tue Oct 15 13:07:24 2013 (r256534) +++ user/ed/newcons/sys/dev/drm2/drm_fb_helper.c Tue Oct 15 13:18:39 2013 (r256535) @@ -47,6 +47,7 @@ struct vt_kms_softc { int sc_height; struct drm_fb_helper *fb_helper; struct task fb_mode_task; + uint32_t sc_cmap[16]; }; static vd_init_t vt_kms_init; @@ -62,25 +63,6 @@ static struct vt_driver vt_vt_kms_driver .vd_postswitch = vt_kms_postswitch, }; -static const uint32_t colormap[] = { - 0x00000000, /* Black */ - 0x00ff0000, /* Red */ - 0x0000ff00, /* Green */ - 0x00c0c000, /* Brown */ - 0x000000ff, /* Blue */ - 0x00c000c0, /* Magenta */ - 0x0000c0c0, /* Cyan */ - 0x00c0c0c0, /* Light grey */ - 0x00808080, /* Dark grey */ - 0x00ff8080, /* Light red */ - 0x0080ff80, /* Light green */ - 0x00ffff80, /* Yellow */ - 0x008080ff, /* Light blue */ - 0x00ff80ff, /* Light magenta */ - 0x0080ffff, /* Light cyan */ - 0x00ffffff, /* White */ -}; - static void vt_kms_blank(struct vt_device *vd, term_color_t color) { @@ -88,20 +70,21 @@ vt_kms_blank(struct vt_device *vd, term_ u_int ofs; uint32_t c; - /* TODO handle difference between */ + c = sc->sc_cmap[fg]; + /* TODO handle difference between depth and bpp. */ switch (sc->sc_depth) { case 8: for (ofs = 0; ofs < (sc->sc_stride * vd->vd_height); ofs++) - *(uint8_t *)(sc->sc_vaddr + ofs) = color; + *(uint8_t *)(sc->sc_vaddr + ofs) = c & 0xff; break; case 16: /* XXX must be 16bits colormap */ for (ofs = 0; ofs < (sc->sc_stride * vd->vd_height); ofs++) - *(uint16_t *)(sc->sc_vaddr + 2 * ofs) = color; + *(uint16_t *)(sc->sc_vaddr + 2 * ofs) = c & 0xffff; break; case 24: /* */ case 32: - c = colormap[color]; + c = sc->sc_cmap[color]; for (ofs = 0; ofs < (sc->sc_stride * vd->vd_height); ofs++) *(uint32_t *)(sc->sc_vaddr + 4 * ofs) = c; break; @@ -122,8 +105,8 @@ vt_kms_bitbltchr(struct vt_device *vd, c int c; uint8_t b = 0; - fgc = colormap[fg]; - bgc = colormap[bg]; + fgc = sc->sc_cmap[fg]; + bgc = sc->sc_cmap[bg]; line = (sc->sc_stride * top) + left * sc->sc_depth/8; for (; height > 0; height--) { @@ -135,7 +118,7 @@ vt_kms_bitbltchr(struct vt_device *vd, c switch(sc->sc_depth) { case 8: *(uint8_t *)(sc->sc_vaddr + line + c) = - b & 0x80 ? fg : bg; + (b & 0x80 ? fgc : bgc) & 0xff; break; /* TODO 16 */ /* TODO 24 */ @@ -156,12 +139,43 @@ static int vt_kms_init(struct vt_device *vd) { struct vt_kms_softc *sc; + int err; sc = vd->vd_softc; vd->vd_height = sc->sc_height; vd->vd_width = sc->sc_width; + switch (sc->sc_depth) { + case 8: + err = vt_generate_vga_palette(sc->sc_cmap, COLOR_FORMAT_RGB, + 0x7, 5, 0x7, 2, 0x3, 0); + if (err) + return (CN_DEAD); + break; + case 15: + err = vt_generate_vga_palette(sc->sc_cmap, COLOR_FORMAT_RGB, + 0x1f, 10, 0x1f, 5, 0x1f, 0); + if (err) + return (CN_DEAD); + break; + case 16: + err = vt_generate_vga_palette(sc->sc_cmap, COLOR_FORMAT_RGB, + 0x1f, 11, 0x3f, 5, 0x1f, 0); + if (err) + return (CN_DEAD); + break; + case 24: + case 32: /* Ignore alpha. */ + err = vt_generate_vga_palette(sc->sc_cmap, COLOR_FORMAT_RGB, + 0xff, 16, 0xff, 8, 0xff, 0); + if (err) + return (CN_DEAD); + break; + default: + return (CN_DEAD); + } + /* Clear the screen. */ vt_kms_blank(vd, TC_BLACK); From owner-svn-src-user@FreeBSD.ORG Tue Oct 15 13:24:11 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 7EA31D9B; Tue, 15 Oct 2013 13:24:11 +0000 (UTC) (envelope-from ray@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 6C7A52332; Tue, 15 Oct 2013 13:24:11 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9FDOBmC022895; Tue, 15 Oct 2013 13:24:11 GMT (envelope-from ray@svn.freebsd.org) Received: (from ray@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9FDOBbD022894; Tue, 15 Oct 2013 13:24:11 GMT (envelope-from ray@svn.freebsd.org) Message-Id: <201310151324.r9FDOBbD022894@svn.freebsd.org> From: Aleksandr Rybalko Date: Tue, 15 Oct 2013 13:24:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256536 - user/ed/newcons/sys/dev/drm2 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 13:24:11 -0000 Author: ray Date: Tue Oct 15 13:24:10 2013 New Revision: 256536 URL: http://svnweb.freebsd.org/changeset/base/256536 Log: Don't forget to include colors/vt_termcolors.h too. Sponsored by: The FreeBSD Foundation Modified: user/ed/newcons/sys/dev/drm2/drm_fb_helper.c Modified: user/ed/newcons/sys/dev/drm2/drm_fb_helper.c ============================================================================== --- user/ed/newcons/sys/dev/drm2/drm_fb_helper.c Tue Oct 15 13:18:39 2013 (r256535) +++ user/ed/newcons/sys/dev/drm2/drm_fb_helper.c Tue Oct 15 13:24:10 2013 (r256536) @@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include struct vt_kms_softc { intptr_t sc_paddr; From owner-svn-src-user@FreeBSD.ORG Tue Oct 15 13:45:38 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 620F5939; Tue, 15 Oct 2013 13:45:38 +0000 (UTC) (envelope-from ray@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 504C12510; Tue, 15 Oct 2013 13:45:38 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9FDjcqX035291; Tue, 15 Oct 2013 13:45:38 GMT (envelope-from ray@svn.freebsd.org) Received: (from ray@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9FDjcg5035290; Tue, 15 Oct 2013 13:45:38 GMT (envelope-from ray@svn.freebsd.org) Message-Id: <201310151345.r9FDjcg5035290@svn.freebsd.org> From: Aleksandr Rybalko Date: Tue, 15 Oct 2013 13:45:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256538 - user/ed/newcons/sys/dev/drm2 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 13:45:38 -0000 Author: ray Date: Tue Oct 15 13:45:37 2013 New Revision: 256538 URL: http://svnweb.freebsd.org/changeset/base/256538 Log: Swap Red and Blue (too much red in dialog(1)). Sponsored by: The FreeBSD Foundation Modified: user/ed/newcons/sys/dev/drm2/drm_fb_helper.c Modified: user/ed/newcons/sys/dev/drm2/drm_fb_helper.c ============================================================================== --- user/ed/newcons/sys/dev/drm2/drm_fb_helper.c Tue Oct 15 13:32:01 2013 (r256537) +++ user/ed/newcons/sys/dev/drm2/drm_fb_helper.c Tue Oct 15 13:45:37 2013 (r256538) @@ -71,7 +71,7 @@ vt_kms_blank(struct vt_device *vd, term_ u_int ofs; uint32_t c; - c = sc->sc_cmap[fg]; + c = sc->sc_cmap[color]; /* TODO handle difference between depth and bpp. */ switch (sc->sc_depth) { case 8: @@ -169,7 +169,7 @@ vt_kms_init(struct vt_device *vd) case 24: case 32: /* Ignore alpha. */ err = vt_generate_vga_palette(sc->sc_cmap, COLOR_FORMAT_RGB, - 0xff, 16, 0xff, 8, 0xff, 0); + 0xff, 0, 0xff, 8, 0xff, 16); if (err) return (CN_DEAD); break; From owner-svn-src-user@FreeBSD.ORG Tue Oct 15 15:43:29 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 8FF06D0A; Tue, 15 Oct 2013 15:43:29 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 7E55420AA; Tue, 15 Oct 2013 15:43:29 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9FFhTAM009871; Tue, 15 Oct 2013 15:43:29 GMT (envelope-from glebius@svn.freebsd.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9FFhTeW009869; Tue, 15 Oct 2013 15:43:29 GMT (envelope-from glebius@svn.freebsd.org) Message-Id: <201310151543.r9FFhTeW009869@svn.freebsd.org> From: Gleb Smirnoff Date: Tue, 15 Oct 2013 15:43:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256545 - user/glebius/course/04.synchronisation X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 15:43:29 -0000 Author: glebius Date: Tue Oct 15 15:43:29 2013 New Revision: 256545 URL: http://svnweb.freebsd.org/changeset/base/256545 Log: More unfinished stuff on synchronisation. Modified: user/glebius/course/04.synchronisation/lection.tex Modified: user/glebius/course/04.synchronisation/lection.tex ============================================================================== --- user/glebius/course/04.synchronisation/lection.tex Tue Oct 15 15:00:53 2013 (r256544) +++ user/glebius/course/04.synchronisation/lection.tex Tue Oct 15 15:43:29 2013 (r256545) @@ -12,6 +12,8 @@ \usetikzlibrary{positioning} \usetikzlibrary{shapes} +\usetikzlibrary{arrows} +\usetikzlibrary{chains} \usetikzlibrary{calc} \input{../course.tex} @@ -207,16 +209,63 @@ mtx\_lock:\\ #define MTX_CONTESTED 0x00000002 /* lock contested */ #define MTX_UNOWNED 0x00000004 /* free mutex */ -atomic_cmpset_acq_ptr(&(mp)->mtx_lock, MTX_UNOWNED, (tid)) +atomic_cmpset_acq_ptr(&(mp)->mtx_lock, MTX_UNOWNED, (td)) \end{verbatim} \end{frame} -\FootReferences{mutex(9)}{sys/kern/mutex.h, sys/kern/kern_mutex.c} +\FootReferences{mutex(9)}{sys/kern/mutex.h, sys/kern/kern\_mutex.c} \begin{frame} \frametitle{mutex(9) implementation} - +\begin{figure} +\begin{tikzpicture}[>=triangle 60, start chain=going below, + node distance=5mm, + every join/.style={->, draw}, + font=\scriptsize] +\tikzset { + base/.style={draw, thick, on chain, align=center, minimum height=4ex}, + proc/.style={base, rectangle}, + test/.style={base, diamond, aspect=3}, + term/.style={proc, rounded corners}, +} +\node [name=entry, proc] {mtx\_lock()}; +\node [name=atomic, test] {atomic\_cmpset(td)}; +\node [name=exit, term] {return}; +\node [name=ownerruns, test, right=of atomic] {owner running?}; +\node [name=trywait, proc] {turnstile\_trywait}; +\node [name=ownerruns2, test, join] {owner running?}; +\node [name=contested, test] {atomic\_cmpset(C)}; +\node [name=wait, proc, left=of contested] {turnstile\_wait}; +\node [name=cancel, proc, right=of ownerruns2] {turnstile\_cancel}; + +\draw [->] (entry.south) to node [name=entry2,midway] {} (atomic); +\draw [->] (atomic.south) to node [xshift=1em, green] {$yes$} (exit); +\draw [->] (atomic.east) to node [yshift=1em, red] {$no$} (ownerruns); +\draw [->] (ownerruns.south) to node [xshift=1em, green] {$yes$} (trywait); +\draw [->] (ownerruns.north) |- node [xshift=1ex, yshift=-1ex, red] {$no$} + (entry2.center); +\draw [->] (ownerruns2.south) to node [xshift=1em, green] {$yes$} (contested); +\draw [->] (ownerruns2.east) to node [yshift=1em, red] {$no$} (cancel); +\draw [->] (cancel.north) |- (entry2.center); +\draw [->] (contested.east) -| node [pos=0, yshift=1em, red] {$no$} + (cancel.south); +\draw [->] (contested.west) to node [yshift=1em, green] {$yes$} (wait); +\draw [->] (wait) -- (atomic.west |- wait) -- +(-2mm, 0) |- (entry2.center); +\end{tikzpicture} +\end{figure} \end{frame} +\FootReferences{mutex(9)}{sys/kern/subr\_turnstile.c, sys/kern/kern\_mutex.c} +\begin{frame} +\frametitle{mutex(9) implementation: turnstile} +\begin{figure} +\begin{tikzpicture}[every node/.style={draw, node distance=10mm}] + \node [name=turnstile, struct, rectangle split parts = ] + \textbf{struct turnstile} + \nodepart{two} LIST\_HEAD ts\_blocked + \nodepart{two} LIST\_HEAD ts\_pending +\end{tikzpicture} +\end{figure} +\end{frame} \end{document} From owner-svn-src-user@FreeBSD.ORG Tue Oct 15 23:19:29 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 96384EAE; Tue, 15 Oct 2013 23:19:29 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 8407D2F57; Tue, 15 Oct 2013 23:19:29 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9FNJT8c084583; Tue, 15 Oct 2013 23:19:29 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9FNJTJ0084575; Tue, 15 Oct 2013 23:19:29 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310152319.r9FNJTJ0084575@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Tue, 15 Oct 2013 23:19:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256564 - user/ae/inet6/sys/netinet X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 23:19:29 -0000 Author: ae Date: Tue Oct 15 23:19:28 2013 New Revision: 256564 URL: http://svnweb.freebsd.org/changeset/base/256564 Log: Initialize zoneid if src or dst address is from link-local scope. Modified: user/ae/inet6/sys/netinet/tcp_input.c user/ae/inet6/sys/netinet/tcp_subr.c Modified: user/ae/inet6/sys/netinet/tcp_input.c ============================================================================== --- user/ae/inet6/sys/netinet/tcp_input.c Tue Oct 15 21:28:51 2013 (r256563) +++ user/ae/inet6/sys/netinet/tcp_input.c Tue Oct 15 23:19:28 2013 (r256564) @@ -98,6 +98,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -1060,6 +1061,11 @@ relocked: inc.inc_flags |= INC_ISIPV6; inc.inc6_faddr = ip6->ip6_src; inc.inc6_laddr = ip6->ip6_dst; + if (IN6_IS_ADDR_LINKLOCAL(&ip6->ip6_src) || + IN6_IS_ADDR_LINKLOCAL(&ip6->ip6_dst)) + inc.inc6_zoneid = in6_getscopezone( + m->m_pkthdr.rcvif, + IPV6_ADDR_SCOPE_LINKLOCAL); } else #endif { Modified: user/ae/inet6/sys/netinet/tcp_subr.c ============================================================================== --- user/ae/inet6/sys/netinet/tcp_subr.c Tue Oct 15 21:28:51 2013 (r256563) +++ user/ae/inet6/sys/netinet/tcp_subr.c Tue Oct 15 23:19:28 2013 (r256564) @@ -1569,6 +1569,10 @@ tcp6_ctlinput(int cmd, struct sockaddr * inc.inc6_faddr = ((struct sockaddr_in6 *)sa)->sin6_addr; inc.inc6_laddr = ip6cp->ip6c_src->sin6_addr; inc.inc_flags |= INC_ISIPV6; + if (IN6_IS_ADDR_LINKLOCAL(&inc.inc6_laddr) || + IN6_IS_ADDR_LINKLOCAL(&inc.inc6_faddr)) + inc.inc6_zoneid = in6_getscopezone(m->m_pkthdr.rcvif, + IPV6_ADDR_SCOPE_LINKLOCAL); INP_INFO_WLOCK(&V_tcbinfo); syncache_unreach(&inc, &th); INP_INFO_WUNLOCK(&V_tcbinfo); From owner-svn-src-user@FreeBSD.ORG Tue Oct 15 23:24:46 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 13207F8; Tue, 15 Oct 2013 23:24:46 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 018302FB9; Tue, 15 Oct 2013 23:24:46 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9FNOjsV088738; Tue, 15 Oct 2013 23:24:45 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9FNOjwL088737; Tue, 15 Oct 2013 23:24:45 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310152324.r9FNOjwL088737@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Tue, 15 Oct 2013 23:24:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256565 - user/ae/inet6/sys/netinet X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 23:24:46 -0000 Author: ae Date: Tue Oct 15 23:24:45 2013 New Revision: 256565 URL: http://svnweb.freebsd.org/changeset/base/256565 Log: Initialize zoneid. Modified: user/ae/inet6/sys/netinet/tcp_syncache.c Modified: user/ae/inet6/sys/netinet/tcp_syncache.c ============================================================================== --- user/ae/inet6/sys/netinet/tcp_syncache.c Tue Oct 15 23:19:28 2013 (r256564) +++ user/ae/inet6/sys/netinet/tcp_syncache.c Tue Oct 15 23:24:45 2013 (r256565) @@ -711,6 +711,7 @@ syncache_socket(struct syncache *sc, str #ifdef INET6 if (sc->sc_inc.inc_flags & INC_ISIPV6) { inp->in6p_laddr = sc->sc_inc.inc6_laddr; + inp->in6p_zoneid = sc->sc_inc.inc6_zoneid; } else { inp->inp_vflag &= ~INP_IPV6; inp->inp_vflag |= INP_IPV4; From owner-svn-src-user@FreeBSD.ORG Tue Oct 15 23:25:07 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 9EA301D9; Tue, 15 Oct 2013 23:25:07 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 7C0EB2FBC; Tue, 15 Oct 2013 23:25:07 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9FNP76a088870; Tue, 15 Oct 2013 23:25:07 GMT (envelope-from glebius@svn.freebsd.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9FNP7uA088868; Tue, 15 Oct 2013 23:25:07 GMT (envelope-from glebius@svn.freebsd.org) Message-Id: <201310152325.r9FNP7uA088868@svn.freebsd.org> From: Gleb Smirnoff Date: Tue, 15 Oct 2013 23:25:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256566 - in user/glebius/course: . 04.synchronisation X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 23:25:07 -0000 Author: glebius Date: Tue Oct 15 23:25:06 2013 New Revision: 256566 URL: http://svnweb.freebsd.org/changeset/base/256566 Log: More on synchronisation. Added: user/glebius/course/04.synchronisation/witness.png (contents, props changed) user/glebius/course/04.synchronisation/witness2.png (contents, props changed) Modified: user/glebius/course/04.synchronisation/lection.tex user/glebius/course/course.tex Modified: user/glebius/course/04.synchronisation/lection.tex ============================================================================== --- user/glebius/course/04.synchronisation/lection.tex Tue Oct 15 23:24:45 2013 (r256565) +++ user/glebius/course/04.synchronisation/lection.tex Tue Oct 15 23:25:06 2013 (r256566) @@ -198,19 +198,21 @@ struct mtx { volatile uintptr_t mtx_lock; }; \end{verbatim} -mtx\_lock:\\ \begin{bytefield}{32} \bitheader[endianness=big]{0,1,2,3,10,11} \\ -\bitbox{21}{thread pointer} & \bitbox{8}{unused} & +\bitbox{21}{owner(td pointer)} & \bitbox{8}{unused} & \bitbox{1}{U} & \bitbox{1}{C} & \bitbox{1}{R} \end{bytefield} -\begin{verbatim} -#define MTX_RECURSED 0x00000001 /* lock recursed */ -#define MTX_CONTESTED 0x00000002 /* lock contested */ -#define MTX_UNOWNED 0x00000004 /* free mutex */ - -atomic_cmpset_acq_ptr(&(mp)->mtx_lock, MTX_UNOWNED, (td)) -\end{verbatim} +\onslide<2-> { +\begin{tabular}{l l l l} +\#define & MTX\_RECURSED & 0x00000001 & /* lock recursed */ \\ +\#define & MTX\_CONTESTED & 0x00000002 & /* lock contested */ \\ +\#define & MTX\_UNOWNED & 0x00000004 & /* free mutex */ \\ +\end{tabular} +} +\onslide<3-> { +\srcline{atomic\_cmpset\_acq\_ptr(\&(mp)->mtx\_lock, MTX\_UNOWNED, (td))} +} \end{frame} @@ -255,17 +257,236 @@ atomic_cmpset_acq_ptr(&(mp)->mtx_lock, M \end{figure} \end{frame} -\FootReferences{mutex(9)}{sys/kern/subr\_turnstile.c, sys/kern/kern\_mutex.c} + +\FootReferences{mutex(9)}{sys/kern/mutex.h, sys/kern/kern\_mutex.c} +\begin{frame} +\frametitle{mutex(9) implementation} +\begin{figure} +\begin{tikzpicture}[>=triangle 60, start chain=going below, + node distance=1cm, + every join/.style={->, draw}, + font=\scriptsize] +\tikzset { + base/.style={draw, thick, on chain, align=center, minimum height=4ex}, + proc/.style={base, rectangle}, + test/.style={base, diamond, aspect=3}, + term/.style={proc, rounded corners}, +} +\node [name=entry, proc] {mtx\_unlock()}; +\node [name=atomic, test] {atomic\_cmpset(td)}; +\node [name=exit, term] {return}; +\node [name=broadcast, proc, right=3.3cm of atomic] {turnstile\_broadcast}; + +\draw [->] (entry.south) to (atomic); +\draw [->] (atomic.south) to node [xshift=1em, green] + {MTX\_CONTESTED is 0} (exit); +\draw [->] (atomic.east) to node [yshift=1em, red] + {MTX\_CONTESTED is 1} (broadcast); +\draw [->] (broadcast.south) |- (exit); +\end{tikzpicture} +\end{figure} +\end{frame} + + +\FootReferences{rwlock(9)}{sys/sys/rwlock.h, sys/kern/kern\_rwlock.c} +\begin{frame}[fragile] +\frametitle{rwlock(9)} +\begin{verbatim} +struct rwlock { + struct lock_object lock_object; + volatile uintptr_t rw_lock; +}; +\end{verbatim} +\begin{bytefield}[bitwidth=2em]{12} +\bitheader[endianness=big]{0,1,2,3,4} \\ +\bitbox{8}{owner/reader count} & +\bitbox{1}{WS} & \bitbox{1}{WW} & \bitbox{1}{RW} & \bitbox{1}{R} +\end{bytefield} +\onslide<2-> \scriptsize { +\begin{tabular}{l l l} +\#define & RW\_LOCK\_READ & 0x01 \\ +\#define & RW\_LOCK\_READ\_WAITERS & 0x02 \\ +\#define & RW\_LOCK\_WRITE\_WAITERS & 0x04 \\ +\#define & RW\_LOCK\_WRITE\_SPINNER & 0x08 \\ +\#define & RW\_LOCK\_FLAGMASK & 0x0f \\ +\end{tabular} +\begin{tabular}{l l l} +\#define & RW\_OWNER(x) & ((x) \& ~RW\_LOCK\_FLAGMASK) \\ +\#define & RW\_READERS(x) & (RW\_OWNER((x)) >> RW\_READERS\_SHIFT) +\end{tabular} +} +\end{frame} + + +\FootReferences{}{sys/kern/subr\_turnstile.c} +\begin{frame} +\frametitle<1,2>{turnstile idea} +\frametitle<3->{priority propagation} +\begin{figure} +\begin{tikzpicture}[node distance=1mm] + % the turnstile + \node [name=tcent, circle, minimum width=1mm, draw, fill=black] {}; + \node [name=turnstile, circle, minimum width=27mm, draw, thick] at (tcent){}; + \draw [thick] (node cs:name=turnstile, angle=45) + -- (node cs:name=turnstile, angle=225); + \draw [thick] (node cs:name=turnstile, angle=135) + -- (node cs:name=turnstile, angle=315); + \draw [thick] (node cs:name=turnstile, angle=135) + -- node[above, pos=.2] {turnstile} +(-3cm,0); + \draw [thick] (node cs:name=turnstile, angle=225) -- +(-3cm,0); +\onslide<1,3-> { + \node [name=tdA, left=of tcent, circle, draw, thick] { tdA }; + \node [name=tdB, left=of tdA, circle, draw, thick] { tdB }; + \node [name=tdC, left=of tdB, circle, draw, thick] { tdC }; + \node [name=dots, left=of tdC, circle] { \ldots }; +} +\onslide<2> { + \node [name=tdA, left=of tcent, circle, draw, thick] { tdB }; + \node [name=tdB, left=of tdA, circle, draw, thick] { tdC }; + \node [name=tdC, left=of tdB, circle] { \ldots }; + \node [name=dots, left=of tdC, circle] { \ldots }; +} + + % lock & owner + \node [name=lock, above=1.5cm of turnstile, draw, thick, rounded corners] + {\Large{lock}}; + \draw [<->,thick] (lock) -- (turnstile); +\onslide<1,3-> { + \node [name=owner, right=1.5cm of lock, draw, thick, circle] {tdO}; +} +\onslide<2> { + \node [name=owner, right=1.5cm of lock, draw, thick, circle] {tdA}; + \node [name=old, below right=1cm and 1cm of owner, draw, thick, circle] + {tdO}; +} + \draw [->, thick] (lock) -- node [above] {owner} (owner); + +\onslide<2> { + % nice rotating arrow + \path (node cs:name=turnstile, angle=45) -- +(2mm,2mm) node [name=arr1] {}; + \draw [->,thick,color=red] (arr1) + arc[radius=17mm, start angle=45, end angle=0] + node [xshift=2ex, rotate=270] {tdO unlocks} + arc[radius=17mm, start angle=0, end angle=-45]; +} + +\onslide<3-> { + \node [name=allprio, ellipse, minimum width=10em, minimum height=4em, + draw, thick, color=red] at (tdB.center){}; + \draw [->,thick,color=red] (allprio.north east) to [out=45, in=270] + node [above, sloped, pos=.6] { priority } (owner); +} +\onslide<4-> { + \node [name=lock2, below=2cm of tdB, draw, thick, rounded corners] + {\Large{lock2}}; + \draw [->,thick] (lock2) -- node [above,sloped,pos=.4] {owner} (tdB); + \node [name=turnstile2, left=1cm of lock2, signal, draw, thick, + minimum height=2em, minimum width=7em] {}; + \node [above=of turnstile2] {lock2s' turnstile}; + \draw [<->,thick] (lock2) -- (turnstile2); + \node [name=allprio2, ellipse, minimum width=8em, minimum height=3em, + draw, thick, color=red] at (turnstile2.center){}; + \draw [->,thick,color=red] (allprio2.north east) to [out=15, in=225] + node [above, sloped] { priority } (tdB); +} +\end{tikzpicture} +\end{figure} +\end{frame} + + \begin{frame} -\frametitle{mutex(9) implementation: turnstile} +\frametitle{turnstiles implementation} +\begin{itemize} + \item {Turnstiles are ephemeral, e.g. don't exist without contention} + \item {Any lock might require a turnstile} + \item {A turnstile can queue many threads} + \item {A thread can hold many turnstiles} + \item {A thread can stay only in one turnstile} +\end{itemize} \begin{figure} \begin{tikzpicture}[every node/.style={draw, node distance=10mm}] - \node [name=turnstile, struct, rectangle split parts = ] + \node [name=turnstile, struct, rectangle split parts = 5] { \textbf{struct turnstile} - \nodepart{two} LIST\_HEAD ts\_blocked - \nodepart{two} LIST\_HEAD ts\_pending + \nodepart{two} LIST\_HEAD ts\_blocked[2] + \nodepart{three} LIST\_HEAD ts\_pending + \nodepart{four} struct lock\_object *ts\_lockobj + \nodepart{five} struct thread *ts\_owner + }; + \node [name=thread, right=of turnstile, struct, rectangle split parts = 6] { + \textbf{struct thread} + \nodepart{two} \ldots + \nodepart{three} struct turnstile *td\_turnstile + \nodepart{four} struct turnstile *td\_blocked + \nodepart{five} LIST\_HEAD td\_contested + \nodepart{six} \ldots + }; \end{tikzpicture} \end{figure} \end{frame} + +\usebackgroundtemplate{ + \hbox to + \paperheight{\hfil\includegraphics[height=\paperheight]{witness.png}} +} +\FootReferences{}{} +\begin{frame} +\frametitle<1>{lock order reversal (LOR)} +\frametitle<2>{lock order reversal (LOR) and other locking problems} +\begin{center} +\begin{columns} + \begin{column}{.4\paperwidth} + {\Large CPU 1, thread A} + \srcline {% + mtx\_lock(\&mtx\_A);\\ + mtx\_lock(\&mtx\_B); + } + \end{column} + \begin{column}{.4\paperwidth} + {\Large CPU 2, thread B} + \srcline {% + mtx\_lock(\&mtx\_B);\\ + mtx\_lock(\&mtx\_A); + } + \end{column} +\end{columns} +\end{center} +\onslide<2> { + Also: + \begin{itemize} + \item {Sleeping with lock held} + \item {Obtaining blockable lock with spin lock held} + \item {Returning from a syscall with lock held} + \item {Recursing on non-recursive lock} + \end{itemize} +} +\end{frame} + + +\usebackgroundtemplate{ + \hbox to + \paperheight{\hfil\includegraphics[height=\paperheight]{witness2.png}} +} +\FootReferences{witness(4)}{sys/kern/subr\_witness.c} +\begin{frame} +\frametitle{witness(4)} +\onslide<1-> { + \begin{itemize} + \item {Maintains ordered list of locks for each process} + \item {Maintains global list of well known locks in correct order + of acquisition} + \item {Maintains dynamic tree of lock orders for every lock in system} + \item {Compares threads' list against global list and dynamic tree} + \item {Reports violations} + \end{itemize} +} +\onslide<2-> { + \shellcmd{% + \# kgdb\\ + (kgdb) p td->td\_sleeplocks\\ + (kgdb) p td->td\_sleeplocks->ll\_children[0].li\_lock\\ + (kgdb) p *td->td\_sleeplocks->ll\_children[0].li\_lock->lo\_witness\\ + } +} +\end{frame} \end{document} Added: user/glebius/course/04.synchronisation/witness.png ============================================================================== Binary file. No diff available. Added: user/glebius/course/04.synchronisation/witness2.png ============================================================================== Binary file. No diff available. Modified: user/glebius/course/course.tex ============================================================================== --- user/glebius/course/course.tex Tue Oct 15 23:24:45 2013 (r256565) +++ user/glebius/course/course.tex Tue Oct 15 23:25:06 2013 (r256566) @@ -46,6 +46,13 @@ \end{beamercolorbox} } +% Source line +\newcommand{\srcline}[1]{ + \begin{beamercolorbox}[rounded=true,shadow=true,sep=0pt,colsep=0pt]{source} + \small{#1} + \end{beamercolorbox} +} + \tikzset { struct/.style = { draw, thick, rectangle split, From owner-svn-src-user@FreeBSD.ORG Tue Oct 15 23:28:13 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id D859E337; Tue, 15 Oct 2013 23:28:13 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id C6CBF2FD0; Tue, 15 Oct 2013 23:28:13 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9FNSDuw089443; Tue, 15 Oct 2013 23:28:13 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9FNSD7Z089442; Tue, 15 Oct 2013 23:28:13 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310152328.r9FNSD7Z089442@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Tue, 15 Oct 2013 23:28:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256567 - user/ae/inet6/sys/netinet X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 23:28:13 -0000 Author: ae Date: Tue Oct 15 23:28:13 2013 New Revision: 256567 URL: http://svnweb.freebsd.org/changeset/base/256567 Log: Properly initialie sin6_scope_id. Modified: user/ae/inet6/sys/netinet/tcp_syncache.c Modified: user/ae/inet6/sys/netinet/tcp_syncache.c ============================================================================== --- user/ae/inet6/sys/netinet/tcp_syncache.c Tue Oct 15 23:25:06 2013 (r256566) +++ user/ae/inet6/sys/netinet/tcp_syncache.c Tue Oct 15 23:28:13 2013 (r256567) @@ -776,7 +776,9 @@ syncache_socket(struct syncache *sc, str sin6.sin6_len = sizeof(sin6); sin6.sin6_addr = sc->sc_inc.inc6_faddr; sin6.sin6_port = sc->sc_inc.inc_fport; - sin6.sin6_flowinfo = sin6.sin6_scope_id = 0; + sin6.sin6_flowinfo = 0; + sin6.sin6_scope_id = IN6_IS_ADDR_LINKLOCAL(&sin6.sin6_addr) ? + sc->sc_inc.inc6_zoneid: 0; laddr6 = inp->in6p_laddr; if (IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)) inp->in6p_laddr = sc->sc_inc.inc6_laddr; From owner-svn-src-user@FreeBSD.ORG Tue Oct 15 23:31:09 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 0443C4B0; Tue, 15 Oct 2013 23:31:09 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id E5E5C2015; Tue, 15 Oct 2013 23:31:08 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9FNV8xS092478; Tue, 15 Oct 2013 23:31:08 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9FNV8wD092477; Tue, 15 Oct 2013 23:31:08 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310152331.r9FNV8wD092477@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Tue, 15 Oct 2013 23:31:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256568 - user/ae/inet6/sys/netinet X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 23:31:09 -0000 Author: ae Date: Tue Oct 15 23:31:08 2013 New Revision: 256568 URL: http://svnweb.freebsd.org/changeset/base/256568 Log: Add XXX comment to handle sending to/from link-local address later. Modified: user/ae/inet6/sys/netinet/tcp_syncache.c Modified: user/ae/inet6/sys/netinet/tcp_syncache.c ============================================================================== --- user/ae/inet6/sys/netinet/tcp_syncache.c Tue Oct 15 23:28:13 2013 (r256567) +++ user/ae/inet6/sys/netinet/tcp_syncache.c Tue Oct 15 23:31:08 2013 (r256568) @@ -1553,6 +1553,7 @@ syncache_respond(struct syncache *sc) return (error); } #endif + /* XXX: scope zone id */ error = ip6_output(m, NULL, NULL, 0, NULL, NULL, NULL); } #endif From owner-svn-src-user@FreeBSD.ORG Tue Oct 15 23:56:32 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 6C8898AE; Tue, 15 Oct 2013 23:56:32 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 5A6EF216B; Tue, 15 Oct 2013 23:56:32 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9FNuWFw004142; Tue, 15 Oct 2013 23:56:32 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9FNuVCl004136; Tue, 15 Oct 2013 23:56:31 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310152356.r9FNuVCl004136@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Tue, 15 Oct 2013 23:56:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256569 - in user/ae/inet6/sys: netinet netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 23:56:32 -0000 Author: ae Date: Tue Oct 15 23:56:31 2013 New Revision: 256569 URL: http://svnweb.freebsd.org/changeset/base/256569 Log: Add scope zone id argument to in6_pcblookup_local function. Modified: user/ae/inet6/sys/netinet/in_pcb.c user/ae/inet6/sys/netinet6/in6_pcb.c user/ae/inet6/sys/netinet6/in6_pcb.h Modified: user/ae/inet6/sys/netinet/in_pcb.c ============================================================================== --- user/ae/inet6/sys/netinet/in_pcb.c Tue Oct 15 23:31:08 2013 (r256568) +++ user/ae/inet6/sys/netinet/in_pcb.c Tue Oct 15 23:56:31 2013 (r256569) @@ -448,7 +448,8 @@ in_pcb_lport(struct inpcb *inp, struct i #ifdef INET6 if ((inp->inp_vflag & INP_IPV6) != 0) tmpinp = in6_pcblookup_local(pcbinfo, - &inp->in6p_laddr, lport, lookupflags, cred); + &inp->in6p_laddr, inp->in6p_zoneid, lport, + lookupflags, cred); #endif #if defined(INET) && defined(INET6) else Modified: user/ae/inet6/sys/netinet6/in6_pcb.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6_pcb.c Tue Oct 15 23:31:08 2013 (r256568) +++ user/ae/inet6/sys/netinet6/in6_pcb.c Tue Oct 15 23:56:31 2013 (r256569) @@ -193,8 +193,8 @@ in6_pcbbind(struct inpcb *inp, struct so priv_check_cred(inp->inp_cred, PRIV_NETINET_REUSEPORT, 0) != 0) { t = in6_pcblookup_local(pcbinfo, - &sin6->sin6_addr, lport, - INPLOOKUP_WILDCARD, cred); + &sin6->sin6_addr, sin6->sin6_scope_id, + lport, INPLOOKUP_WILDCARD, cred); if (t && ((t->inp_flags & INP_TIMEWAIT) == 0) && (so->so_type != SOCK_STREAM || @@ -227,7 +227,7 @@ in6_pcbbind(struct inpcb *inp, struct so #endif } t = in6_pcblookup_local(pcbinfo, &sin6->sin6_addr, - lport, lookupflags, cred); + sin6->sin6_scope_id, lport, lookupflags, cred); if (t && (t->inp_flags & INP_TIMEWAIT)) { /* * XXXRW: If an incpb has had its timewait @@ -269,6 +269,7 @@ in6_pcbbind(struct inpcb *inp, struct so #endif } inp->in6p_laddr = sin6->sin6_addr; + inp->in6p_zoneid = sin6->sin6_scope_id; } if (lport == 0) { if ((error = in6_pcbsetport(&inp->in6p_laddr, inp, cred)) != 0) { @@ -676,7 +677,7 @@ in6_pcbnotify(struct inpcbinfo *pcbinfo, */ struct inpcb * in6_pcblookup_local(struct inpcbinfo *pcbinfo, struct in6_addr *laddr, - u_short lport, int lookupflags, struct ucred *cred) + uint32_t zoneid, u_short lport, int lookupflags, struct ucred *cred) { register struct inpcb *inp; int matchwild = 3, wildcard; @@ -700,6 +701,7 @@ in6_pcblookup_local(struct inpcbinfo *pc continue; if (IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr) && IN6_ARE_ADDR_EQUAL(&inp->in6p_laddr, laddr) && + inp->in6p_zoneid == zoneid && inp->inp_lport == lport) { /* Found. */ if (cred == NULL || @@ -734,7 +736,6 @@ in6_pcblookup_local(struct inpcbinfo *pc * fit. */ LIST_FOREACH(inp, &phd->phd_pcblist, inp_portlist) { - wildcard = 0; if (cred != NULL && !prison_equal_ip6(cred->cr_prison, inp->inp_cred->cr_prison)) @@ -742,6 +743,7 @@ in6_pcblookup_local(struct inpcbinfo *pc /* XXX inp locking */ if ((inp->inp_vflag & INP_IPV6) == 0) continue; + wildcard = 0; if (!IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr)) wildcard++; if (!IN6_IS_ADDR_UNSPECIFIED( @@ -751,6 +753,8 @@ in6_pcblookup_local(struct inpcbinfo *pc else if (!IN6_ARE_ADDR_EQUAL( &inp->in6p_laddr, laddr)) continue; + else if (inp->in6p_zoneid != zoneid) + continue; } else { if (!IN6_IS_ADDR_UNSPECIFIED(laddr)) wildcard++; Modified: user/ae/inet6/sys/netinet6/in6_pcb.h ============================================================================== --- user/ae/inet6/sys/netinet6/in6_pcb.h Tue Oct 15 23:31:08 2013 (r256568) +++ user/ae/inet6/sys/netinet6/in6_pcb.h Tue Oct 15 23:56:31 2013 (r256569) @@ -87,9 +87,8 @@ int in6_pcbconnect_mbuf(struct inpcb *, struct ucred *, struct mbuf *); void in6_pcbdisconnect(struct inpcb *); struct inpcb * - in6_pcblookup_local(struct inpcbinfo *, - struct in6_addr *, u_short, int, - struct ucred *); + in6_pcblookup_local(struct inpcbinfo *, struct in6_addr *, uint32_t, + u_short, int, struct ucred *); struct inpcb * in6_pcblookup(struct inpcbinfo *, struct in6_addr *, u_int, struct in6_addr *, u_int, int, From owner-svn-src-user@FreeBSD.ORG Wed Oct 16 07:52:20 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 43D90879; Wed, 16 Oct 2013 07:52:20 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 312EF284A; Wed, 16 Oct 2013 07:52:20 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9G7qKPv055293; Wed, 16 Oct 2013 07:52:20 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9G7qJxw055290; Wed, 16 Oct 2013 07:52:19 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310160752.r9G7qJxw055290@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 16 Oct 2013 07:52:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256592 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 07:52:20 -0000 Author: ae Date: Wed Oct 16 07:52:19 2013 New Revision: 256592 URL: http://svnweb.freebsd.org/changeset/base/256592 Log: Add checks for scope zone id to pcb code. Modified: user/ae/inet6/sys/netinet6/in6_pcb.c user/ae/inet6/sys/netinet6/in6_pcb.h user/ae/inet6/sys/netinet6/in6_pcbgroup.c Modified: user/ae/inet6/sys/netinet6/in6_pcb.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6_pcb.c Wed Oct 16 06:15:40 2013 (r256591) +++ user/ae/inet6/sys/netinet6/in6_pcb.c Wed Oct 16 07:52:19 2013 (r256592) @@ -630,8 +630,10 @@ in6_pcbnotify(struct inpcbinfo *pcbinfo, * XXX: should we avoid to notify the value to TCP sockets? */ if (cmd == PRC_MSGSIZE && (inp->inp_flags & IN6P_MTU) != 0 && - (IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr) || - IN6_ARE_ADDR_EQUAL(&inp->in6p_faddr, &sa6_dst->sin6_addr))) { + (IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr) || ( + IN6_ARE_ADDR_EQUAL(&inp->in6p_faddr, + &sa6_dst->sin6_addr) && (sa6_dst->sin6_scope_id == 0 || + sa6_dst->sin6_scope_id == inp->in6p_zoneid)))) { ip6_notify_pmtu(inp, (struct sockaddr_in6 *)dst, (u_int32_t *)cmdarg); } @@ -647,7 +649,9 @@ in6_pcbnotify(struct inpcbinfo *pcbinfo, if (lport == 0 && fport == 0 && flowinfo && inp->inp_socket != NULL && flowinfo == (inp->inp_flow & IPV6_FLOWLABEL_MASK) && - IN6_ARE_ADDR_EQUAL(&inp->in6p_laddr, &sa6_src.sin6_addr)) + IN6_ARE_ADDR_EQUAL(&inp->in6p_laddr, &sa6_src.sin6_addr) && + (sa6_src.sin6_scope_id == 0 || + sa6_src.sin6_scope_id == inp->in6p_zoneid)) goto do_notify; else if (!IN6_ARE_ADDR_EQUAL(&inp->in6p_faddr, &sa6_dst->sin6_addr) || @@ -657,6 +661,7 @@ in6_pcbnotify(struct inpcbinfo *pcbinfo, !IN6_ARE_ADDR_EQUAL(&inp->in6p_laddr, &sa6_src.sin6_addr)) || (fport && inp->inp_fport != fport)) { + /* XXX: zoneid */ INP_WUNLOCK(inp); continue; } @@ -852,6 +857,7 @@ in6_pcblookup_group(struct inpcbinfo *pc { struct inpcbhead *head; struct inpcb *inp, *tmpinp; + uint32_t zoneid; u_short fport = fport_arg, lport = lport_arg; int faith; @@ -860,6 +866,8 @@ in6_pcblookup_group(struct inpcbinfo *pc else faith = 0; + zoneid = (ifp == NULL) ? 0: + in6_getscopezone(ifp, IPV6_ADDR_SCOPE_LINKLOCAL); /* * First look for an exact match. */ @@ -875,7 +883,8 @@ in6_pcblookup_group(struct inpcbinfo *pc if (IN6_ARE_ADDR_EQUAL(&inp->in6p_faddr, faddr) && IN6_ARE_ADDR_EQUAL(&inp->in6p_laddr, laddr) && inp->inp_fport == fport && - inp->inp_lport == lport) { + inp->inp_lport == lport && + inp->in6p_zoneid == zoneid) { /* * XXX We should be able to directly return * the inp here, without any checks. @@ -933,7 +942,8 @@ in6_pcblookup_group(struct inpcbinfo *pc continue; } - if (IN6_ARE_ADDR_EQUAL(&inp->in6p_laddr, laddr)) { + if (IN6_ARE_ADDR_EQUAL(&inp->in6p_laddr, laddr) && + inp->in6p_zoneid == zoneid) { if (injail) goto found; else @@ -986,6 +996,7 @@ in6_pcblookup_hash_locked(struct inpcbin { struct inpcbhead *head; struct inpcb *inp, *tmpinp; + uint32_t zoneid; u_short fport = fport_arg, lport = lport_arg; int faith; @@ -999,6 +1010,8 @@ in6_pcblookup_hash_locked(struct inpcbin else faith = 0; + zoneid = (ifp == NULL) ? 0: + in6_getscopezone(ifp, IPV6_ADDR_SCOPE_LINKLOCAL); /* * First look for an exact match. */ @@ -1013,7 +1026,8 @@ in6_pcblookup_hash_locked(struct inpcbin if (IN6_ARE_ADDR_EQUAL(&inp->in6p_faddr, faddr) && IN6_ARE_ADDR_EQUAL(&inp->in6p_laddr, laddr) && inp->inp_fport == fport && - inp->inp_lport == lport) { + inp->inp_lport == lport && + inp->in6p_zoneid == zoneid) { /* * XXX We should be able to directly return * the inp here, without any checks. @@ -1069,7 +1083,8 @@ in6_pcblookup_hash_locked(struct inpcbin continue; } - if (IN6_ARE_ADDR_EQUAL(&inp->in6p_laddr, laddr)) { + if (IN6_ARE_ADDR_EQUAL(&inp->in6p_laddr, laddr) && + inp->in6p_zoneid == zoneid) { if (injail) return (inp); else @@ -1141,6 +1156,7 @@ in6_pcblookup(struct inpcbinfo *pcbinfo, { #if defined(PCBGROUP) struct inpcbgroup *pcbgroup; + uint32_t zoneid; #endif KASSERT((lookupflags & ~INPLOOKUP_MASK) == 0, @@ -1150,8 +1166,10 @@ in6_pcblookup(struct inpcbinfo *pcbinfo, #if defined(PCBGROUP) if (in_pcbgroup_enabled(pcbinfo)) { + zoneid = (ifp == NULL) ? 0: + in6_getscopezone(ifp, IPV6_ADDR_SCOPE_LINKLOCAL); pcbgroup = in6_pcbgroup_bytuple(pcbinfo, laddr, lport, faddr, - fport); + fport, zoneid); return (in6_pcblookup_group(pcbinfo, pcbgroup, faddr, fport, laddr, lport, lookupflags, ifp)); } @@ -1167,6 +1185,7 @@ in6_pcblookup_mbuf(struct inpcbinfo *pcb { #ifdef PCBGROUP struct inpcbgroup *pcbgroup; + uint32_t zoneid; #endif KASSERT((lookupflags & ~INPLOOKUP_MASK) == 0, @@ -1181,8 +1200,10 @@ in6_pcblookup_mbuf(struct inpcbinfo *pcb if (pcbgroup != NULL) return (in6_pcblookup_group(pcbinfo, pcbgroup, faddr, fport, laddr, lport, lookupflags, ifp)); + zoneid = (ifp == NULL) ? 0: + in6_getscopezone(ifp, IPV6_ADDR_SCOPE_LINKLOCAL); pcbgroup = in6_pcbgroup_bytuple(pcbinfo, laddr, lport, faddr, - fport); + fport, zoneid); return (in6_pcblookup_group(pcbinfo, pcbgroup, faddr, fport, laddr, lport, lookupflags, ifp)); } Modified: user/ae/inet6/sys/netinet6/in6_pcb.h ============================================================================== --- user/ae/inet6/sys/netinet6/in6_pcb.h Wed Oct 16 06:15:40 2013 (r256591) +++ user/ae/inet6/sys/netinet6/in6_pcb.h Wed Oct 16 07:52:19 2013 (r256592) @@ -77,7 +77,7 @@ struct inpcbgroup * in6_pcbgroup_bymbuf(struct inpcbinfo *, struct mbuf *); struct inpcbgroup * in6_pcbgroup_bytuple(struct inpcbinfo *, const struct in6_addr *, - u_short, const struct in6_addr *, u_short); + u_short, const struct in6_addr *, u_short, uint32_t); void in6_pcbpurgeif0(struct inpcbinfo *, struct ifnet *); void in6_losing(struct inpcb *); Modified: user/ae/inet6/sys/netinet6/in6_pcbgroup.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6_pcbgroup.c Wed Oct 16 06:15:40 2013 (r256591) +++ user/ae/inet6/sys/netinet6/in6_pcbgroup.c Wed Oct 16 07:52:19 2013 (r256592) @@ -74,7 +74,8 @@ in6_pcbgroup_bymbuf(struct inpcbinfo *pc struct inpcbgroup * in6_pcbgroup_bytuple(struct inpcbinfo *pcbinfo, const struct in6_addr *laddrp, - u_short lport, const struct in6_addr *faddrp, u_short fport) + u_short lport, const struct in6_addr *faddrp, u_short fport, + uint32_t zoneid) { uint32_t hash; @@ -99,5 +100,6 @@ in6_pcbgroup_byinpcb(struct inpcb *inp) { return (in6_pcbgroup_bytuple(inp->inp_pcbinfo, &inp->in6p_laddr, - inp->inp_lport, &inp->in6p_faddr, inp->inp_fport)); + inp->inp_lport, &inp->in6p_faddr, inp->inp_fport, + inp->in6p_zoneid)); } From owner-svn-src-user@FreeBSD.ORG Wed Oct 16 08:14:05 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id A6A3BEBF; Wed, 16 Oct 2013 08:14:05 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 842AD295F; Wed, 16 Oct 2013 08:14:05 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9G8E5qY067208; Wed, 16 Oct 2013 08:14:05 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9G8E5lo067207; Wed, 16 Oct 2013 08:14:05 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310160814.r9G8E5lo067207@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 16 Oct 2013 08:14:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256593 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 08:14:05 -0000 Author: ae Date: Wed Oct 16 08:14:05 2013 New Revision: 256593 URL: http://svnweb.freebsd.org/changeset/base/256593 Log: Remove in6_pcbladdr() function: * move code from in6_pcbladdr() into in6_pcbconnect_mbuf(); * remove sa6_embedscope() and use sa6_checkzone() instead; * remove in6_setscope() call; * pass outgoing interface determined with SAS algorithm into in6_pcblookup_hash_locked() to be able determine scope zone id; * initialize in6p_zoneid when connection has link-local address. Modified: user/ae/inet6/sys/netinet6/in6_pcb.c Modified: user/ae/inet6/sys/netinet6/in6_pcb.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6_pcb.c Wed Oct 16 07:52:19 2013 (r256592) +++ user/ae/inet6/sys/netinet6/in6_pcb.c Wed Oct 16 08:14:05 2013 (r256593) @@ -289,82 +289,6 @@ in6_pcbbind(struct inpcb *inp, struct so } /* - * Transform old in6_pcbconnect() into an inner subroutine for new - * in6_pcbconnect(): Do some validity-checking on the remote - * address (in mbuf 'nam') and then determine local host address - * (i.e., which interface) to use to access that remote host. - * - * This preserves definition of in6_pcbconnect(), while supporting a - * slightly different version for T/TCP. (This is more than - * a bit of a kludge, but cleaning up the internal interfaces would - * have forced minor changes in every protocol). - */ -static int -in6_pcbladdr(register struct inpcb *inp, struct sockaddr *nam, - struct in6_addr *plocal_addr6) -{ - register struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)nam; - int error = 0; - struct ifnet *ifp = NULL; - int scope_ambiguous = 0; - struct in6_addr in6a; - - INP_WLOCK_ASSERT(inp); - INP_HASH_WLOCK_ASSERT(inp->inp_pcbinfo); /* XXXRW: why? */ - - if (nam->sa_len != sizeof (*sin6)) - return (EINVAL); - if (sin6->sin6_family != AF_INET6) - return (EAFNOSUPPORT); - if (sin6->sin6_port == 0) - return (EADDRNOTAVAIL); - - if (sin6->sin6_scope_id == 0 && !V_ip6_use_defzone) - scope_ambiguous = 1; - if ((error = sa6_embedscope(sin6, V_ip6_use_defzone)) != 0) - return(error); - - if (!TAILQ_EMPTY(&V_in6_ifaddrhead)) { - /* - * If the destination address is UNSPECIFIED addr, - * use the loopback addr, e.g ::1. - */ - if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) - sin6->sin6_addr = in6addr_loopback; - } - if ((error = prison_remote_ip6(inp->inp_cred, &sin6->sin6_addr)) != 0) - return (error); - - error = in6_selectsrc(sin6, inp->in6p_outputopts, - inp, NULL, inp->inp_cred, &ifp, &in6a); - if (error) - return (error); - - if (ifp && scope_ambiguous && - (error = in6_setscope(&sin6->sin6_addr, ifp, NULL)) != 0) { - return(error); - } - - /* - * Do not update this earlier, in case we return with an error. - * - * XXX: this in6_selectsrc result might replace the bound local - * address with the address specified by setsockopt(IPV6_PKTINFO). - * Is it the intended behavior? - */ - *plocal_addr6 = in6a; - - /* - * Don't do pcblookup call here; return interface in - * plocal_addr6 - * and exit to caller, that will do the lookup. - */ - - return (0); -} - -/* - * Outer subroutine: * Connect from a socket to a specified address. * Both address and port must be specified in argument sin. * If don't have a local address for this socket yet, @@ -375,30 +299,49 @@ in6_pcbconnect_mbuf(register struct inpc struct ucred *cred, struct mbuf *m) { struct inpcbinfo *pcbinfo = inp->inp_pcbinfo; - register struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)nam; + struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)nam; + struct ifnet *ifp = NULL; struct in6_addr addr6; int error; INP_WLOCK_ASSERT(inp); INP_HASH_WLOCK_ASSERT(pcbinfo); + if (nam->sa_len != sizeof(*sin6)) + return (EINVAL); + if (sin6->sin6_family != AF_INET6) + return (EAFNOSUPPORT); + if (sin6->sin6_port == 0) + return (EADDRNOTAVAIL); + /* + * If the destination address is UNSPECIFIED addr, use the loopback + * addr, e.g ::1. + */ + if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) + sin6->sin6_addr = in6addr_loopback; + /* + * Check sin6_scope_id and automatically fill it, if possible. + */ + error = sa6_checkzone(sin6); + if (error != 0) + return (error); + if ((error = prison_remote_ip6(inp->inp_cred, &sin6->sin6_addr)) != 0) + return (error); /* - * Call inner routine, to assign local interface address. - * in6_pcbladdr() may automatically fill in sin6_scope_id. + * Determine source address and outgoing interface. */ - if ((error = in6_pcbladdr(inp, nam, &addr6)) != 0) + error = in6_selectsrc(sin6, inp->in6p_outputopts, inp, NULL, + inp->inp_cred, &ifp, &addr6); + if (error) return (error); if (in6_pcblookup_hash_locked(pcbinfo, &sin6->sin6_addr, - sin6->sin6_port, - IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr) - ? &addr6 : &inp->in6p_laddr, - inp->inp_lport, 0, NULL) != NULL) { + sin6->sin6_port, IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr) ? + &addr6: &inp->in6p_laddr, inp->inp_lport, 0, ifp) != NULL) return (EADDRINUSE); - } if (IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)) { if (inp->inp_lport == 0) { - error = in6_pcbbind(inp, (struct sockaddr *)0, cred); + error = in6_pcbbind(inp, NULL, cred); if (error) return (error); } @@ -406,6 +349,10 @@ in6_pcbconnect_mbuf(register struct inpc } inp->in6p_faddr = sin6->sin6_addr; inp->inp_fport = sin6->sin6_port; + if (IN6_IS_ADDR_LINKLOCAL(&inp->in6p_faddr) || + IN6_IS_ADDR_LINKLOCAL(&inp->in6p_laddr)) + inp->in6p_zoneid = in6_getscopezone(ifp, + IPV6_ADDR_SCOPE_LINKLOCAL); /* update flowinfo - draft-itojun-ipv6-flowlabel-api-00 */ inp->inp_flow &= ~IPV6_FLOWLABEL_MASK; if (inp->inp_flags & IN6P_AUTOFLOWLABEL) From owner-svn-src-user@FreeBSD.ORG Wed Oct 16 08:21:44 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id BDBC54F6; Wed, 16 Oct 2013 08:21:44 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id ABB2529E2; Wed, 16 Oct 2013 08:21:44 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9G8Li91071591; Wed, 16 Oct 2013 08:21:44 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9G8LiqR071590; Wed, 16 Oct 2013 08:21:44 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310160821.r9G8LiqR071590@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 16 Oct 2013 08:21:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256595 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 08:21:44 -0000 Author: ae Date: Wed Oct 16 08:21:44 2013 New Revision: 256595 URL: http://svnweb.freebsd.org/changeset/base/256595 Log: Add in6_srcaddrscope() function. It is similar to in6_addrscope(), but returns link-local scope for IPv4-mapped addresses from 169.254/16 and 127/8 networks. Modified: user/ae/inet6/sys/netinet6/in6_src.c Modified: user/ae/inet6/sys/netinet6/in6_src.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6_src.c Wed Oct 16 08:19:58 2013 (r256594) +++ user/ae/inet6/sys/netinet6/in6_src.c Wed Oct 16 08:21:44 2013 (r256595) @@ -143,6 +143,7 @@ static int walk_addrsel_policy(int (*)(s void *); static int dump_addrsel_policyent(struct in6_addrpolicy *, void *); static struct in6_addrpolicy *match_addrsel_policy(struct sockaddr_in6 *); +static int in6_srcaddrscope(const struct in6_addr *); /* * Return an IPv6 address, which is the most appropriate for a given @@ -1184,3 +1185,20 @@ match_addrsel_policy(struct sockaddr_in6 return (bestpol); } + +/* + * This function is similar to in6_addrscope, but has some difference, + * specific for the source address selection algorithm (RFC 6724). + */ +static int +in6_srcaddrscope(const struct in6_addr *addr) +{ + + /* 169.254/16 and 127/8 have link-local scope */ + if (IN6_IS_ADDR_V4MAPPED(addr)) { + if (addr->s6_addr[12] == 127 || ( + addr->s6_addr[12] == 169 && addr->s6_addr[13] == 254)) + return (IPV6_ADDR_SCOPE_LINKLOCAL); + } + return (in6_addrscope(addr)); +} From owner-svn-src-user@FreeBSD.ORG Wed Oct 16 08:24:06 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id B9B236A7; Wed, 16 Oct 2013 08:24:06 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id A7B742A07; Wed, 16 Oct 2013 08:24:06 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9G8O6oM072207; Wed, 16 Oct 2013 08:24:06 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9G8O670072206; Wed, 16 Oct 2013 08:24:06 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310160824.r9G8O670072206@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 16 Oct 2013 08:24:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256596 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 08:24:06 -0000 Author: ae Date: Wed Oct 16 08:24:06 2013 New Revision: 256596 URL: http://svnweb.freebsd.org/changeset/base/256596 Log: Rename lookup_addrsel_policy() into lookup_policy_label(). Now it returns label insted of address policy. Modified: user/ae/inet6/sys/netinet6/in6_src.c Modified: user/ae/inet6/sys/netinet6/in6_src.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6_src.c Wed Oct 16 08:21:44 2013 (r256595) +++ user/ae/inet6/sys/netinet6/in6_src.c Wed Oct 16 08:24:06 2013 (r256596) @@ -134,7 +134,7 @@ static int in6_selectif(struct sockaddr_ struct ip6_moptions *, struct route_in6 *ro, struct ifnet **, struct ifnet *, u_int); -static struct in6_addrpolicy *lookup_addrsel_policy(struct sockaddr_in6 *); +static int lookup_policy_label(const struct in6_addr *, uint32_t); static void init_policy_queue(void); static int add_addrsel_policyent(struct in6_addrpolicy *); @@ -949,21 +949,24 @@ addrsel_policy_init(void) ADDRSEL_SXLOCK_INIT(); } -static struct in6_addrpolicy * -lookup_addrsel_policy(struct sockaddr_in6 *key) +static int +lookup_policy_label(const struct in6_addr *addr, uint32_t zoneid) { + struct sockaddr_in6 sa6; struct in6_addrpolicy *match = NULL; - ADDRSEL_LOCK(); - match = match_addrsel_policy(key); + sa6.sin6_addr = *addr; + sa6.sin6_scope_id = zoneid; + ADDRSEL_LOCK(); + match = match_addrsel_policy(&sa6); if (match == NULL) match = &V_defaultaddrpolicy; else match->use++; ADDRSEL_UNLOCK(); - return (match); + return (match->label); } /* From owner-svn-src-user@FreeBSD.ORG Wed Oct 16 08:30:30 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id AE585861; Wed, 16 Oct 2013 08:30:30 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 8CF6C2A7A; Wed, 16 Oct 2013 08:30:30 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9G8UU9J076186; Wed, 16 Oct 2013 08:30:30 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9G8UUUS076184; Wed, 16 Oct 2013 08:30:30 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310160830.r9G8UUUS076184@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 16 Oct 2013 08:30:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256597 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 08:30:30 -0000 Author: ae Date: Wed Oct 16 08:30:30 2013 New Revision: 256597 URL: http://svnweb.freebsd.org/changeset/base/256597 Log: * Add srcaddrcmp() function to compare addresses using SAS Algorithm; * add srcaddr_choice and dstaddr_props structures to describe source and destination addresses; * remove old REPLACE, NEXT and BREAK macros; Modified: user/ae/inet6/sys/netinet6/in6_src.c Modified: user/ae/inet6/sys/netinet6/in6_src.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6_src.c Wed Oct 16 08:24:06 2013 (r256596) +++ user/ae/inet6/sys/netinet6/in6_src.c Wed Oct 16 08:30:30 2013 (r256597) @@ -151,27 +151,148 @@ static int in6_srcaddrscope(const struct * If necessary, this function lookups the routing table and returns * an entry to the caller for later use. */ -#define REPLACE(r) do {\ - IP6STAT_INC(ip6s_sources_rule[(r)]); \ - rule = (r); \ - /* { \ - char ip6buf[INET6_ADDRSTRLEN], ip6b[INET6_ADDRSTRLEN]; \ - printf("in6_selectsrc: replace %s with %s by %d\n", ia_best ? ip6_sprintf(ip6buf, &ia_best->ia_addr.sin6_addr) : "none", ip6_sprintf(ip6b, &ia->ia_addr.sin6_addr), (r)); \ - } */ \ - goto replace; \ -} while(0) -#define NEXT(r) do {\ - /* { \ - char ip6buf[INET6_ADDRSTRLEN], ip6b[INET6_ADDRSTRLEN]; \ - printf("in6_selectsrc: keep %s against %s by %d\n", ia_best ? ip6_sprintf(ip6buf, &ia_best->ia_addr.sin6_addr) : "none", ip6_sprintf(ip6b, &ia->ia_addr.sin6_addr), (r)); \ - } */ \ - goto next; /* XXX: we can't use 'continue' here */ \ -} while(0) -#define BREAK(r) do { \ - IP6STAT_INC(ip6s_sources_rule[(r)]); \ - rule = (r); \ - goto out; /* XXX: we can't use 'break' here */ \ -} while(0) +struct srcaddr_choice { + struct in6_ifaddr *ia; + int scope; + int label; + int prefixlen; + int rule; +}; +struct dstaddr_props { + struct ifnet *ifp; + struct in6_addr *addr; + int scope; + int label; + int prefixlen; +}; + +#define REPLACE(r) { rule = r; goto replace; } +#define NEXT(r) { rule = r; goto next; } + +static int +srcaddrcmp(struct srcaddr_choice *c, struct in6_ifaddr *ia, + struct dstaddr_props *dst, struct ucred *cred, + struct ip6_pktopts *opts) +{ + int srcscope, rule, label, prefer_tempaddr, prefixlen; + + /* Avoid unusable addresses */ + if ((ia->ia6_flags & (IN6_IFF_NOTREADY | IN6_IFF_DETACHED)) || + (ia->ia_ifp->if_flags & IFF_UP) == 0) + return (-1); + /* + * In any case, multicast addresses and the unspecified address + * MUST NOT be included in a candidate set. + */ + if (IN6_IS_ADDR_MULTICAST(IA6_IN6(ia)) || + IN6_IS_ADDR_UNSPECIFIED(IA6_IN6(ia))) + return (-1); + if (!V_ip6_use_deprecated && IFA6_IS_DEPRECATED(ia)) + return (-1); + /* If jailed, only take addresses of the jail into account. */ + if (cred != NULL && prison_check_ip6(cred, IA6_IN6(ia)) != 0) + return (-1); + /* Source address can not break the destination zone */ + srcscope = in6_srcaddrscope(IA6_IN6(ia)); + if (ia->ia_ifp != dst->ifp && + in6_getscopezone(ia->ia_ifp, srcscope) != + in6_getscopezone(dst->ifp, dst->scope)) + return (-1); + label = ADDR_LABEL_NOTAPP; + prefixlen = -1; + /* Rule 1: Prefer same address. */ + if (IN6_ARE_ADDR_EQUAL(IA6_IN6(ia), dst->addr)) + REPLACE(1); + /* Rule 2: Prefer appropriate scope. */ + if (c->ia == NULL) { + dst->label = lookup_policy_label(dst->addr, + in6_getscopezone(dst->ifp, dst->scope)); + REPLACE(0); + } + if (IN6_ARE_SCOPE_CMP(c->scope, srcscope) < 0) { + if (IN6_ARE_SCOPE_CMP(c->scope, dst->scope) < 0) + REPLACE(2); + NEXT(2); + } else if (IN6_ARE_SCOPE_CMP(srcscope, c->scope) < 0) { + if (IN6_ARE_SCOPE_CMP(srcscope, dst->scope) < 0) + NEXT(2); + REPLACE(2); + } + /* Rule 3: Avoid deprecated addresses. */ + if (!IFA6_IS_DEPRECATED(c->ia) && IFA6_IS_DEPRECATED(ia)) + NEXT(3); + if (IFA6_IS_DEPRECATED(c->ia) && !IFA6_IS_DEPRECATED(ia)) + REPLACE(3); + /* + * Rule 4: Prefer home addresses. + * XXX: This is a TODO. + */ + /* Rule 5: Prefer outgoing interface. */ + if (c->ia->ia_ifp == dst->ifp && ia->ia_ifp != dst->ifp) + NEXT(5); + if (c->ia->ia_ifp != dst->ifp && ia->ia_ifp == dst->ifp) + REPLACE(5); + /* + * Rule 5.5: Prefer addresses in a prefix advertised by + * the next-hop. + * XXX: not yet. + */ + /* Rule 6: Prefer matching label. */ + if (dst->label != ADDR_LABEL_NOTAPP) { + c->label = lookup_policy_label(IA6_IN6(c->ia), + in6_getscopezone(c->ia->ia_ifp, c->scope)); + label = lookup_policy_label(IA6_IN6(ia), + in6_getscopezone(ia->ia_ifp, srcscope)); + if (c->label == dst->label && label != dst->label) + NEXT(6); + if (label == dst->label && c->label != dst->label) + REPLACE(6); + } + /* Rule 7: Prefer temporary addresses. */ + if (opts == NULL || + opts->ip6po_prefer_tempaddr == IP6PO_TEMPADDR_SYSTEM) + prefer_tempaddr = V_ip6_prefer_tempaddr; + else if (opts->ip6po_prefer_tempaddr == IP6PO_TEMPADDR_NOTPREFER) + prefer_tempaddr = 0; + else + prefer_tempaddr = 1; + if ((c->ia->ia6_flags & IN6_IFF_TEMPORARY) != 0 && + (ia->ia6_flags & IN6_IFF_TEMPORARY) == 0) { + if (prefer_tempaddr) + NEXT(7); + REPLACE(7); + } + if ((c->ia->ia6_flags & IN6_IFF_TEMPORARY) == 0 && + (ia->ia6_flags & IN6_IFF_TEMPORARY) != 0) { + if (prefer_tempaddr) + REPLACE(7); + NEXT(7); + } + /* Rule 8: Use longest matching prefix. */ + if (c->prefixlen < 0) + c->prefixlen = in6_matchlen(IA6_IN6(c->ia), dst->addr); + prefixlen = in6_matchlen(IA6_IN6(ia), dst->addr); + if (c->prefixlen > prefixlen) + NEXT(8); + if (prefixlen > c->prefixlen) + REPLACE(8); + return (-1); +replace: + /* debug output */ + c->ia = ia; + c->label = label; + c->scope = srcscope; + c->rule = rule; + c->prefixlen = prefixlen; + /* Update statistic */ + IP6STAT_INC(ip6s_sources_rule[rule]); + return (rule); +next: + /* debug output */ + return (rule); +} +#undef REPLACE +#undef NEXT int in6_selectsrc(struct sockaddr_in6 *dstsock, struct ip6_pktopts *opts, From owner-svn-src-user@FreeBSD.ORG Wed Oct 16 08:48:46 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id EB61AC13; Wed, 16 Oct 2013 08:48:46 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id C92042B58; Wed, 16 Oct 2013 08:48:46 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9G8mkox083898; Wed, 16 Oct 2013 08:48:46 GMT (envelope-from glebius@svn.freebsd.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9G8mjP9083881; Wed, 16 Oct 2013 08:48:45 GMT (envelope-from glebius@svn.freebsd.org) Message-Id: <201310160848.r9G8mjP9083881@svn.freebsd.org> From: Gleb Smirnoff Date: Wed, 16 Oct 2013 08:48:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256598 - in user/glebius/course/04.synchronisation/code: . application call module X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 08:48:47 -0000 Author: glebius Date: Wed Oct 16 08:48:45 2013 New Revision: 256598 URL: http://svnweb.freebsd.org/changeset/base/256598 Log: An example module that handles a double linked list in racy manner. Added: user/glebius/course/04.synchronisation/code/ - copied from r256591, user/glebius/course/02.entering_kernel/syscall/ user/glebius/course/04.synchronisation/code/call/ - copied from r256591, user/glebius/course/02.entering_kernel/syscall/application/ user/glebius/course/04.synchronisation/code/module/api.h (contents, props changed) user/glebius/course/04.synchronisation/code/module/syscall.c - copied, changed from r256591, user/glebius/course/02.entering_kernel/syscall/module/foo_syscall.c Deleted: user/glebius/course/04.synchronisation/code/application/ user/glebius/course/04.synchronisation/code/module/foo_syscall.c Modified: user/glebius/course/04.synchronisation/code/Makefile user/glebius/course/04.synchronisation/code/call/Makefile user/glebius/course/04.synchronisation/code/call/call.c user/glebius/course/04.synchronisation/code/module/Makefile Modified: user/glebius/course/04.synchronisation/code/Makefile ============================================================================== --- user/glebius/course/02.entering_kernel/syscall/Makefile Wed Oct 16 06:15:40 2013 (r256591) +++ user/glebius/course/04.synchronisation/code/Makefile Wed Oct 16 08:48:45 2013 (r256598) @@ -1,3 +1,3 @@ -SUBDIR= module application +SUBDIR= module call .include Modified: user/glebius/course/04.synchronisation/code/call/Makefile ============================================================================== --- user/glebius/course/02.entering_kernel/syscall/application/Makefile Wed Oct 16 06:15:40 2013 (r256591) +++ user/glebius/course/04.synchronisation/code/call/Makefile Wed Oct 16 08:48:45 2013 (r256598) @@ -1,4 +1,6 @@ PROG= call +CFLAGS+= -I../module + NO_MAN= .include Modified: user/glebius/course/04.synchronisation/code/call/call.c ============================================================================== --- user/glebius/course/02.entering_kernel/syscall/application/call.c Wed Oct 16 06:15:40 2013 (r256591) +++ user/glebius/course/04.synchronisation/code/call/call.c Wed Oct 16 08:48:45 2013 (r256598) @@ -5,13 +5,17 @@ #include #include #include +#include #include +#include + int main(int argc, char **argv) { int modid, syscall_num; struct module_stat stat; + int what; stat.version = sizeof(stat); if ((modid = modfind("sys/foo_syscall")) == -1) @@ -20,5 +24,15 @@ main(int argc, char **argv) err(1, "modstat"); syscall_num = stat.data.intval; - return syscall(syscall_num, argc, argv); + if (argc < 2) + err(1, "argument required"); + + if (strcmp(argv[1], "add") == 0) + what = ADD; + else if (strcmp(argv[1], "delete") == 0) + what = DELETE; + else + err(1, "add or delete"); + + return syscall(syscall_num, what, argv); } Modified: user/glebius/course/04.synchronisation/code/module/Makefile ============================================================================== --- user/glebius/course/02.entering_kernel/syscall/module/Makefile Wed Oct 16 06:15:40 2013 (r256591) +++ user/glebius/course/04.synchronisation/code/module/Makefile Wed Oct 16 08:48:45 2013 (r256598) @@ -1,4 +1,4 @@ -KMOD= foo_syscall -SRCS= foo_syscall.c +KMOD= syscall +SRCS= syscall.c .include Added: user/glebius/course/04.synchronisation/code/module/api.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/glebius/course/04.synchronisation/code/module/api.h Wed Oct 16 08:48:45 2013 (r256598) @@ -0,0 +1,4 @@ +enum { + ADD = 1, + DELETE +}; Copied and modified: user/glebius/course/04.synchronisation/code/module/syscall.c (from r256591, user/glebius/course/02.entering_kernel/syscall/module/foo_syscall.c) ============================================================================== --- user/glebius/course/02.entering_kernel/syscall/module/foo_syscall.c Wed Oct 16 06:15:40 2013 (r256591, copy source) +++ user/glebius/course/04.synchronisation/code/module/syscall.c Wed Oct 16 08:48:45 2013 (r256598) @@ -6,6 +6,8 @@ #include #include +#include + /* * ABI for arguments. Arguments should be aligned by * register size. @@ -24,6 +26,14 @@ struct foo_args { char p_l_[PADL_(int)]; void *p; char p_r_[PADR_(int)]; }; +struct foo_entry { + LIST_ENTRY(foo_entry) foo_link; +}; + +static LIST_HEAD(, foo_entry) foo_head; + +MALLOC_DEFINE(M_FOO, "foo", "foo entries"); + /* * The function implementing the syscall. */ @@ -31,9 +41,25 @@ static int foo_syscall(struct thread *td, void *arg) { struct foo_args *args = (struct foo_args *)arg; + struct foo_entry *ent; + int d = args->d; + + switch (d) { + case ADD: + ent = malloc(sizeof(*ent), M_FOO, M_WAITOK); + LIST_INSERT_HEAD(&foo_head, ent, foo_link); + break; + case DELETE: + ent = LIST_FIRST(&foo_head); + if (ent) { + LIST_REMOVE(ent, foo_link); + free(ent, M_FOO); + } + break; + default: + return (EINVAL); + }; - printf("arguments %d %p\n", - args->d, args->p); return (0); } @@ -59,6 +85,7 @@ foo_load(struct module *module, int cmd, switch (cmd) { case MOD_LOAD : + LIST_INIT(&foo_head); printf("syscall loaded at %d\n", offset); break; case MOD_UNLOAD : From owner-svn-src-user@FreeBSD.ORG Wed Oct 16 08:58:58 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id E4556224; Wed, 16 Oct 2013 08:58:58 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id D26BE2C3B; Wed, 16 Oct 2013 08:58:58 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9G8wwEG088992; Wed, 16 Oct 2013 08:58:58 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9G8wwCt088991; Wed, 16 Oct 2013 08:58:58 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310160858.r9G8wwCt088991@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 16 Oct 2013 08:58:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256599 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 08:58:59 -0000 Author: ae Date: Wed Oct 16 08:58:58 2013 New Revision: 256599 URL: http://svnweb.freebsd.org/changeset/base/256599 Log: Add cached_rtlookup() function. It validates route and if it is ok, returns it. Otherwise it does new route lookup. Modified: user/ae/inet6/sys/netinet6/in6_src.c Modified: user/ae/inet6/sys/netinet6/in6_src.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6_src.c Wed Oct 16 08:48:45 2013 (r256598) +++ user/ae/inet6/sys/netinet6/in6_src.c Wed Oct 16 08:58:58 2013 (r256599) @@ -127,6 +127,9 @@ static VNET_DEFINE(struct in6_addrpolicy VNET_DEFINE(int, ip6_prefer_tempaddr) = 0; +static int cached_rtlookup(const struct sockaddr_in6 *dst, + struct route_in6 *ro, u_int fibnum); + static int selectroute(struct sockaddr_in6 *, struct ip6_pktopts *, struct ip6_moptions *, struct route_in6 *, struct ifnet **, struct rtentry **, int, u_int); @@ -294,6 +297,33 @@ next: #undef REPLACE #undef NEXT +static int +cached_rtlookup(const struct sockaddr_in6 *dst, struct route_in6 *ro, + u_int fibnum) +{ + + /* + * Use a cached route if it exists and is valid, else try to allocate + * a new one. Note that we should check the address family of the + * cached destination, in case of sharing the cache with IPv4. + */ + KASSERT(ro != NULL, ("%s: ro is NULL", __func__)); + if (ro->ro_rt != NULL && ( + (ro->ro_rt->rt_flags & RTF_UP) == 0 || + ro->ro_dst.sin6_family != AF_INET6 || + !IN6_ARE_ADDR_EQUAL(&ro->ro_dst.sin6_addr, &dst->sin6_addr))) { + RO_RTFREE(ro); + } + if (ro->ro_rt == NULL) { + /* No route yet, so try to acquire one */ + memcpy(&ro->ro_dst, dst, sizeof(*dst)); + in6_rtalloc(ro, fibnum); + } + if (ro->ro_rt == NULL) + return (EHOSTUNREACH); + return (0); +} + int in6_selectsrc(struct sockaddr_in6 *dstsock, struct ip6_pktopts *opts, struct inpcb *inp, struct route_in6 *ro, struct ucred *cred, From owner-svn-src-user@FreeBSD.ORG Wed Oct 16 09:02:12 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id F303A4F9; Wed, 16 Oct 2013 09:02:11 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id C869F2C91; Wed, 16 Oct 2013 09:02:11 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9G92BPW092777; Wed, 16 Oct 2013 09:02:11 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9G92BnT092776; Wed, 16 Oct 2013 09:02:11 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310160902.r9G92BnT092776@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 16 Oct 2013 09:02:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256600 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 09:02:12 -0000 Author: ae Date: Wed Oct 16 09:02:11 2013 New Revision: 256600 URL: http://svnweb.freebsd.org/changeset/base/256600 Log: Add check_scopezones() function to check that source address doesn't break destination scope zone. Modified: user/ae/inet6/sys/netinet6/in6_src.c Modified: user/ae/inet6/sys/netinet6/in6_src.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6_src.c Wed Oct 16 08:58:58 2013 (r256599) +++ user/ae/inet6/sys/netinet6/in6_src.c Wed Oct 16 09:02:11 2013 (r256600) @@ -129,6 +129,9 @@ VNET_DEFINE(int, ip6_prefer_tempaddr) = static int cached_rtlookup(const struct sockaddr_in6 *dst, struct route_in6 *ro, u_int fibnum); +static int check_scopezones(const struct sockaddr_in6 *dst, + struct route_in6 *ro, u_int fibnum, const struct ip6_moptions *mopts, + const struct in6_addr *src, const struct ifnet *ifp); static int selectroute(struct sockaddr_in6 *, struct ip6_pktopts *, struct ip6_moptions *, struct route_in6 *, struct ifnet **, @@ -324,6 +327,38 @@ cached_rtlookup(const struct sockaddr_in return (0); } +static int +check_scopezones(const struct sockaddr_in6 *dst, struct route_in6 *ro, + u_int fibnum, const struct ip6_moptions *mopts, const struct in6_addr *src, + const struct ifnet *ifp) +{ + struct ifnet *oifp; + + oifp = NULL; + /* Determine zone index of destination address. */ + if (IN6_IS_SCOPE_LINKLOCAL(&dst->sin6_addr) || + IN6_IS_ADDR_MC_INTFACELOCAL(&dst->sin6_addr)) { + if (dst->sin6_scope_id == 0) + return (EHOSTUNREACH); + oifp = in6_getlinkifnet(dst->sin6_scope_id); + } else if (IN6_IS_ADDR_MULTICAST(&dst->sin6_addr) && + mopts != NULL && mopts->im6o_multicast_ifp != NULL) { + oifp = mopts->im6o_multicast_ifp; + } else { + if (cached_rtlookup(dst, ro, fibnum) == 0) + oifp = ro->ro_rt->rt_ifp; + } + if (oifp == NULL) + return (EHOSTUNREACH); + + if (oifp != ifp && + in6_getscopezone(ifp, in6_srcaddrscope(src)) != + in6_getscopezone(oifp, in6_srcaddrscope(&dst->sin6_addr))) + return (EHOSTUNREACH); + + return (0); +} + int in6_selectsrc(struct sockaddr_in6 *dstsock, struct ip6_pktopts *opts, struct inpcb *inp, struct route_in6 *ro, struct ucred *cred, From owner-svn-src-user@FreeBSD.ORG Wed Oct 16 09:03:38 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id E25737C5; Wed, 16 Oct 2013 09:03:38 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id B63272CAE; Wed, 16 Oct 2013 09:03:38 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9G93cRj093612; Wed, 16 Oct 2013 09:03:38 GMT (envelope-from glebius@svn.freebsd.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9G93cE2093609; Wed, 16 Oct 2013 09:03:38 GMT (envelope-from glebius@svn.freebsd.org) Message-Id: <201310160903.r9G93cE2093609@svn.freebsd.org> From: Gleb Smirnoff Date: Wed, 16 Oct 2013 09:03:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256601 - in user/glebius/course/04.synchronisation/code: . call module X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 09:03:39 -0000 Author: glebius Date: Wed Oct 16 09:03:37 2013 New Revision: 256601 URL: http://svnweb.freebsd.org/changeset/base/256601 Log: Minor nits and a script to demonstrate race. Added: user/glebius/course/04.synchronisation/code/stress.sh (contents, props changed) Modified: user/glebius/course/04.synchronisation/code/call/call.c user/glebius/course/04.synchronisation/code/module/Makefile Modified: user/glebius/course/04.synchronisation/code/call/call.c ============================================================================== --- user/glebius/course/04.synchronisation/code/call/call.c Wed Oct 16 09:02:11 2013 (r256600) +++ user/glebius/course/04.synchronisation/code/call/call.c Wed Oct 16 09:03:37 2013 (r256601) @@ -25,14 +25,14 @@ main(int argc, char **argv) syscall_num = stat.data.intval; if (argc < 2) - err(1, "argument required"); + errx(1, "argument required"); if (strcmp(argv[1], "add") == 0) what = ADD; else if (strcmp(argv[1], "delete") == 0) what = DELETE; else - err(1, "add or delete"); + errx(1, "add or delete"); return syscall(syscall_num, what, argv); } Modified: user/glebius/course/04.synchronisation/code/module/Makefile ============================================================================== --- user/glebius/course/04.synchronisation/code/module/Makefile Wed Oct 16 09:02:11 2013 (r256600) +++ user/glebius/course/04.synchronisation/code/module/Makefile Wed Oct 16 09:03:37 2013 (r256601) @@ -1,4 +1,5 @@ KMOD= syscall SRCS= syscall.c +DEBUG_FLAGS=-g .include Added: user/glebius/course/04.synchronisation/code/stress.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/glebius/course/04.synchronisation/code/stress.sh Wed Oct 16 09:03:37 2013 (r256601) @@ -0,0 +1,6 @@ +#!/bin/sh + +while (true); do ./call/call add; done & +while (true); do ./call/call add; done & +while (true); do ./call/call delete; done & +while (true); do ./call/call delete; done & From owner-svn-src-user@FreeBSD.ORG Wed Oct 16 09:05:49 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id CE3289F8; Wed, 16 Oct 2013 09:05:49 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id AB6BE2CCC; Wed, 16 Oct 2013 09:05:49 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9G95nmf094259; Wed, 16 Oct 2013 09:05:49 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9G95niG094258; Wed, 16 Oct 2013 09:05:49 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310160905.r9G95niG094258@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 16 Oct 2013 09:05:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256602 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 09:05:49 -0000 Author: ae Date: Wed Oct 16 09:05:49 2013 New Revision: 256602 URL: http://svnweb.freebsd.org/changeset/base/256602 Log: Add handle_pktinfo() function to handle IPV6_PKTINFO advanced socket option. Modified: user/ae/inet6/sys/netinet6/in6_src.c Modified: user/ae/inet6/sys/netinet6/in6_src.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6_src.c Wed Oct 16 09:03:37 2013 (r256601) +++ user/ae/inet6/sys/netinet6/in6_src.c Wed Oct 16 09:05:49 2013 (r256602) @@ -132,6 +132,10 @@ static int cached_rtlookup(const struct static int check_scopezones(const struct sockaddr_in6 *dst, struct route_in6 *ro, u_int fibnum, const struct ip6_moptions *mopts, const struct in6_addr *src, const struct ifnet *ifp); +static int handle_pktinfo(const struct sockaddr_in6 *dst, + const struct in6_pktinfo* pi, const struct ip6_moptions *mopts, + struct route_in6 *ro, u_int fibnum, struct ifnet **ifpp, + struct in6_addr *srcp, int *done); static int selectroute(struct sockaddr_in6 *, struct ip6_pktopts *, struct ip6_moptions *, struct route_in6 *, struct ifnet **, @@ -359,6 +363,130 @@ check_scopezones(const struct sockaddr_i return (0); } +/* + * dst - original destination address; + * pi - options configured via IPV6_PKTINFO; + * mopts - options configured via IPV6_MULTICAST_IF; + * ro - route to destination; + * fibnum - FIB number + * + * These parameters are returned back to caller: + * ifpp - determined outgoing interface; + * srcp - determined source address; + * done - if set, this means that outgoing interface and + * source address were determined. + * + * NOTE: don't forget to RTFREE(ro->ro_rt) after calling this function, + * if needed of course. + */ +static int +handle_pktinfo(const struct sockaddr_in6 *dst, + const struct in6_pktinfo* pi, const struct ip6_moptions *mopts, + struct route_in6 *ro, u_int fibnum, struct ifnet **ifpp, + struct in6_addr *srcp, int *done) +{ + struct in6_ifaddr *ia; + struct ifnet *ifp; + + ifp = NULL; + *done = 0; + if (pi->ipi6_ifindex != 0) { + ifp = ifnet_byindex(pi->ipi6_ifindex); + if (ifp == NULL) + return (ENXIO); + if (ND_IFINFO(ifp)->flags & ND6_IFF_IFDISABLED) + return (ENETDOWN); + } + if (ifp != NULL && IN6_IS_ADDR_UNSPECIFIED(&pi->ipi6_addr)) { + /* + * If an interface is explicitly specified, use it. + */ + *ifpp = ifp; + return (0); + } + if (ifp != NULL && !IN6_IS_ADDR_UNSPECIFIED(&pi->ipi6_addr)) { + /* + * If both, address and ifindex are specified via + * IPV6_PKTINFO, then check that address is available + * on this interface. + */ + ia = in6ifa_ifpwithaddr(ifp, &pi->ipi6_addr); + } else { + /* + * If address is specified via IPV6_PKTINFO, but interface + * isn't, we can determine interface for a global unicast + * from the ifaddr hash. + */ + if (!IN6_IS_ADDR_LINKLOCAL(&pi->ipi6_addr)) { + /* ipi6_addr is global. */ + ia = in6ifa_ifwithaddr(&pi->ipi6_addr, 0); + } else if (IN6_IS_ADDR_MULTICAST(&dst->sin6_addr)) { + /* ipi6_addr is link-local, dst is multicast. */ + if (mopts != NULL && + mopts->im6o_multicast_ifp != NULL) { + /* + * Outgoing interface is specified via + * IPV6_MULTICAST_IF socket option. + */ + ia = in6ifa_ifpwithaddr( + mopts->im6o_multicast_ifp, &pi->ipi6_addr); + } else if (dst->sin6_scope_id != 0 && ( /* XXX */ + IN6_IS_ADDR_MC_LINKLOCAL(&dst->sin6_addr) || + IN6_IS_ADDR_MC_INTFACELOCAL(&dst->sin6_addr))) { + /* + * Destination multicast address is in the + * link-local or interface-local scope. + * Use its sin6_scope_id to determine + * outgoing interface. + */ + ia = in6ifa_ifwithaddr(&pi->ipi6_addr, + dst->sin6_scope_id); + } else { + /* + * XXX: Try to lookup route for this multicast + * destination address. + */ + if (cached_rtlookup(dst, ro, fibnum) != 0) + return (EHOSTUNREACH); + ia = in6ifa_ifpwithaddr(ro->ro_rt->rt_ifp, + &pi->ipi6_addr); + } + } else if (IN6_IS_ADDR_LINKLOCAL(&dst->sin6_addr)) { + /* both are link-local. */ + ia = in6ifa_ifwithaddr(&pi->ipi6_addr, + dst->sin6_scope_id); + } else { + /* ipi6_addr is link-local, dst is global. */ + if (cached_rtlookup(dst, ro, fibnum) != 0) + return (EHOSTUNREACH); + /* Check that address is available on interface. */ + ia = in6ifa_ifpwithaddr(ro->ro_rt->rt_ifp, + &pi->ipi6_addr); + } + } + if (ia == NULL || ( + ia->ia6_flags & (IN6_IFF_ANYCAST | IN6_IFF_NOTREADY))) { + RO_RTFREE(ro); + if (ia != NULL) + ifa_free(&ia->ia_ifa); + return (EADDRNOTAVAIL); + } + ifp = ia->ia_ifp; + ifa_free(&ia->ia_ifa); + /* + * Source address can not break the destination zone. + */ + if (check_scopezones(dst, ro, fibnum, mopts, &pi->ipi6_addr, + ifp) != 0) { + RO_RTFREE(ro); + return (EHOSTUNREACH); + } + *ifpp = ifp; + *srcp = pi->ipi6_addr; + *done = 1; + return (0); +} + int in6_selectsrc(struct sockaddr_in6 *dstsock, struct ip6_pktopts *opts, struct inpcb *inp, struct route_in6 *ro, struct ucred *cred, From owner-svn-src-user@FreeBSD.ORG Wed Oct 16 09:15:07 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id D7887EA1; Wed, 16 Oct 2013 09:15:07 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id B63F52D6C; Wed, 16 Oct 2013 09:15:07 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9G9F7PA099226; Wed, 16 Oct 2013 09:15:07 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9G9F7hJ099225; Wed, 16 Oct 2013 09:15:07 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310160915.r9G9F7hJ099225@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 16 Oct 2013 09:15:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256604 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 09:15:08 -0000 Author: ae Date: Wed Oct 16 09:15:07 2013 New Revision: 256604 URL: http://svnweb.freebsd.org/changeset/base/256604 Log: Add handle_nexthop() function to handle IPV6_NEXTHOP advanced socket API option. Modified: user/ae/inet6/sys/netinet6/in6_src.c Modified: user/ae/inet6/sys/netinet6/in6_src.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6_src.c Wed Oct 16 09:12:40 2013 (r256603) +++ user/ae/inet6/sys/netinet6/in6_src.c Wed Oct 16 09:15:07 2013 (r256604) @@ -132,6 +132,8 @@ static int cached_rtlookup(const struct static int check_scopezones(const struct sockaddr_in6 *dst, struct route_in6 *ro, u_int fibnum, const struct ip6_moptions *mopts, const struct in6_addr *src, const struct ifnet *ifp); +static int handle_nexthop(struct ip6po_nhinfo *nh, u_int fibnum, + struct ifnet **ifpp); static int handle_pktinfo(const struct sockaddr_in6 *dst, const struct in6_pktinfo* pi, const struct ip6_moptions *mopts, struct route_in6 *ro, u_int fibnum, struct ifnet **ifpp, @@ -487,6 +489,71 @@ handle_pktinfo(const struct sockaddr_in6 return (0); } +/* + * nh - next hop destination and route; + * fibnum - FIB number. + * ifpp - pointer to outgoing interface. + * + * NOTE: we can keep this route, it will be freed in the socket + * option handling code (see ip6_output.c). + */ +static int +handle_nexthop(struct ip6po_nhinfo *nh, u_int fibnum, struct ifnet **ifpp) +{ + struct sockaddr_in6 *sa; + struct in6_ifaddr *ia; + struct route_in6 *ro; + struct ifnet *ifp, *oifp; + + sa = (struct sockaddr_in6 *)nh->ip6po_nhi_nexthop; + ro = &nh->ip6po_nhi_route; + if (sa->sin6_family != AF_INET6) + return (EAFNOSUPPORT); + /* + * If *ifpp is not NULL, this means that outgoing interface + * was determined in the PKTINFO handling code. + */ + oifp = *ifpp; + + /* + * Check that the next hop address is our own. + */ + ia = in6ifa_ifwithaddr(&sa->sin6_addr, sa->sin6_scope_id); + if (ia != NULL) { + /* Address is our own. */ + ifp = ia->ia_ifp; + ifa_free(&ia->ia_ifa); + } else { + /* + * Address is not our own. + * Determine outgoing interface by zone index. + */ + if (IN6_IS_ADDR_LINKLOCAL(&sa->sin6_addr)) + ifp = in6_getlinkifnet(sa->sin6_scope_id); + else { + if (cached_rtlookup(sa, ro, fibnum) != 0) + return (EHOSTUNREACH); + /* + * The node identified by that address must be a + * neighbor of the sending host. + */ + if (ro->ro_rt->rt_flags & RTF_GATEWAY) + return (EHOSTUNREACH); + ifp = ro->ro_rt->rt_ifp; + } + } + /* + * When the outgoing interface is specified by IPV6_PKTINFO + * as well, the next hop specified by this option must be + * reachable via the specified interface. + */ + if (ifp == NULL || (oifp != NULL && oifp != ifp)) + return (EHOSTUNREACH); + + *ifpp = ifp; + return (0); +} + int in6_selectsrc(struct sockaddr_in6 *dstsock, struct ip6_pktopts *opts, struct inpcb *inp, struct route_in6 *ro, struct ucred *cred, From owner-svn-src-user@FreeBSD.ORG Wed Oct 16 09:17:46 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id C56F7FA8; Wed, 16 Oct 2013 09:17:46 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 99DF92D7E; Wed, 16 Oct 2013 09:17:46 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9G9Hk7n099870; Wed, 16 Oct 2013 09:17:46 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9G9HktA099869; Wed, 16 Oct 2013 09:17:46 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310160917.r9G9HktA099869@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 16 Oct 2013 09:17:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256605 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 09:17:46 -0000 Author: ae Date: Wed Oct 16 09:17:46 2013 New Revision: 256605 URL: http://svnweb.freebsd.org/changeset/base/256605 Log: When choosing hop limit, handle link-local destinations specially. Also some style fixes. Modified: user/ae/inet6/sys/netinet6/in6_src.c Modified: user/ae/inet6/sys/netinet6/in6_src.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6_src.c Wed Oct 16 09:15:07 2013 (r256604) +++ user/ae/inet6/sys/netinet6/in6_src.c Wed Oct 16 09:17:46 2013 (r256605) @@ -1242,35 +1242,41 @@ in6_selectroute_fib(struct sockaddr_in6 * 1. Hoplimit value specified via ioctl. * 2. (If the outgoing interface is detected) the current * hop limit of the interface specified by router advertisement. - * 3. The system default hoplimit. + * 3. If destination address is from link-local scope, use its zoneid + * to determine outgoing interface and use its hop limit. + * 4. The system default hoplimit. */ int in6_selecthlim(struct inpcb *in6p, struct ifnet *ifp) { + struct route_in6 ro6; if (in6p && in6p->in6p_hops >= 0) return (in6p->in6p_hops); - else if (ifp) + + if (ifp != NULL) return (ND_IFINFO(ifp)->chlim); - else if (in6p && !IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr)) { - struct route_in6 ro6; - struct ifnet *lifp; + /* XXX: should we check for multicast here?*/ + if (in6p && IN6_IS_ADDR_LINKLOCAL(&in6p->in6p_faddr)) { + if (in6p->in6p_zoneid != 0 && + (ifp = in6_getlinkifnet(in6p->in6p_zoneid))) + return (ND_IFINFO(ifp)->chlim); + } else if (in6p && !IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr)) { bzero(&ro6, sizeof(ro6)); ro6.ro_dst.sin6_family = AF_INET6; ro6.ro_dst.sin6_len = sizeof(struct sockaddr_in6); ro6.ro_dst.sin6_addr = in6p->in6p_faddr; in6_rtalloc(&ro6, in6p->inp_inc.inc_fibnum); if (ro6.ro_rt) { - lifp = ro6.ro_rt->rt_ifp; + ifp = ro6.ro_rt->rt_ifp; RTFREE(ro6.ro_rt); - if (lifp) - return (ND_IFINFO(lifp)->chlim); + if (ifp) + return (ND_IFINFO(ifp)->chlim); } } return (V_ip6_defhlim); } - /* * XXX: this is borrowed from in6_pcbbind(). If possible, we should * share this function by all *bsd*... From owner-svn-src-user@FreeBSD.ORG Wed Oct 16 09:25:01 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 2CD1750D; Wed, 16 Oct 2013 09:25:01 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 1A4662DFF; Wed, 16 Oct 2013 09:25:01 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9G9P0c1004489; Wed, 16 Oct 2013 09:25:00 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9G9P0R5004488; Wed, 16 Oct 2013 09:25:00 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310160925.r9G9P0R5004488@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 16 Oct 2013 09:25:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256608 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 09:25:01 -0000 Author: ae Date: Wed Oct 16 09:25:00 2013 New Revision: 256608 URL: http://svnweb.freebsd.org/changeset/base/256608 Log: Rewrite socket options handling code. Use handle_pktinfo(), handle_nexthop() and cached_rtlookup() functions. Jail code should be changed to support scope zones, for now just disable it and mark with XXX. Modified: user/ae/inet6/sys/netinet6/in6_src.c Modified: user/ae/inet6/sys/netinet6/in6_src.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6_src.c Wed Oct 16 09:21:40 2013 (r256607) +++ user/ae/inet6/sys/netinet6/in6_src.c Wed Oct 16 09:25:00 2013 (r256608) @@ -559,20 +559,23 @@ in6_selectsrc(struct sockaddr_in6 *dstso struct inpcb *inp, struct route_in6 *ro, struct ucred *cred, struct ifnet **ifpp, struct in6_addr *srcp) { - struct in6_addr dst, tmp; - struct ifnet *ifp = NULL, *oifp = NULL; - struct in6_ifaddr *ia = NULL, *ia_best = NULL; - struct in6_pktinfo *pi = NULL; - int dst_scope = -1, best_scope = -1, best_matchlen = -1; - struct in6_addrpolicy *dst_policy = NULL, *best_policy = NULL; - u_int32_t odstzone; - int prefer_tempaddr; - int error, rule; + struct route_in6 ro6; + struct dstaddr_props dstprops; + struct srcaddr_choice best; struct ip6_moptions *mopts; + struct in6_pktinfo *pi; + struct in6_ifaddr *ia; + struct ifaddr *ifa; + struct ifnet *ifp, *oifp; + u_int fibnum; + int error, done; KASSERT(srcp != NULL, ("%s: srcp is NULL", __func__)); + KASSERT(ifpp != NULL, ("%s: ifpp is NULL", __func__)); + KASSERT(sa6_checkzone(dst) == 0, ("%s: invalid zone information", + __func__)); - dst = dstsock->sin6_addr; /* make a copy for local operation */ + ifp = oifp = NULL; if (ifpp) { /* * Save a possibly passed in ifp for in6_selectsrc. Only @@ -589,82 +592,111 @@ in6_selectsrc(struct sockaddr_in6 *dstso if (inp != NULL) { INP_LOCK_ASSERT(inp); mopts = inp->in6p_moptions; + fibnum = inp->inp_inc.inc_fibnum; } else { mopts = NULL; + fibnum = RT_DEFAULT_FIB; + } + if (ro == NULL) { + ro = &ro6; + bzero(ro, sizeof(*ro)); } /* - * If the source address is explicitly specified by the caller, - * check if the requested source address is indeed a unicast address - * assigned to the node, and can be used as the packet's source - * address. If everything is okay, use the address as source. + * XXX: jail support MUST be added later! */ - if (opts && (pi = opts->ip6po_pktinfo) && - !IN6_IS_ADDR_UNSPECIFIED(&pi->ipi6_addr)) { - struct sockaddr_in6 srcsock; - struct in6_ifaddr *ia6; - - /* get the outgoing interface */ - if ((error = in6_selectif(dstsock, opts, mopts, ro, &ifp, oifp, - (inp != NULL) ? inp->inp_inc.inc_fibnum : RT_DEFAULT_FIB)) - != 0) + if (opts != NULL && (pi = opts->ip6po_pktinfo) != NULL) { + error = handle_pktinfo(dst, pi, mopts, ro, fibnum, + &ifp, srcp, &done); + if (error != 0) return (error); - + if (done != 0) { + /* + * When the outgoing interface is specified by + * IPV6_PKTINFO as well, the next hop specified by + * this option must be reachable via the specified + * interface. Also, we ignore next hop for multicast + * destinations. + */ + if (!IN6_IS_ADDR_MULTICAST(&dst->sin6_addr) && + opts->ip6po_nexthop != NULL) + error = handle_nexthop(&opts->ip6po_nhinfo, + fibnum, &ifp); + if (error != 0 || ro == &ro6) + RO_RTFREE(ro); + if (error == 0) + *ifpp = ifp; + return (error); + } + } else if (IN6_IS_ADDR_MULTICAST(&dst->sin6_addr)) { /* - * determine the appropriate zone id of the source based on - * the zone of the destination and the outgoing interface. - * If the specified address is ambiguous wrt the scope zone, - * the interface must be specified; otherwise, ifa_ifwithaddr() - * will fail matching the address. + * If the destination address is a multicast address and + * the IPV6_MULTICAST_IF socket option is specified for the + * socket, the interface is used. */ - bzero(&srcsock, sizeof(srcsock)); - srcsock.sin6_family = AF_INET6; - srcsock.sin6_len = sizeof(srcsock); - srcsock.sin6_addr = pi->ipi6_addr; - if (ifp) { - error = in6_setscope(&srcsock.sin6_addr, ifp, NULL); - if (error) - return (error); - } - if (cred != NULL && (error = prison_local_ip6(cred, - &srcsock.sin6_addr, (inp != NULL && - (inp->inp_flags & IN6P_IPV6_V6ONLY) != 0))) != 0) + if (mopts && mopts->im6o_multicast_ifp) { + ifp = mopts->im6o_multicast_ifp; + } else if (IN6_IS_ADDR_MC_LINKLOCAL(&dst->sin6_addr) || + IN6_IS_ADDR_MC_INTFACELOCAL(&dst->sin6_addr)) { + /* + * Destination multicast address is in the link-local + * or interface-local scope. Use its sin6_scope_id to + * determine outgoing interface. + */ + ifp = in6_getlinkifnet(dst->sin6_scope_id); + } else { + /* + * XXX: Try to lookup route for this multicast + * destination address. + */ + if (cached_rtlookup(dst, ro, fibnum) != 0) + return (EHOSTUNREACH); + ifp = ro->ro_rt->rt_ifp; + } + } else if (opts != NULL && opts->ip6po_nexthop != NULL) { + error = handle_nexthop(&opts->ip6po_nhinfo, fibnum, &ifp); + if (error != 0) return (error); - - ia6 = (struct in6_ifaddr *)ifa_ifwithaddr( - (struct sockaddr *)&srcsock); - if (ia6 == NULL || - (ia6->ia6_flags & (IN6_IFF_ANYCAST | IN6_IFF_NOTREADY))) { - if (ia6 != NULL) - ifa_free(&ia6->ia_ifa); - return (EADDRNOTAVAIL); - } - pi->ipi6_addr = srcsock.sin6_addr; /* XXX: this overrides pi */ - if (ifpp) - *ifpp = ifp; - bcopy(&ia6->ia_addr.sin6_addr, srcp, sizeof(*srcp)); - ifa_free(&ia6->ia_ifa); - return (0); + } else { + /* + * We don't have any options and destination isn't multicast. + * Use sin6_scope_id for link-local addresses. + * Do a route lookup for global addresses. + */ + if (dst->sin6_scope_id != 0) + ifp = in6_getlinkifnet(dst->sin6_scope_id); + else { + if (cached_rtlookup(dst, ro, fibnum) != 0) + return (EHOSTUNREACH); + ifp = ro->ro_rt->rt_ifp; + } } /* * Otherwise, if the socket has already bound the source, just use it. */ if (inp != NULL && !IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)) { +#if 0 /* XXX: Jail support. */ if (cred != NULL && (error = prison_local_ip6(cred, &inp->in6p_laddr, ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0))) != 0) return (error); bcopy(&inp->in6p_laddr, srcp, sizeof(*srcp)); +#endif + if (ro == &ro6) + RO_RTFREE(ro); + *srcp = inp->in6p_laddr; + *ifpp = ifp; return (0); } - /* - * Bypass source address selection and use the primary jail IP + * XXX: Bypass source address selection and use the primary jail IP * if requested. */ +#if 0 if (cred != NULL && !prison_saddrsel_ip6(cred, srcp)) return (0); +#endif /* * If the address is not specified, choose the best one based on From owner-svn-src-user@FreeBSD.ORG Wed Oct 16 09:27:52 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id EFD80618; Wed, 16 Oct 2013 09:27:51 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id DD52E2E14; Wed, 16 Oct 2013 09:27:51 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9G9RpJ8005534; Wed, 16 Oct 2013 09:27:51 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9G9Rpbo005533; Wed, 16 Oct 2013 09:27:51 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310160927.r9G9Rpbo005533@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 16 Oct 2013 09:27:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256609 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 09:27:52 -0000 Author: ae Date: Wed Oct 16 09:27:51 2013 New Revision: 256609 URL: http://svnweb.freebsd.org/changeset/base/256609 Log: Rewrite the SAS Algorithm's loop and use srcaddrcmp() function for comparing. Modified: user/ae/inet6/sys/netinet6/in6_src.c Modified: user/ae/inet6/sys/netinet6/in6_src.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6_src.c Wed Oct 16 09:25:00 2013 (r256608) +++ user/ae/inet6/sys/netinet6/in6_src.c Wed Oct 16 09:27:51 2013 (r256609) @@ -555,7 +555,7 @@ handle_nexthop(struct ip6po_nhinfo *nh, } int -in6_selectsrc(struct sockaddr_in6 *dstsock, struct ip6_pktopts *opts, +in6_selectsrc(struct sockaddr_in6 *dst, struct ip6_pktopts *opts, struct inpcb *inp, struct route_in6 *ro, struct ucred *cred, struct ifnet **ifpp, struct in6_addr *srcp) { @@ -671,7 +671,12 @@ in6_selectsrc(struct sockaddr_in6 *dstso ifp = ro->ro_rt->rt_ifp; } } - + if (ifp == NULL) { + if (oifp == NULL) + return (EHOSTUNREACH); + /* Use outgoing interface specified by caller. */ + ifp = oifp; + } /* * Otherwise, if the socket has already bound the source, just use it. */ @@ -702,205 +707,49 @@ in6_selectsrc(struct sockaddr_in6 *dstso * If the address is not specified, choose the best one based on * the outgoing interface and the destination address. */ - /* get the outgoing interface */ - if ((error = in6_selectif(dstsock, opts, mopts, ro, &ifp, oifp, - (inp != NULL) ? inp->inp_inc.inc_fibnum : RT_DEFAULT_FIB)) != 0) - return (error); - -#ifdef DIAGNOSTIC - if (ifp == NULL) /* this should not happen */ - panic("in6_selectsrc: NULL ifp"); -#endif - error = in6_setscope(&dst, ifp, &odstzone); - if (error) - return (error); - - rule = 0; - IN6_IFADDR_RLOCK(); - TAILQ_FOREACH(ia, &V_in6_ifaddrhead, ia_link) { - int new_scope = -1, new_matchlen = -1; - struct in6_addrpolicy *new_policy = NULL; - u_int32_t srczone, osrczone, dstzone; - struct in6_addr src; - struct ifnet *ifp1 = ia->ia_ifp; - - /* - * We'll never take an address that breaks the scope zone - * of the destination. We also skip an address if its zone - * does not contain the outgoing interface. - * XXX: we should probably use sin6_scope_id here. - */ - if (in6_setscope(&dst, ifp1, &dstzone) || - odstzone != dstzone) { - continue; - } - src = ia->ia_addr.sin6_addr; - if (in6_setscope(&src, ifp, &osrczone) || - in6_setscope(&src, ifp1, &srczone) || - osrczone != srczone) { - continue; - } - - /* avoid unusable addresses */ - if ((ia->ia6_flags & - (IN6_IFF_NOTREADY | IN6_IFF_ANYCAST | IN6_IFF_DETACHED))) { + dstprops.ifp = ifp; + dstprops.addr = &dst->sin6_addr; + dstprops.scope = in6_srcaddrscope(&dst->sin6_addr); + best.rule = -1; + best.ia = NULL; + /* + * RFC 6724 (section 4): + * For all multicast and link-local destination addresses, the set of + * candidate source addresses MUST only include addresses assigned to + * interfaces belonging to the same link as the outgoing interface. + */ + if (IN6_IS_ADDR_MULTICAST(&dst->sin6_addr) || + dstprops.scope == IPV6_ADDR_SCOPE_LINKLOCAL) { + IF_ADDR_RLOCK(ifp); + TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { + if (ifa->ifa_addr->sa_family != AF_INET6) continue; + error = srcaddrcmp(&best, (struct in6_ifaddr*)ifa, + &dstprops, cred, opts); + if (error == 1) + break; + } + if (best.rule >= 0) + ifa_ref(&best.ia->ia_ifa); + IF_ADDR_RUNLOCK(ifp); + } else { + IN6_IFADDR_RLOCK(); + TAILQ_FOREACH(ia, &V_in6_ifaddrhead, ia_link) { + error = srcaddrcmp(&best, ia, &dstprops, cred, opts); + if (error == 1) + break; } - if (!V_ip6_use_deprecated && IFA6_IS_DEPRECATED(ia)) - continue; - - /* If jailed only take addresses of the jail into account. */ - if (cred != NULL && - prison_check_ip6(cred, &ia->ia_addr.sin6_addr) != 0) - continue; - - /* Rule 1: Prefer same address */ - if (IN6_ARE_ADDR_EQUAL(&dst, &ia->ia_addr.sin6_addr)) { - ia_best = ia; - BREAK(1); /* there should be no better candidate */ - } - - if (ia_best == NULL) - REPLACE(0); - - /* Rule 2: Prefer appropriate scope */ - if (dst_scope < 0) - dst_scope = in6_addrscope(&dst); - new_scope = in6_addrscope(&ia->ia_addr.sin6_addr); - if (IN6_ARE_SCOPE_CMP(best_scope, new_scope) < 0) { - if (IN6_ARE_SCOPE_CMP(best_scope, dst_scope) < 0) - REPLACE(2); - NEXT(2); - } else if (IN6_ARE_SCOPE_CMP(new_scope, best_scope) < 0) { - if (IN6_ARE_SCOPE_CMP(new_scope, dst_scope) < 0) - NEXT(2); - REPLACE(2); - } - - /* - * Rule 3: Avoid deprecated addresses. Note that the case of - * !ip6_use_deprecated is already rejected above. - */ - if (!IFA6_IS_DEPRECATED(ia_best) && IFA6_IS_DEPRECATED(ia)) - NEXT(3); - if (IFA6_IS_DEPRECATED(ia_best) && !IFA6_IS_DEPRECATED(ia)) - REPLACE(3); - - /* Rule 4: Prefer home addresses */ - /* - * XXX: This is a TODO. We should probably merge the MIP6 - * case above. - */ - - /* Rule 5: Prefer outgoing interface */ - if (!(ND_IFINFO(ifp)->flags & ND6_IFF_NO_PREFER_IFACE)) { - if (ia_best->ia_ifp == ifp && ia->ia_ifp != ifp) - NEXT(5); - if (ia_best->ia_ifp != ifp && ia->ia_ifp == ifp) - REPLACE(5); - } - - /* - * Rule 6: Prefer matching label - * Note that best_policy should be non-NULL here. - */ - if (dst_policy == NULL) - dst_policy = lookup_addrsel_policy(dstsock); - if (dst_policy->label != ADDR_LABEL_NOTAPP) { - new_policy = lookup_addrsel_policy(&ia->ia_addr); - if (dst_policy->label == best_policy->label && - dst_policy->label != new_policy->label) - NEXT(6); - if (dst_policy->label != best_policy->label && - dst_policy->label == new_policy->label) - REPLACE(6); - } - - /* - * Rule 7: Prefer public addresses. - * We allow users to reverse the logic by configuring - * a sysctl variable, so that privacy conscious users can - * always prefer temporary addresses. - */ - if (opts == NULL || - opts->ip6po_prefer_tempaddr == IP6PO_TEMPADDR_SYSTEM) { - prefer_tempaddr = V_ip6_prefer_tempaddr; - } else if (opts->ip6po_prefer_tempaddr == - IP6PO_TEMPADDR_NOTPREFER) { - prefer_tempaddr = 0; - } else - prefer_tempaddr = 1; - if (!(ia_best->ia6_flags & IN6_IFF_TEMPORARY) && - (ia->ia6_flags & IN6_IFF_TEMPORARY)) { - if (prefer_tempaddr) - REPLACE(7); - else - NEXT(7); - } - if ((ia_best->ia6_flags & IN6_IFF_TEMPORARY) && - !(ia->ia6_flags & IN6_IFF_TEMPORARY)) { - if (prefer_tempaddr) - NEXT(7); - else - REPLACE(7); - } - - /* - * Rule 8: prefer addresses on alive interfaces. - * This is a KAME specific rule. - */ - if ((ia_best->ia_ifp->if_flags & IFF_UP) && - !(ia->ia_ifp->if_flags & IFF_UP)) - NEXT(8); - if (!(ia_best->ia_ifp->if_flags & IFF_UP) && - (ia->ia_ifp->if_flags & IFF_UP)) - REPLACE(8); - - /* - * Rule 14: Use longest matching prefix. - * Note: in the address selection draft, this rule is - * documented as "Rule 8". However, since it is also - * documented that this rule can be overridden, we assign - * a large number so that it is easy to assign smaller numbers - * to more preferred rules. - */ - new_matchlen = in6_matchlen(&ia->ia_addr.sin6_addr, &dst); - if (best_matchlen < new_matchlen) - REPLACE(14); - if (new_matchlen < best_matchlen) - NEXT(14); - - /* Rule 15 is reserved. */ - - /* - * Last resort: just keep the current candidate. - * Or, do we need more rules? - */ - continue; - - replace: - ia_best = ia; - best_scope = (new_scope >= 0 ? new_scope : - in6_addrscope(&ia_best->ia_addr.sin6_addr)); - best_policy = (new_policy ? new_policy : - lookup_addrsel_policy(&ia_best->ia_addr)); - best_matchlen = (new_matchlen >= 0 ? new_matchlen : - in6_matchlen(&ia_best->ia_addr.sin6_addr, - &dst)); - - next: - continue; - - out: - break; - } - - if ((ia = ia_best) == NULL) { + if (best.rule >= 0) + ifa_ref(&best.ia->ia_ifa); IN6_IFADDR_RUNLOCK(); + } + if (best.rule < 0) { IP6STAT_INC(ip6s_sources_none); + if (ro == &ro6) + RO_RTFREE(ro); return (EADDRNOTAVAIL); } - +#if 0 /* * At this point at least one of the addresses belonged to the jail * but it could still be, that we want to further restrict it, e.g. @@ -917,22 +766,24 @@ in6_selectsrc(struct sockaddr_in6 *dstso IP6STAT_INC(ip6s_sources_none); return (EADDRNOTAVAIL); } +#endif + *ifpp = ifp; + *srcp = best.ia->ia_addr.sin6_addr; - if (ifpp) - *ifpp = ifp; - - bcopy(&tmp, srcp, sizeof(*srcp)); - if (ia->ia_ifp == ifp) - IP6STAT_INC(ip6s_sources_sameif[best_scope]); + /* Update statistic */ + if (best.ia->ia_ifp == ifp) + IP6STAT_INC(ip6s_sources_sameif[best.scope]); else - IP6STAT_INC(ip6s_sources_otherif[best_scope]); - if (dst_scope == best_scope) - IP6STAT_INC(ip6s_sources_samescope[best_scope]); + IP6STAT_INC(ip6s_sources_otherif[best.scope]); + if (dstprops.scope == best.scope) + IP6STAT_INC(ip6s_sources_samescope[best.scope]); else - IP6STAT_INC(ip6s_sources_otherscope[best_scope]); - if (IFA6_IS_DEPRECATED(ia)) - IP6STAT_INC(ip6s_sources_deprecated[best_scope]); - IN6_IFADDR_RUNLOCK(); + IP6STAT_INC(ip6s_sources_otherscope[best.scope]); + if (IFA6_IS_DEPRECATED(best.ia)) + IP6STAT_INC(ip6s_sources_deprecated[best.scope]); + ifa_free(&best.ia->ia_ifa); + if (ro == &ro6) + RO_RTFREE(ro); return (0); } From owner-svn-src-user@FreeBSD.ORG Wed Oct 16 09:40:01 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 35601D91; Wed, 16 Oct 2013 09:40:01 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 0AE522EFA; Wed, 16 Oct 2013 09:40:01 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9G9e0U5011512; Wed, 16 Oct 2013 09:40:00 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9G9e0ri011502; Wed, 16 Oct 2013 09:40:00 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310160940.r9G9e0ri011502@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 16 Oct 2013 09:40:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256611 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 09:40:01 -0000 Author: ae Date: Wed Oct 16 09:40:00 2013 New Revision: 256611 URL: http://svnweb.freebsd.org/changeset/base/256611 Log: Constify argument. Modified: user/ae/inet6/sys/netinet6/in6.c user/ae/inet6/sys/netinet6/in6.h user/ae/inet6/sys/netinet6/in6_var.h Modified: user/ae/inet6/sys/netinet6/in6.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6.c Wed Oct 16 09:33:23 2013 (r256610) +++ user/ae/inet6/sys/netinet6/in6.c Wed Oct 16 09:40:00 2013 (r256611) @@ -2003,7 +2003,7 @@ in6ifa_ifwithaddr(const struct in6_addr * ifaddr is returned referenced. */ struct in6_ifaddr * -in6ifa_ifpwithaddr(struct ifnet *ifp, struct in6_addr *addr) +in6ifa_ifpwithaddr(struct ifnet *ifp, const struct in6_addr *addr) { struct ifaddr *ifa; @@ -2155,7 +2155,7 @@ in6_localaddr(struct in6_addr *in6) * on one of its interfaces. */ int -in6_localip(struct in6_addr *in6) +in6_localip(const struct in6_addr *in6) { struct in6_ifaddr *ia; Modified: user/ae/inet6/sys/netinet6/in6.h ============================================================================== --- user/ae/inet6/sys/netinet6/in6.h Wed Oct 16 09:33:23 2013 (r256610) +++ user/ae/inet6/sys/netinet6/in6.h Wed Oct 16 09:40:00 2013 (r256611) @@ -637,7 +637,7 @@ struct ip6_hdr; int in6_cksum_pseudo(struct ip6_hdr *, uint32_t, uint8_t, uint16_t); int in6_cksum(struct mbuf *, u_int8_t, u_int32_t, u_int32_t); int in6_localaddr(struct in6_addr *); -int in6_localip(struct in6_addr *); +int in6_localip(const struct in6_addr *); int in6_addrscope(const struct in6_addr *); struct in6_ifaddr *in6_ifawithifp(struct ifnet *, struct in6_addr *); extern void in6_if_up(struct ifnet *); Modified: user/ae/inet6/sys/netinet6/in6_var.h ============================================================================== --- user/ae/inet6/sys/netinet6/in6_var.h Wed Oct 16 09:33:23 2013 (r256610) +++ user/ae/inet6/sys/netinet6/in6_var.h Wed Oct 16 09:40:00 2013 (r256611) @@ -813,7 +813,7 @@ void in6_domifdetach(struct ifnet *, voi void in6_setmaxmtu(void); int in6_if2idlen(struct ifnet *); struct in6_ifaddr *in6ifa_ifpforlinklocal(struct ifnet *, int); -struct in6_ifaddr *in6ifa_ifpwithaddr(struct ifnet *, struct in6_addr *); +struct in6_ifaddr *in6ifa_ifpwithaddr(struct ifnet *, const struct in6_addr *); struct in6_ifaddr *in6ifa_ifwithaddr(const struct in6_addr *, uint32_t); struct in6_ifaddr *in6ifa_llaonifp(struct ifnet *); char *ip6_sprintf(char *, const struct in6_addr *); From owner-svn-src-user@FreeBSD.ORG Wed Oct 16 10:11:31 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 005DAB09; Wed, 16 Oct 2013 10:11:30 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id D2EAB21A6; Wed, 16 Oct 2013 10:11:30 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9GABUlk029929; Wed, 16 Oct 2013 10:11:30 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9GABURR029927; Wed, 16 Oct 2013 10:11:30 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310161011.r9GABURR029927@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 16 Oct 2013 10:11:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256615 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 10:11:31 -0000 Author: ae Date: Wed Oct 16 10:11:30 2013 New Revision: 256615 URL: http://svnweb.freebsd.org/changeset/base/256615 Log: Remove in6_selectroute, in6_selectroute_fib, in6_selectif and selectroute functions. Modified: user/ae/inet6/sys/netinet6/in6_src.c user/ae/inet6/sys/netinet6/ip6_var.h Modified: user/ae/inet6/sys/netinet6/in6_src.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6_src.c Wed Oct 16 09:56:40 2013 (r256614) +++ user/ae/inet6/sys/netinet6/in6_src.c Wed Oct 16 10:11:30 2013 (r256615) @@ -139,13 +139,6 @@ static int handle_pktinfo(const struct s struct route_in6 *ro, u_int fibnum, struct ifnet **ifpp, struct in6_addr *srcp, int *done); -static int selectroute(struct sockaddr_in6 *, struct ip6_pktopts *, - struct ip6_moptions *, struct route_in6 *, struct ifnet **, - struct rtentry **, int, u_int); -static int in6_selectif(struct sockaddr_in6 *, struct ip6_pktopts *, - struct ip6_moptions *, struct route_in6 *ro, struct ifnet **, - struct ifnet *, u_int); - static int lookup_policy_label(const struct in6_addr *, uint32_t); static void init_policy_queue(void); @@ -788,339 +781,6 @@ in6_selectsrc(struct sockaddr_in6 *dst, } /* - * clone - meaningful only for bsdi and freebsd - */ -static int -selectroute(struct sockaddr_in6 *dstsock, struct ip6_pktopts *opts, - struct ip6_moptions *mopts, struct route_in6 *ro, - struct ifnet **retifp, struct rtentry **retrt, int norouteok, u_int fibnum) -{ - int error = 0; - struct ifnet *ifp = NULL; - struct rtentry *rt = NULL; - struct sockaddr_in6 *sin6_next; - struct in6_pktinfo *pi = NULL; - struct in6_addr *dst = &dstsock->sin6_addr; -#if 0 - char ip6buf[INET6_ADDRSTRLEN]; - - if (dstsock->sin6_addr.s6_addr32[0] == 0 && - dstsock->sin6_addr.s6_addr32[1] == 0 && - !IN6_IS_ADDR_LOOPBACK(&dstsock->sin6_addr)) { - printf("in6_selectroute: strange destination %s\n", - ip6_sprintf(ip6buf, &dstsock->sin6_addr)); - } else { - printf("in6_selectroute: destination = %s%%%d\n", - ip6_sprintf(ip6buf, &dstsock->sin6_addr), - dstsock->sin6_scope_id); /* for debug */ - } -#endif - - /* If the caller specify the outgoing interface explicitly, use it. */ - if (opts && (pi = opts->ip6po_pktinfo) != NULL && pi->ipi6_ifindex) { - /* XXX boundary check is assumed to be already done. */ - ifp = ifnet_byindex(pi->ipi6_ifindex); - if (ifp != NULL && - (norouteok || retrt == NULL || - IN6_IS_ADDR_MULTICAST(dst))) { - /* - * we do not have to check or get the route for - * multicast. - */ - goto done; - } else - goto getroute; - } - - /* - * If the destination address is a multicast address and the outgoing - * interface for the address is specified by the caller, use it. - */ - if (IN6_IS_ADDR_MULTICAST(dst) && - mopts != NULL && (ifp = mopts->im6o_multicast_ifp) != NULL) { - goto done; /* we do not need a route for multicast. */ - } - - getroute: - /* - * If the next hop address for the packet is specified by the caller, - * use it as the gateway. - */ - if (opts && opts->ip6po_nexthop) { - struct route_in6 *ron; - struct llentry *la; - - sin6_next = satosin6(opts->ip6po_nexthop); - - /* at this moment, we only support AF_INET6 next hops */ - if (sin6_next->sin6_family != AF_INET6) { - error = EAFNOSUPPORT; /* or should we proceed? */ - goto done; - } - - /* - * If the next hop is an IPv6 address, then the node identified - * by that address must be a neighbor of the sending host. - */ - ron = &opts->ip6po_nextroute; - /* - * XXX what do we do here? - * PLZ to be fixing - */ - - - if (ron->ro_rt == NULL) { - in6_rtalloc(ron, fibnum); /* multi path case? */ - if (ron->ro_rt == NULL) { - /* XXX-BZ WT.? */ - if (ron->ro_rt) { - RTFREE(ron->ro_rt); - ron->ro_rt = NULL; - } - error = EHOSTUNREACH; - goto done; - } - } - - rt = ron->ro_rt; - ifp = rt->rt_ifp; - IF_AFDATA_RLOCK(ifp); - la = lla_lookup(LLTABLE6(ifp), 0, (struct sockaddr *)&sin6_next->sin6_addr); - IF_AFDATA_RUNLOCK(ifp); - if (la != NULL) - LLE_RUNLOCK(la); - else { - error = EHOSTUNREACH; - goto done; - } -#if 0 - if ((ron->ro_rt && - (ron->ro_rt->rt_flags & (RTF_UP | RTF_LLINFO)) != - (RTF_UP | RTF_LLINFO)) || - !IN6_ARE_ADDR_EQUAL(&satosin6(&ron->ro_dst)->sin6_addr, - &sin6_next->sin6_addr)) { - if (ron->ro_rt) { - RTFREE(ron->ro_rt); - ron->ro_rt = NULL; - } - *satosin6(&ron->ro_dst) = *sin6_next; - } - if (ron->ro_rt == NULL) { - in6_rtalloc(ron, fibnum); /* multi path case? */ - if (ron->ro_rt == NULL || - !(ron->ro_rt->rt_flags & RTF_LLINFO)) { - if (ron->ro_rt) { - RTFREE(ron->ro_rt); - ron->ro_rt = NULL; - } - error = EHOSTUNREACH; - goto done; - } - } -#endif - - /* - * When cloning is required, try to allocate a route to the - * destination so that the caller can store path MTU - * information. - */ - goto done; - } - - /* - * Use a cached route if it exists and is valid, else try to allocate - * a new one. Note that we should check the address family of the - * cached destination, in case of sharing the cache with IPv4. - */ - if (ro) { - if (ro->ro_rt && - (!(ro->ro_rt->rt_flags & RTF_UP) || - ((struct sockaddr *)(&ro->ro_dst))->sa_family != AF_INET6 || - !IN6_ARE_ADDR_EQUAL(&satosin6(&ro->ro_dst)->sin6_addr, - dst))) { - RTFREE(ro->ro_rt); - ro->ro_rt = (struct rtentry *)NULL; - } - if (ro->ro_rt == (struct rtentry *)NULL) { - struct sockaddr_in6 *sa6; - - /* No route yet, so try to acquire one */ - bzero(&ro->ro_dst, sizeof(struct sockaddr_in6)); - sa6 = (struct sockaddr_in6 *)&ro->ro_dst; - *sa6 = *dstsock; - sa6->sin6_scope_id = 0; - -#ifdef RADIX_MPATH - rtalloc_mpath_fib((struct route *)ro, - ntohl(sa6->sin6_addr.s6_addr32[3]), fibnum); -#else - ro->ro_rt = in6_rtalloc1((struct sockaddr *) - &ro->ro_dst, 0, 0UL, fibnum); - if (ro->ro_rt) - RT_UNLOCK(ro->ro_rt); -#endif - } - - /* - * do not care about the result if we have the nexthop - * explicitly specified. - */ - if (opts && opts->ip6po_nexthop) - goto done; - - if (ro->ro_rt) { - ifp = ro->ro_rt->rt_ifp; - - if (ifp == NULL) { /* can this really happen? */ - RTFREE(ro->ro_rt); - ro->ro_rt = NULL; - } - } - if (ro->ro_rt == NULL) - error = EHOSTUNREACH; - rt = ro->ro_rt; - - /* - * Check if the outgoing interface conflicts with - * the interface specified by ipi6_ifindex (if specified). - * Note that loopback interface is always okay. - * (this may happen when we are sending a packet to one of - * our own addresses.) - */ - if (ifp && opts && opts->ip6po_pktinfo && - opts->ip6po_pktinfo->ipi6_ifindex) { - if (!(ifp->if_flags & IFF_LOOPBACK) && - ifp->if_index != - opts->ip6po_pktinfo->ipi6_ifindex) { - error = EHOSTUNREACH; - goto done; - } - } - } - - done: - if (ifp == NULL && rt == NULL) { - /* - * This can happen if the caller did not pass a cached route - * nor any other hints. We treat this case an error. - */ - error = EHOSTUNREACH; - } - if (error == EHOSTUNREACH) - IP6STAT_INC(ip6s_noroute); - - if (retifp != NULL) { - *retifp = ifp; - - /* - * Adjust the "outgoing" interface. If we're going to loop - * the packet back to ourselves, the ifp would be the loopback - * interface. However, we'd rather know the interface associated - * to the destination address (which should probably be one of - * our own addresses.) - */ - if (rt) { - if ((rt->rt_ifp->if_flags & IFF_LOOPBACK) && - (rt->rt_gateway->sa_family == AF_LINK)) - *retifp = - ifnet_byindex(((struct sockaddr_dl *) - rt->rt_gateway)->sdl_index); - } - } - - if (retrt != NULL) - *retrt = rt; /* rt may be NULL */ - - return (error); -} - -static int -in6_selectif(struct sockaddr_in6 *dstsock, struct ip6_pktopts *opts, - struct ip6_moptions *mopts, struct route_in6 *ro, struct ifnet **retifp, - struct ifnet *oifp, u_int fibnum) -{ - int error; - struct route_in6 sro; - struct rtentry *rt = NULL; - - KASSERT(retifp != NULL, ("%s: retifp is NULL", __func__)); - - if (ro == NULL) { - bzero(&sro, sizeof(sro)); - ro = &sro; - } - - if ((error = selectroute(dstsock, opts, mopts, ro, retifp, - &rt, 1, fibnum)) != 0) { - if (ro == &sro && rt && rt == sro.ro_rt) - RTFREE(rt); - /* Help ND. See oifp comment in in6_selectsrc(). */ - if (oifp != NULL && fibnum == RT_DEFAULT_FIB) { - *retifp = oifp; - error = 0; - } - return (error); - } - - /* - * do not use a rejected or black hole route. - * XXX: this check should be done in the L2 output routine. - * However, if we skipped this check here, we'd see the following - * scenario: - * - install a rejected route for a scoped address prefix - * (like fe80::/10) - * - send a packet to a destination that matches the scoped prefix, - * with ambiguity about the scope zone. - * - pick the outgoing interface from the route, and disambiguate the - * scope zone with the interface. - * - ip6_output() would try to get another route with the "new" - * destination, which may be valid. - * - we'd see no error on output. - * Although this may not be very harmful, it should still be confusing. - * We thus reject the case here. - */ - if (rt && (rt->rt_flags & (RTF_REJECT | RTF_BLACKHOLE))) { - int flags = (rt->rt_flags & RTF_HOST ? EHOSTUNREACH : ENETUNREACH); - - if (ro == &sro && rt && rt == sro.ro_rt) - RTFREE(rt); - return (flags); - } - - if (ro == &sro && rt && rt == sro.ro_rt) - RTFREE(rt); - return (0); -} - -/* - * Public wrapper function to selectroute(). - * - * XXX-BZ in6_selectroute() should and will grow the FIB argument. The - * in6_selectroute_fib() function is only there for backward compat on stable. - */ -int -in6_selectroute(struct sockaddr_in6 *dstsock, struct ip6_pktopts *opts, - struct ip6_moptions *mopts, struct route_in6 *ro, - struct ifnet **retifp, struct rtentry **retrt) -{ - - return (selectroute(dstsock, opts, mopts, ro, retifp, - retrt, 0, RT_DEFAULT_FIB)); -} - -#ifndef BURN_BRIDGES -int -in6_selectroute_fib(struct sockaddr_in6 *dstsock, struct ip6_pktopts *opts, - struct ip6_moptions *mopts, struct route_in6 *ro, - struct ifnet **retifp, struct rtentry **retrt, u_int fibnum) -{ - - return (selectroute(dstsock, opts, mopts, ro, retifp, - retrt, 0, fibnum)); -} -#endif - -/* * Default hop limit selection. The precedence is as follows: * 1. Hoplimit value specified via ioctl. * 2. (If the outgoing interface is detected) the current Modified: user/ae/inet6/sys/netinet6/ip6_var.h ============================================================================== --- user/ae/inet6/sys/netinet6/ip6_var.h Wed Oct 16 09:56:40 2013 (r256614) +++ user/ae/inet6/sys/netinet6/ip6_var.h Wed Oct 16 10:11:30 2013 (r256615) @@ -455,12 +455,6 @@ int none_input(struct mbuf **, int *, in int in6_selectsrc(struct sockaddr_in6 *, struct ip6_pktopts *, struct inpcb *inp, struct route_in6 *, struct ucred *cred, struct ifnet **, struct in6_addr *); -int in6_selectroute(struct sockaddr_in6 *, struct ip6_pktopts *, - struct ip6_moptions *, struct route_in6 *, struct ifnet **, - struct rtentry **); -int in6_selectroute_fib(struct sockaddr_in6 *, struct ip6_pktopts *, - struct ip6_moptions *, struct route_in6 *, struct ifnet **, - struct rtentry **, u_int); u_int32_t ip6_randomid(void); u_int32_t ip6_randomflowlabel(void); #endif /* _KERNEL */ From owner-svn-src-user@FreeBSD.ORG Wed Oct 16 11:51:09 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id A3DD9AA6; Wed, 16 Oct 2013 11:51:09 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 82E812731; Wed, 16 Oct 2013 11:51:09 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9GBp9OT082388; Wed, 16 Oct 2013 11:51:09 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9GBp91D082386; Wed, 16 Oct 2013 11:51:09 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310161151.r9GBp91D082386@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 16 Oct 2013 11:51:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256620 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 11:51:09 -0000 Author: ae Date: Wed Oct 16 11:51:08 2013 New Revision: 256620 URL: http://svnweb.freebsd.org/changeset/base/256620 Log: Introduce new flag for ip6_output() - IPV6_USEROIF. It means, that top level already determined outgoing interface and ip6_output() can use it. But in some cases ip6_output() will ignore it (e.g. packet forwarded by pfil(4), routing header, etc). Rework route lookup part of ip6_output() to properly handle the fact, that now we don't keep routes for link-local addresses. Also, since in6_selectroute_fib() disappeared, now we need use in6_rtalloc(). But in some cases it isn't needed. Modified: user/ae/inet6/sys/netinet6/ip6_output.c user/ae/inet6/sys/netinet6/ip6_var.h Modified: user/ae/inet6/sys/netinet6/ip6_output.c ============================================================================== --- user/ae/inet6/sys/netinet6/ip6_output.c Wed Oct 16 11:30:47 2013 (r256619) +++ user/ae/inet6/sys/netinet6/ip6_output.c Wed Oct 16 11:51:08 2013 (r256620) @@ -143,8 +143,8 @@ static int ip6_insertfraghdr(struct mbuf struct ip6_frag **); static int ip6_insert_jumboopt(struct ip6_exthdrs *, u_int32_t); static int ip6_splithdr(struct mbuf *, struct ip6_exthdrs *); -static int ip6_getpmtu(struct route_in6 *, struct route_in6 *, - struct ifnet *, struct in6_addr *, u_long *, int *, u_int); +static int ip6_getpmtu(const struct in6_addr *, struct ifnet *, + struct route_in6 *, struct route_in6 *, u_int, u_long *, int *); static int copypktopts(struct ip6_pktopts *, struct ip6_pktopts *, int); @@ -221,8 +221,6 @@ in6_delayed_cksum(struct mbuf *m, uint32 * type of "mtu": rt_rmx.rmx_mtu is u_long, ifnet.ifr_mtu is int, and * nd_ifinfo.linkmtu is u_int32_t. so we use u_long to hold largest one, * which is rt_rmx.rmx_mtu. - * - * ifpp - XXX: just for statistics */ int ip6_output(struct mbuf *m0, struct ip6_pktopts *opt, @@ -230,13 +228,12 @@ ip6_output(struct mbuf *m0, struct ip6_p struct ifnet **ifpp, struct inpcb *inp) { struct ip6_hdr *ip6, *mhip6; - struct ifnet *ifp, *origifp; + struct ifnet *ifp = NULL, *origifp; struct mbuf *m = m0; struct mbuf *mprev = NULL; int hlen, tlen, len, off; struct route_in6 ip6route; - struct rtentry *rt = NULL; - struct sockaddr_in6 *dst, src_sa, dst_sa; + struct sockaddr_in6 *dst, dst_sa; struct in6_addr odst; int error = 0; struct in6_ifaddr *ia = NULL; @@ -244,8 +241,7 @@ ip6_output(struct mbuf *m0, struct ip6_p int alwaysfrag, dontfrag; u_int32_t optlen = 0, plen = 0, unfragpartlen = 0; struct ip6_exthdrs exthdrs; - struct in6_addr finaldst, src0, dst0; - u_int32_t zone; + struct in6_addr finaldst; struct route_in6 *ro_pmtu = NULL; int hdrsplit = 0; int needipsec = 0; @@ -258,6 +254,7 @@ ip6_output(struct mbuf *m0, struct ip6_p struct secpolicy *sp = NULL; #endif /* IPSEC */ struct m_tag *fwd_tag = NULL; + u_int fibnum; ip6 = mtod(m, struct ip6_hdr *); if (ip6 == NULL) { @@ -265,8 +262,11 @@ ip6_output(struct mbuf *m0, struct ip6_p goto bad; } - if (inp != NULL) + if (inp != NULL) { M_SETFIB(m, inp->inp_inc.inc_fibnum); + fibnum = inp->inp_inc.inc_fibnum; + } else + fibnum = M_GETFIB(m); finaldst = ip6->ip6_dst; bzero(&exthdrs, sizeof(exthdrs)); @@ -512,14 +512,22 @@ skip_ipsec2:; /* * Route packet. */ - if (ro == 0) { - ro = &ip6route; - bzero((caddr_t)ro, sizeof(*ro)); + if (ro == NULL || ro->ro_rt == NULL) { + if (ro == NULL) + ro = &ip6route; + bzero(ro, sizeof(*ro)); + ro->ro_dst.sin6_family = AF_INET6; + ro->ro_dst.sin6_len = sizeof(ro->ro_dst); + ro->ro_dst.sin6_addr = ip6->ip6_dst; } ro_pmtu = ro; - if (opt && opt->ip6po_rthdr) - ro = &opt->ip6po_route; - dst = (struct sockaddr_in6 *)&ro->ro_dst; + if (opt != NULL) { + if (opt->ip6po_nexthop != NULL) + ro = &opt->ip6po_nextroute; + else if (opt->ip6po_rthdr != NULL) + ro = &opt->ip6po_route; + } + dst = &ro->ro_dst; #ifdef FLOWTABLE if (ro->ro_rt == NULL) { struct flentry *fle; @@ -636,102 +644,136 @@ again: /* adjust pointer */ ip6 = mtod(m, struct ip6_hdr *); - if (ro->ro_rt && fwd_tag == NULL) { - rt = ro->ro_rt; + if (fwd_tag != NULL) { + /* + * We have changed destination by packet filter. + * Check that we have valid route and free it, if + * new destination is different one. + * + * dst_sa contains the new destination. + */ + if (ro != &ip6route) { + /* + * XXX: check that we do not leak route here. + */ + ro = &ip6route; + bzero(ro, sizeof(*ro)); + } else if (ro->ro_rt != NULL && ( + (ro->ro_rt->rt_flags & RTF_UP) == 0 || + ro->ro_dst.sin6_family != AF_INET6 || + IN6_ARE_ADDR_EQUAL(&ro->ro_dst.sin6_addr, + &dst_sa.sin6_addr) == 0)) + RO_RTFREE(ro); + /* + * Copy new destination to prepare new route lookup. + */ + bcopy(&dst_sa, &ro->ro_dst, sizeof(dst_sa)); + dst = &ro->ro_dst; + } else { + /* + * fwd_tag is NULL. + * Check that route exists and is valid. + */ + if (ro->ro_rt != NULL && ( + (ro->ro_rt->rt_flags & RTF_UP) == 0 || + ro->ro_dst.sin6_family != AF_INET6)) + RO_RTFREE(ro); + } + if (ro->ro_rt != NULL) { ifp = ro->ro_rt->rt_ifp; } else { - if (fwd_tag == NULL) { - bzero(&dst_sa, sizeof(dst_sa)); - dst_sa.sin6_family = AF_INET6; - dst_sa.sin6_len = sizeof(dst_sa); - dst_sa.sin6_addr = ip6->ip6_dst; - } - error = in6_selectroute_fib(&dst_sa, opt, im6o, ro, &ifp, - &rt, inp ? inp->inp_inc.inc_fibnum : M_GETFIB(m)); - if (error != 0) { - if (ifp != NULL) - in6_ifstat_inc(ifp, ifs6_out_discard); - goto bad; + /* + * We can just use specified by user outgoing interface when + * IPV6_USEROIF flag is set. But we should determine new + * outgoing interface if PFIL has changed destination address, + * or some packet options is set. + */ + if ((flags & IPV6_USEROIF) != 0 && + (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst) || + (fwd_tag == NULL && (opt == NULL || + (opt->ip6po_nexthop == NULL && + opt->ip6po_rthdr == NULL))))) + ifp = *ifpp; + else { + /* + * We ignore next hop and routing header when + * destination IP address is multicast. So, first + * look into multicast options to determine outgoing + * interface. + */ + if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) { + if (im6o != NULL && + im6o->im6o_multicast_ifp != NULL) { + ifp = im6o->im6o_multicast_ifp; + goto oif_found; + } + /* + * If address is from interface-local or + * link-local scope, then we can not + * disambiguate it without scope zone id. + */ + if (IN6_IS_ADDR_MC_LINKLOCAL(&ip6->ip6_dst) || + IN6_IS_ADDR_MC_INTFACELOCAL( + &ip6->ip6_dst)) { + error = EHOSTUNREACH; + IP6STAT_INC(ip6s_noroute); + goto bad; + } + } else if (IN6_IS_ADDR_LINKLOCAL(&dst->sin6_addr) || + IN6_IS_ADDR_MC_INTFACELOCAL(&dst->sin6_addr) || + IN6_IS_ADDR_MC_LINKLOCAL(&dst->sin6_addr)) { + /* + * Check that destination has correct zone id + */ + if (dst->sin6_scope_id == 0 || !(ifp = + in6_getlinkifnet(dst->sin6_scope_id))) { + error = EHOSTUNREACH; + IP6STAT_INC(ip6s_noroute); + goto bad; + } + goto oif_found; + } + /* + * Check that destination address is our own. + */ + ia = in6ifa_ifwithaddr(&dst->sin6_addr, 0); + if (ia != NULL) { + ifp = ia->ia_ifp; + ifa_free(&ia->ia_ifa); + goto oif_found; + } + /* + * Destination address is not our, try to find a route. + */ + in6_rtalloc(ro, fibnum); + if (ro->ro_rt) + ifp = ro->ro_rt->rt_ifp; } } - if (rt == NULL) { - /* - * If in6_selectroute() does not return a route entry, - * dst may not have been updated. - */ - *dst = dst_sa; /* XXX */ + if (ifp == NULL) { + error = EHOSTUNREACH; + IP6STAT_INC(ip6s_noroute); + goto bad; } - - /* - * then rt (for unicast) and ifp must be non-NULL valid values. - */ +oif_found: if ((flags & IPV6_FORWARDING) == 0) { /* XXX: the FORWARDING flag can be set for mrouting. */ in6_ifstat_inc(ifp, ifs6_out_request); } - if (rt != NULL) { - ia = (struct in6_ifaddr *)(rt->rt_ifa); - rt->rt_use++; - } - - /* - * The outgoing interface must be in the zone of source and + * XXX: The outgoing interface must be in the zone of source and * destination addresses. */ origifp = ifp; - - src0 = ip6->ip6_src; - if (in6_setscope(&src0, origifp, &zone)) - goto badscope; - bzero(&src_sa, sizeof(src_sa)); - src_sa.sin6_family = AF_INET6; - src_sa.sin6_len = sizeof(src_sa); - src_sa.sin6_addr = ip6->ip6_src; - if (sa6_recoverscope(&src_sa) || zone != src_sa.sin6_scope_id) - goto badscope; - - dst0 = ip6->ip6_dst; - if (in6_setscope(&dst0, origifp, &zone)) - goto badscope; - /* re-initialize to be sure */ - bzero(&dst_sa, sizeof(dst_sa)); - dst_sa.sin6_family = AF_INET6; - dst_sa.sin6_len = sizeof(dst_sa); - dst_sa.sin6_addr = ip6->ip6_dst; - if (sa6_recoverscope(&dst_sa) || zone != dst_sa.sin6_scope_id) { - goto badscope; - } - - /* We should use ia_ifp to support the case of - * sending packets to an address of our own. - */ - if (ia != NULL && ia->ia_ifp) - ifp = ia->ia_ifp; - - /* scope check is done. */ - goto routefound; - - badscope: - IP6STAT_INC(ip6s_badscope); - in6_ifstat_inc(origifp, ifs6_out_discard); - if (error == 0) - error = EHOSTUNREACH; /* XXX */ - goto bad; - - routefound: - if (rt && !IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) { - if (opt && opt->ip6po_nextroute.ro_rt) { - /* - * The nexthop is explicitly specified by the - * application. We assume the next hop is an IPv6 - * address. - */ - dst = (struct sockaddr_in6 *)opt->ip6po_nexthop; - } - else if ((rt->rt_flags & RTF_GATEWAY)) - dst = (struct sockaddr_in6 *)rt->rt_gateway; - } + /* + * If we have valid route and it is marked as gateway, then + * use rt_gateway as dst. Otherwise dst will point to the destination + * address (it can be ip6->ip6_dst, opt->ip6po_nexthop, + * ip6route.ro_dst from fwd_tag or opt->ip6po_route.ro_dst). + */ + if (ro->ro_rt && !IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst) && + (ro->ro_rt->rt_flags & RTF_GATEWAY) != 0) + dst = (struct sockaddr_in6 *)ro->ro_rt->rt_gateway; if (!IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) { m->m_flags &= ~(M_BCAST | M_MCAST); /* just in case */ @@ -806,8 +848,8 @@ again: *ifpp = ifp; /* Determine path MTU. */ - if ((error = ip6_getpmtu(ro_pmtu, ro, ifp, &finaldst, &mtu, - &alwaysfrag, inp ? inp->inp_inc.inc_fibnum : M_GETFIB(m))) != 0) + if ((error = ip6_getpmtu(&finaldst, ifp, ro, ro_pmtu, + fibnum, &mtu, &alwaysfrag)) != 0) goto bad; /* @@ -927,7 +969,6 @@ again: /* Or forward to some other address? */ if ((m->m_flags & M_IP6_NEXTHOP) && (fwd_tag = m_tag_find(m, PACKET_TAG_IPFORWARD, NULL)) != NULL) { - dst = (struct sockaddr_in6 *)&ro->ro_dst; bcopy((fwd_tag+1), &dst_sa, sizeof(struct sockaddr_in6)); m->m_flags |= M_SKIP_FIREWALL; m->m_flags &= ~M_IP6_NEXTHOP; @@ -1367,9 +1408,8 @@ ip6_insertfraghdr(struct mbuf *m0, struc } static int -ip6_getpmtu(struct route_in6 *ro_pmtu, struct route_in6 *ro, - struct ifnet *ifp, struct in6_addr *dst, u_long *mtup, - int *alwaysfragp, u_int fibnum) +ip6_getpmtu(const struct in6_addr *dst, struct ifnet *ifp, struct route_in6 *ro, + struct route_in6 *ro_pmtu, u_int fibnum, u_long *mtup, int *alwaysfragp) { u_int32_t mtu = 0; int alwaysfrag = 0; @@ -1377,20 +1417,17 @@ ip6_getpmtu(struct route_in6 *ro_pmtu, s if (ro_pmtu != ro) { /* The first hop and the final destination may differ. */ - struct sockaddr_in6 *sa6_dst = - (struct sockaddr_in6 *)&ro_pmtu->ro_dst; if (ro_pmtu->ro_rt && ((ro_pmtu->ro_rt->rt_flags & RTF_UP) == 0 || - !IN6_ARE_ADDR_EQUAL(&sa6_dst->sin6_addr, dst))) { - RTFREE(ro_pmtu->ro_rt); - ro_pmtu->ro_rt = (struct rtentry *)NULL; - } - if (ro_pmtu->ro_rt == NULL) { - bzero(sa6_dst, sizeof(*sa6_dst)); - sa6_dst->sin6_family = AF_INET6; - sa6_dst->sin6_len = sizeof(struct sockaddr_in6); - sa6_dst->sin6_addr = *dst; - + !IN6_ARE_ADDR_EQUAL(&ro_pmtu->ro_dst.sin6_addr, dst))) + RO_RTFREE(ro_pmtu); + if (ro_pmtu->ro_rt == NULL && + !IN6_IS_ADDR_LINKLOCAL(dst) && + !IN6_IS_ADDR_MULTICAST(dst)) { + bzero(&ro_pmtu->ro_dst, sizeof(ro_pmtu->ro_dst)); + ro_pmtu->ro_dst.sin6_family = AF_INET6; + ro_pmtu->ro_dst.sin6_len = sizeof(ro_pmtu->ro_dst); + ro_pmtu->ro_dst.sin6_addr = *dst; in6_rtalloc(ro_pmtu, fibnum); } } @@ -2031,9 +2068,8 @@ do { \ * routing, or optional information to specify * the outgoing interface. */ - error = ip6_getpmtu(&sro, NULL, NULL, - &in6p->in6p_faddr, &pmtu, NULL, - so->so_fibnum); + error = ip6_getpmtu(&in6p->in6p_faddr, NULL, + NULL, &sro, so->so_fibnum, &pmtu, NULL); if (sro.ro_rt) RTFREE(sro.ro_rt); if (error) Modified: user/ae/inet6/sys/netinet6/ip6_var.h ============================================================================== --- user/ae/inet6/sys/netinet6/ip6_var.h Wed Oct 16 11:30:47 2013 (r256619) +++ user/ae/inet6/sys/netinet6/ip6_var.h Wed Oct 16 11:51:08 2013 (r256620) @@ -292,6 +292,7 @@ struct ip6aux { #define IPV6_UNSPECSRC 0x01 /* allow :: as the source address */ #define IPV6_FORWARDING 0x02 /* most of IPv6 header exists */ #define IPV6_MINMTU 0x04 /* use minimum MTU (IPV6_USE_MIN_MTU) */ +#define IPV6_USEROIF 0x08 /* use interface specified by user */ /* * IPv6 protocol layer specific mbuf flags. From owner-svn-src-user@FreeBSD.ORG Wed Oct 16 11:53:03 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id CB3A0BBF; Wed, 16 Oct 2013 11:53:03 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id B956C2740; Wed, 16 Oct 2013 11:53:03 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9GBr3uE082952; Wed, 16 Oct 2013 11:53:03 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9GBr3jp082950; Wed, 16 Oct 2013 11:53:03 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310161153.r9GBr3jp082950@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 16 Oct 2013 11:53:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256621 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 11:53:03 -0000 Author: ae Date: Wed Oct 16 11:53:03 2013 New Revision: 256621 URL: http://svnweb.freebsd.org/changeset/base/256621 Log: Don't pass rtentry to nd6_output. Modified: user/ae/inet6/sys/netinet6/ip6_forward.c user/ae/inet6/sys/netinet6/ip6_output.c Modified: user/ae/inet6/sys/netinet6/ip6_forward.c ============================================================================== --- user/ae/inet6/sys/netinet6/ip6_forward.c Wed Oct 16 11:51:08 2013 (r256620) +++ user/ae/inet6/sys/netinet6/ip6_forward.c Wed Oct 16 11:53:03 2013 (r256621) @@ -620,7 +620,7 @@ skip_routing: } pass: - error = nd6_output(rt->rt_ifp, origifp, m, dst, rt); + error = nd6_output(rt->rt_ifp, origifp, m, dst, NULL); if (error) { in6_ifstat_inc(rt->rt_ifp, ifs6_out_discard); IP6STAT_INC(ip6s_cantforward); Modified: user/ae/inet6/sys/netinet6/ip6_output.c ============================================================================== --- user/ae/inet6/sys/netinet6/ip6_output.c Wed Oct 16 11:51:08 2013 (r256620) +++ user/ae/inet6/sys/netinet6/ip6_output.c Wed Oct 16 11:53:03 2013 (r256621) @@ -1066,7 +1066,7 @@ passout: ia6->ia_ifa.if_obytes += m->m_pkthdr.len; ifa_free(&ia6->ia_ifa); } - error = nd6_output(ifp, origifp, m, dst, ro->ro_rt); + error = nd6_output(ifp, origifp, m, dst, NULL); goto done; } @@ -1221,7 +1221,7 @@ sendorfree: ia->ia_ifa.if_opackets++; ia->ia_ifa.if_obytes += m->m_pkthdr.len; } - error = nd6_output(ifp, origifp, m, dst, ro->ro_rt); + error = nd6_output(ifp, origifp, m, dst, NULL); } else m_freem(m); } From owner-svn-src-user@FreeBSD.ORG Wed Oct 16 13:07:06 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 90C80CF3; Wed, 16 Oct 2013 13:07:06 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 7ED3B2C05; Wed, 16 Oct 2013 13:07:06 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9GD76R3022730; Wed, 16 Oct 2013 13:07:06 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9GD76Zs022729; Wed, 16 Oct 2013 13:07:06 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310161307.r9GD76Zs022729@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 16 Oct 2013 13:07:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256625 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 13:07:06 -0000 Author: ae Date: Wed Oct 16 13:07:06 2013 New Revision: 256625 URL: http://svnweb.freebsd.org/changeset/base/256625 Log: Add additional error codes for IPV6_PKTINFO socket option handling corresponding to RFC3542: * Return ENETDOWN when interface specified by ipi6_ifindex is not enabled for IPv6 use. * Return EADDRNOTAVAIL when ipi6_ifindex specifies an interface but the address ipi6_addr is not available for use on that interface. * Return EINVAL when ipi6_addr is multicast address. Modified: user/ae/inet6/sys/netinet6/ip6_output.c Modified: user/ae/inet6/sys/netinet6/ip6_output.c ============================================================================== --- user/ae/inet6/sys/netinet6/ip6_output.c Wed Oct 16 12:18:44 2013 (r256624) +++ user/ae/inet6/sys/netinet6/ip6_output.c Wed Oct 16 13:07:06 2013 (r256625) @@ -2693,7 +2693,8 @@ ip6_setpktopt(int optname, u_char *buf, sticky && !IN6_IS_ADDR_UNSPECIFIED(&pktinfo->ipi6_addr)) { return (EINVAL); } - + if (IN6_IS_ADDR_MULTICAST(&pktinfo->ipi6_addr)) + return (EINVAL); /* validate the interface index if specified. */ if (pktinfo->ipi6_ifindex > V_if_index || pktinfo->ipi6_ifindex < 0) { @@ -2704,7 +2705,19 @@ ip6_setpktopt(int optname, u_char *buf, if (ifp == NULL) return (ENXIO); } - + if (ifp != NULL && ( + ND_IFINFO(ifp)->flags & ND6_IFF_IFDISABLED)) + return (ENETDOWN); + + if (ifp != NULL && + !IN6_IS_ADDR_UNSPECIFIED(&pktinfo->ipi6_addr)) { + struct in6_ifaddr *ia; + + ia = in6ifa_ifpwithaddr(ifp, &pktinfo->ipi6_addr); + if (ia == NULL) + return (EADDRNOTAVAIL); + ifa_free(&ia->ia_ifa); + } /* * We store the address anyway, and let in6_selectsrc() * validate the specified address. This is because ipi6_addr From owner-svn-src-user@FreeBSD.ORG Wed Oct 16 13:23:48 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 666B815A; Wed, 16 Oct 2013 13:23:48 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 540962CFF; Wed, 16 Oct 2013 13:23:48 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9GDNmkV031806; Wed, 16 Oct 2013 13:23:48 GMT (envelope-from glebius@svn.freebsd.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9GDNmCN031805; Wed, 16 Oct 2013 13:23:48 GMT (envelope-from glebius@svn.freebsd.org) Message-Id: <201310161323.r9GDNmCN031805@svn.freebsd.org> From: Gleb Smirnoff Date: Wed, 16 Oct 2013 13:23:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256626 - user/glebius/course/04.synchronisation X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 13:23:48 -0000 Author: glebius Date: Wed Oct 16 13:23:47 2013 New Revision: 256626 URL: http://svnweb.freebsd.org/changeset/base/256626 Log: More on synchronisation. Modified: user/glebius/course/04.synchronisation/lection.tex Modified: user/glebius/course/04.synchronisation/lection.tex ============================================================================== --- user/glebius/course/04.synchronisation/lection.tex Wed Oct 16 13:07:06 2013 (r256625) +++ user/glebius/course/04.synchronisation/lection.tex Wed Oct 16 13:23:47 2013 (r256626) @@ -403,6 +403,7 @@ struct rwlock { \item {A thread can hold many turnstiles} \item {A thread can stay only in one turnstile} \end{itemize} +\onslide<2-> { \begin{figure} \begin{tikzpicture}[every node/.style={draw, node distance=10mm}] \node [name=turnstile, struct, rectangle split parts = 5] { @@ -422,6 +423,7 @@ struct rwlock { }; \end{tikzpicture} \end{figure} +} \end{frame} @@ -470,7 +472,7 @@ struct rwlock { \FootReferences{witness(4)}{sys/kern/subr\_witness.c} \begin{frame} \frametitle{witness(4)} -\onslide<1-> { +\only<1,2> { \begin{itemize} \item {Maintains ordered list of locks for each process} \item {Maintains global list of well known locks in correct order @@ -480,7 +482,7 @@ struct rwlock { \item {Reports violations} \end{itemize} } -\onslide<2-> { +\only<2> { \shellcmd{% \# kgdb\\ (kgdb) p td->td\_sleeplocks\\ @@ -488,5 +490,60 @@ struct rwlock { (kgdb) p *td->td\_sleeplocks->ll\_children[0].li\_lock->lo\_witness\\ } } +\only<3> { + Example warning: + \shellcmd{\tiny{% + lock order reversal:\\ + 1st 0xfffff800014b3d50 ufs (ufs) \@ /usr/src/sys/kern/vfs\_subr.c:2101\\ + 2nd 0xfffffe001ec98ab8 bufwait (bufwait) \@ /usr/src/sys/ufs/ffs/ffs\_vnops.c:262\\ + 3rd 0xfffff80017c8dd50 ufs (ufs) \@ /usr/src/sys/kern/vfs\_subr.c:2101\\ + KDB: stack backtrace:\\ + db\_trace\_self\_wrapper() at db\_trace\_self\_wrapper+0x2b/frame 0xfffffe002cdb1dd0\\ + kdb\_backtrace() at kdb\_backtrace+0x39/frame 0xfffffe002cdb1e80\\ + witness\_checkorder() at witness\_checkorder+0xd23/frame 0xfffffe002cdb1f10\\ + \_\_lockmgr\_args() at \_\_lockmgr\_args+0x86c/frame 0xfffffe002cdb2040\\ + ffs\_lock() at ffs\_lock+0x84/frame 0xfffffe002cdb2090\\ + VOP\_LOCK1\_APV() at VOP\_LOCK1\_APV+0xf5/frame 0xfffffe002cdb20c0\\ + \_vn\_lock() at \_vn\_lock+0xab/frame 0xfffffe002cdb2130\\ + vget() at vget+0x70/frame 0xfffffe002cdb2180\\ + vfs\_hash\_get() at vfs\_hash\_get+0xf5/frame 0xfffffe002cdb21d0\\ + ffs\_vgetf() at ffs\_vgetf+0x41/frame 0xfffffe002cdb2260\\ + softdep\_sync\_buf() at softdep\_sync\_buf+0x8fa/frame 0xfffffe002cdb2310\\ + ffs\_syncvnode() at ffs\_syncvnode+0x258/frame 0xfffffe002cdb2390\\ + ffs\_truncate() at ffs\_truncate+0x5b5/frame 0xfffffe002cdb2570\\ + ufs\_direnter() at ufs\_direnter+0x812/frame 0xfffffe002cdb2630\\ + ufs\_makeinode() at ufs\_makeinode+0x4bf/frame 0xfffffe002cdb27f0\\ + VOP\_CREATE\_APV() at VOP\_CREATE\_APV+0xea/frame 0xfffffe002cdb2820\\ + vn\_open\_cred() at vn\_open\_cred+0x300/frame 0xfffffe002cdb2970\\ + kern\_openat() at kern\_openat+0x261/frame 0xfffffe002cdb2ae0\\ + amd64\_syscall() at amd64\_syscall+0x265/frame 0xfffffe002cdb2bf0\\ + Xfast\_syscall() at Xfast\_syscall+0xfb/frame 0xfffffe002cdb2bf0\\ + }} +} +\end{frame} + + +\usebackgroundtemplate{} +\FootReferences{}{} +\begin{frame} +\frametitle{Practice} + \begin{itemize} + \item \Man{queue}{3} + \item \Man{malloc}{9} + \item \Man{mutex}{9} + \end{itemize} + Checkout or update todays examples. + \shellcmd{% + \# svn co http://svn.freebsd.org/base/user/glebius/course\\ + \# cd course\\ + \# cd 04.*/code\\ + } + or + \shellcmd{% + \# cd course\\ + \# svn update\\ + \# cd 04.*/code\\ + } \end{frame} + \end{document} From owner-svn-src-user@FreeBSD.ORG Wed Oct 16 13:33:48 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id CDA4F6C0; Wed, 16 Oct 2013 13:33:48 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id BBF132E4E; Wed, 16 Oct 2013 13:33:48 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9GDXmSm037558; Wed, 16 Oct 2013 13:33:48 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9GDXmol037557; Wed, 16 Oct 2013 13:33:48 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310161333.r9GDXmol037557@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 16 Oct 2013 13:33:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256627 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 13:33:48 -0000 Author: ae Date: Wed Oct 16 13:33:48 2013 New Revision: 256627 URL: http://svnweb.freebsd.org/changeset/base/256627 Log: RTFREE() sets ro_rt to NULL, no need to do it again. Also properly initialize ro_dst for IPV6_NEXTHOP socket option. Modified: user/ae/inet6/sys/netinet6/ip6_output.c Modified: user/ae/inet6/sys/netinet6/ip6_output.c ============================================================================== --- user/ae/inet6/sys/netinet6/ip6_output.c Wed Oct 16 13:23:47 2013 (r256626) +++ user/ae/inet6/sys/netinet6/ip6_output.c Wed Oct 16 13:33:48 2013 (r256627) @@ -2434,13 +2434,11 @@ ip6_clearpktopts(struct ip6_pktopts *pkt if (optname == -1 || optname == IPV6_TCLASS) pktopt->ip6po_tclass = -1; if (optname == -1 || optname == IPV6_NEXTHOP) { - if (pktopt->ip6po_nextroute.ro_rt) { + if (pktopt->ip6po_nextroute.ro_rt) RTFREE(pktopt->ip6po_nextroute.ro_rt); - pktopt->ip6po_nextroute.ro_rt = NULL; - } if (pktopt->ip6po_nexthop) free(pktopt->ip6po_nexthop, M_IP6OPT); - pktopt->ip6po_nexthop = NULL; + bzero(&pktopt->ip6po_nhinfo, sizeof(pktopt->ip6po_nhinfo)); } if (optname == -1 || optname == IPV6_HOPOPTS) { if (pktopt->ip6po_hbh) @@ -2456,10 +2454,8 @@ ip6_clearpktopts(struct ip6_pktopts *pkt if (pktopt->ip6po_rhinfo.ip6po_rhi_rthdr) free(pktopt->ip6po_rhinfo.ip6po_rhi_rthdr, M_IP6OPT); pktopt->ip6po_rhinfo.ip6po_rhi_rthdr = NULL; - if (pktopt->ip6po_route.ro_rt) { + if (pktopt->ip6po_route.ro_rt) RTFREE(pktopt->ip6po_route.ro_rt); - pktopt->ip6po_route.ro_rt = NULL; - } } if (optname == -1 || optname == IPV6_DSTOPTS) { if (pktopt->ip6po_dest2) @@ -2822,6 +2818,7 @@ ip6_setpktopt(int optname, u_char *buf, if (opt->ip6po_nexthop == NULL) return (ENOBUFS); bcopy(buf, opt->ip6po_nexthop, *buf); + bcopy(buf, &opt->ip6po_nextroute.ro_dst, *buf); break; case IPV6_2292HOPOPTS: From owner-svn-src-user@FreeBSD.ORG Wed Oct 16 22:53:01 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 4E757BC4; Wed, 16 Oct 2013 22:53:01 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 3A81F2075; Wed, 16 Oct 2013 22:53:01 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9GMr0Aq033437; Wed, 16 Oct 2013 22:53:00 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9GMr0Y0033436; Wed, 16 Oct 2013 22:53:00 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310162253.r9GMr0Y0033436@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 16 Oct 2013 22:53:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256654 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 22:53:01 -0000 Author: ae Date: Wed Oct 16 22:53:00 2013 New Revision: 256654 URL: http://svnweb.freebsd.org/changeset/base/256654 Log: Rework ip6_input(): * remove bunch of unneeded variables and sort declarations; * don't use auxiliary data; * rework scope related checks, remove in6_setscope() calls; * use ifaddr hash to check for own addresses; * remove route and lle lookup from input path; * remove FAITH support from ip6_input. Modified: user/ae/inet6/sys/netinet6/ip6_input.c Modified: user/ae/inet6/sys/netinet6/ip6_input.c ============================================================================== --- user/ae/inet6/sys/netinet6/ip6_input.c Wed Oct 16 22:30:29 2013 (r256653) +++ user/ae/inet6/sys/netinet6/ip6_input.c Wed Oct 16 22:53:00 2013 (r256654) @@ -427,19 +427,16 @@ out: void ip6_input(struct mbuf *m) { + struct in6_addr odst; struct ip6_hdr *ip6; + struct in6_ifaddr *ia; + int32_t plen; + int32_t rtalert = ~0; int off = sizeof(struct ip6_hdr), nest; - u_int32_t plen; - u_int32_t rtalert = ~0; + int srcscope, dstscope; int nxt, ours = 0; - struct ifnet *deliverifp = NULL, *ifp = NULL; - struct in6_addr odst; - struct route_in6 rin6; int srcrt = 0; - struct llentry *lle = NULL; - struct sockaddr_in6 dst6, *dst; - bzero(&rin6, sizeof(struct route_in6)); #ifdef IPSEC /* * should the inner packet be considered authentic? @@ -452,18 +449,12 @@ ip6_input(struct mbuf *m) #endif /* IPSEC */ - /* - * make sure we don't have onion peering information into m_tag. - */ - ip6_delaux(m); - if (m->m_flags & M_FASTFWD_OURS) { /* * Firewall changed destination to local. */ m->m_flags &= ~M_FASTFWD_OURS; ours = 1; - deliverifp = m->m_pkthdr.rcvif; ip6 = mtod(m, struct ip6_hdr *); goto hbhcheck; } @@ -643,7 +634,6 @@ ip6_input(struct mbuf *m) if (m->m_flags & M_FASTFWD_OURS) { m->m_flags &= ~M_FASTFWD_OURS; ours = 1; - deliverifp = m->m_pkthdr.rcvif; goto hbhcheck; } if ((m->m_flags & M_IP6_NEXTHOP) && @@ -654,30 +644,22 @@ ip6_input(struct mbuf *m) * connected host. */ ip6_forward(m, 1); - goto out; + return; } passin: - /* - * Disambiguate address scope zones (if there is ambiguity). - * We first make sure that the original source or destination address - * is not in our internal form for scoped addresses. Such addresses - * are not necessarily invalid spec-wise, but we cannot accept them due - * to the usage conflict. - * in6_setscope() then also checks and rejects the cases where src or - * dst are the loopback address and the receiving interface - * is not loopback. - */ - if (in6_clearscope(&ip6->ip6_src) || in6_clearscope(&ip6->ip6_dst)) { - IP6STAT_INC(ip6s_badscope); /* XXX */ - goto bad; - } - if (in6_setscope(&ip6->ip6_src, m->m_pkthdr.rcvif, NULL) || - in6_setscope(&ip6->ip6_dst, m->m_pkthdr.rcvif, NULL)) { - IP6STAT_INC(ip6s_badscope); - goto bad; + srcscope = in6_addrscope(&ip6->ip6_src); + if (srcscope == IPV6_ADDR_SCOPE_LINKLOCAL && + IN6_IS_ADDR_LOOPBACK(&ip6->ip6_src)) { + /* + * Packets with the loopback source address must be + * received on the loopback interface. + */ + if (m->m_pkthdr.rcvif != V_loif) { + IP6STAT_INC(ip6s_badscope); + goto bad; + } } - /* * Multicast check. Assume packet is for us to avoid * prematurely taking locks. @@ -685,167 +667,38 @@ passin: if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) { ours = 1; in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_mcast); - deliverifp = m->m_pkthdr.rcvif; goto hbhcheck; } /* * Unicast check */ - - bzero(&dst6, sizeof(dst6)); - dst6.sin6_family = AF_INET6; - dst6.sin6_len = sizeof(struct sockaddr_in6); - dst6.sin6_addr = ip6->ip6_dst; - ifp = m->m_pkthdr.rcvif; - IF_AFDATA_RLOCK(ifp); - lle = lla_lookup(LLTABLE6(ifp), 0, - (struct sockaddr *)&dst6); - IF_AFDATA_RUNLOCK(ifp); - if ((lle != NULL) && (lle->la_flags & LLE_IFADDR)) { - struct ifaddr *ifa; - struct in6_ifaddr *ia6; - int bad; - - bad = 1; -#define sa_equal(a1, a2) \ - (bcmp((a1), (a2), ((a1))->sin6_len) == 0) - IF_ADDR_RLOCK(ifp); - TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { - if (ifa->ifa_addr->sa_family != dst6.sin6_family) - continue; - if (sa_equal(&dst6, ifa->ifa_addr)) - break; - } - KASSERT(ifa != NULL, ("%s: ifa not found for lle %p", - __func__, lle)); -#undef sa_equal - - ia6 = (struct in6_ifaddr *)ifa; - if (!(ia6->ia6_flags & IN6_IFF_NOTREADY)) { - /* Count the packet in the ip address stats */ - ia6->ia_ifa.if_ipackets++; - ia6->ia_ifa.if_ibytes += m->m_pkthdr.len; - + dstscope = in6_addrscope(&ip6->ip6_dst); + ia = in6ifa_ifwithaddr(&ip6->ip6_dst, + in6_getscopezone(m->m_pkthdr.rcvif, dstscope)); + if (ia == NULL) { + /* + * This means that the receiving interface doesn't have this + * scoped (i.e. not global) address configured. + */ + if (IN6_IS_ADDR_LOOPBACK(&ip6->ip6_dst)) { /* - * record address information into m_tag. + * Packets with the loopback destination address must + * be received on the loopback interface. */ - (void)ip6_setdstifaddr(m, ia6); - - bad = 0; - } else { - char ip6bufs[INET6_ADDRSTRLEN]; - char ip6bufd[INET6_ADDRSTRLEN]; - /* address is not ready, so discard the packet. */ - nd6log((LOG_INFO, - "ip6_input: packet to an unready address %s->%s\n", - ip6_sprintf(ip6bufs, &ip6->ip6_src), - ip6_sprintf(ip6bufd, &ip6->ip6_dst))); - } - IF_ADDR_RUNLOCK(ifp); - LLE_RUNLOCK(lle); - if (bad) + IP6STAT_INC(ip6s_badscope); goto bad; - else { - ours = 1; - deliverifp = ifp; - goto hbhcheck; - } - } - if (lle != NULL) - LLE_RUNLOCK(lle); - - dst = &rin6.ro_dst; - dst->sin6_len = sizeof(struct sockaddr_in6); - dst->sin6_family = AF_INET6; - dst->sin6_addr = ip6->ip6_dst; - rin6.ro_rt = in6_rtalloc1((struct sockaddr *)dst, 0, 0, M_GETFIB(m)); - if (rin6.ro_rt) - RT_UNLOCK(rin6.ro_rt); - -#define rt6_key(r) ((struct sockaddr_in6 *)((r)->rt_nodes->rn_key)) - - /* - * Accept the packet if the forwarding interface to the destination - * according to the routing table is the loopback interface, - * unless the associated route has a gateway. - * Note that this approach causes to accept a packet if there is a - * route to the loopback interface for the destination of the packet. - * But we think it's even useful in some situations, e.g. when using - * a special daemon which wants to intercept the packet. - * - * XXX: some OSes automatically make a cloned route for the destination - * of an outgoing packet. If the outgoing interface of the packet - * is a loopback one, the kernel would consider the packet to be - * accepted, even if we have no such address assinged on the interface. - * We check the cloned flag of the route entry to reject such cases, - * assuming that route entries for our own addresses are not made by - * cloning (it should be true because in6_addloop explicitly installs - * the host route). However, we might have to do an explicit check - * while it would be less efficient. Or, should we rather install a - * reject route for such a case? - */ - if (rin6.ro_rt && - (rin6.ro_rt->rt_flags & - (RTF_HOST|RTF_GATEWAY)) == RTF_HOST && -#ifdef RTF_WASCLONED - !(rin6.ro_rt->rt_flags & RTF_WASCLONED) && -#endif -#ifdef RTF_CLONED - !(rin6.ro_rt->rt_flags & RTF_CLONED) && -#endif -#if 0 - /* - * The check below is redundant since the comparison of - * the destination and the key of the rtentry has - * already done through looking up the routing table. - */ - IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst, - &rt6_key(rin6.ro_rt)->sin6_addr) -#endif - rin6.ro_rt->rt_ifp->if_type == IFT_LOOP) { - int free_ia6 = 0; - struct in6_ifaddr *ia6; - - /* - * found the loopback route to the interface address - */ - if (rin6.ro_rt->rt_gateway->sa_family == AF_LINK) { - struct sockaddr_in6 dest6; - - bzero(&dest6, sizeof(dest6)); - dest6.sin6_family = AF_INET6; - dest6.sin6_len = sizeof(dest6); - dest6.sin6_addr = ip6->ip6_dst; - ia6 = (struct in6_ifaddr *) - ifa_ifwithaddr((struct sockaddr *)&dest6); - if (ia6 == NULL) - goto bad; - free_ia6 = 1; } - else - ia6 = (struct in6_ifaddr *)rin6.ro_rt->rt_ifa; - - /* - * record address information into m_tag. - */ - (void)ip6_setdstifaddr(m, ia6); - /* - * packets to a tentative, duplicated, or somehow invalid - * address must not be accepted. + * RFC 4007 p9: + * If a router receives a packet with a link-local destination + * address that is not one of the router's own link-local + * addresses on the arrival link, the router is expected to + * try to forward the packet to the destination on that link. */ - if (!(ia6->ia6_flags & IN6_IFF_NOTREADY)) { - /* this address is ready */ - ours = 1; - deliverifp = ia6->ia_ifp; /* correct? */ - /* Count the packet in the ip address stats */ - ia6->ia_ifa.if_ipackets++; - ia6->ia_ifa.if_ibytes += m->m_pkthdr.len; - if (ia6 != NULL && free_ia6 != 0) - ifa_free(&ia6->ia_ifa); - goto hbhcheck; - } else { + /* FALLTHROUGH */ + } else { + if (ia->ia6_flags & IN6_IFF_NOTREADY) { char ip6bufs[INET6_ADDRSTRLEN]; char ip6bufd[INET6_ADDRSTRLEN]; /* address is not ready, so discard the packet. */ @@ -853,26 +706,16 @@ passin: "ip6_input: packet to an unready address %s->%s\n", ip6_sprintf(ip6bufs, &ip6->ip6_src), ip6_sprintf(ip6bufd, &ip6->ip6_dst))); - - if (ia6 != NULL && free_ia6 != 0) - ifa_free(&ia6->ia_ifa); + ifa_free(&ia->ia_ifa); goto bad; } + /* Count the packet in the ip address stats */ + ia->ia_ifa.if_ipackets++; + ia->ia_ifa.if_ibytes += m->m_pkthdr.len; + ifa_free(&ia->ia_ifa); + ours = 1; + goto hbhcheck; } - - /* - * FAITH (Firewall Aided Internet Translator) - */ - if (V_ip6_keepfaith) { - if (rin6.ro_rt && rin6.ro_rt->rt_ifp && - rin6.ro_rt->rt_ifp->if_type == IFT_FAITH) { - /* XXX do we need more sanity checks? */ - ours = 1; - deliverifp = rin6.ro_rt->rt_ifp; /* faith */ - goto hbhcheck; - } - } - /* * Now there is no reason to process the packet if it's not our own * and we're not a router. @@ -885,32 +728,6 @@ passin: hbhcheck: /* - * record address information into m_tag, if we don't have one yet. - * note that we are unable to record it, if the address is not listed - * as our interface address (e.g. multicast addresses, addresses - * within FAITH prefixes and such). - */ - if (deliverifp) { - struct in6_ifaddr *ia6; - - if ((ia6 = ip6_getdstifaddr(m)) != NULL) { - ifa_free(&ia6->ia_ifa); - } else { - ia6 = in6_ifawithifp(deliverifp, &ip6->ip6_dst); - if (ia6) { - if (!ip6_setdstifaddr(m, ia6)) { - /* - * XXX maybe we should drop the packet here, - * as we could not provide enough information - * to the upper layers. - */ - } - ifa_free(&ia6->ia_ifa); - } - } - } - - /* * Process Hop-by-Hop options header if it's contained. * m may be modified in ip6_hopopts_input(). * If a JumboPayload option is included, plen will also be modified. @@ -921,7 +738,7 @@ passin: error = ip6_input_hbh(m, &plen, &rtalert, &off, &nxt, &ours); if (error != 0) - goto out; + return; } else nxt = ip6->ip6_nxt; @@ -968,7 +785,7 @@ passin: } } else if (!ours) { ip6_forward(m, srcrt); - goto out; + return; } ip6 = mtod(m, struct ip6_hdr *); @@ -993,7 +810,7 @@ passin: * Tell launch routine the next header */ IP6STAT_INC(ip6s_delivered); - in6_ifstat_inc(deliverifp, ifs6_in_deliver); + in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_deliver); nest = 0; while (nxt != IPPROTO_DONE) { @@ -1031,12 +848,9 @@ passin: nxt = (*inet6sw[ip6_protox[nxt]].pr_input)(&m, &off, nxt); } - goto out; + return; bad: m_freem(m); -out: - if (rin6.ro_rt) - RTFREE(rin6.ro_rt); } /* From owner-svn-src-user@FreeBSD.ORG Thu Oct 17 05:43:28 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id F03DF8FE; Thu, 17 Oct 2013 05:43:28 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id DD9C52346; Thu, 17 Oct 2013 05:43:28 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9H5hSsG052481; Thu, 17 Oct 2013 05:43:28 GMT (envelope-from glebius@svn.freebsd.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9H5hS8f052480; Thu, 17 Oct 2013 05:43:28 GMT (envelope-from glebius@svn.freebsd.org) Message-Id: <201310170543.r9H5hS8f052480@svn.freebsd.org> From: Gleb Smirnoff Date: Thu, 17 Oct 2013 05:43:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256664 - user/glebius/course/03.processes&threads X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2013 05:43:29 -0000 Author: glebius Date: Thu Oct 17 05:43:28 2013 New Revision: 256664 URL: http://svnweb.freebsd.org/changeset/base/256664 Log: Typos. Modified: user/glebius/course/03.processes&threads/lection.tex Modified: user/glebius/course/03.processes&threads/lection.tex ============================================================================== --- user/glebius/course/03.processes&threads/lection.tex Thu Oct 17 05:20:40 2013 (r256663) +++ user/glebius/course/03.processes&threads/lection.tex Thu Oct 17 05:43:28 2013 (r256664) @@ -54,10 +54,10 @@ { file descriptor table }; \draw [->] (proc.four east) -- (fdesc); \node[name=rlim, right=of proc.five east, rounded corners] - { resource limits }; + { credentials }; \draw [->] (proc.five east) -- (rlim); \node[name=cred, right=of proc.six east, rounded corners] - { credentials }; + { resource limits }; \draw [->] (proc.six east) -- (cred); % threads @@ -94,7 +94,7 @@ \node [name=thread, struct, inner sep=2mm, rectangle split parts = 6] { \textbf{struct thread} \nodepart{two} struct proc *td\_proc - \nodepart{three} struct proc *td\_sched + \nodepart{three} struct td\_sched *td\_sched \nodepart{four} struct pcb *td\_pcb \nodepart{five} struct vm\_object *td\_kstack\_obj \nodepart{six} \ldots From owner-svn-src-user@FreeBSD.ORG Thu Oct 17 10:53:58 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 9E77899F; Thu, 17 Oct 2013 10:53:58 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 8B56B2548; Thu, 17 Oct 2013 10:53:58 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9HArwfd017120; Thu, 17 Oct 2013 10:53:58 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9HArvep017115; Thu, 17 Oct 2013 10:53:57 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310171053.r9HArvep017115@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Thu, 17 Oct 2013 10:53:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256673 - in user/ae/inet6/sys: netinet netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2013 10:53:58 -0000 Author: ae Date: Thu Oct 17 10:53:57 2013 New Revision: 256673 URL: http://svnweb.freebsd.org/changeset/base/256673 Log: Remove auxiliary data support and use in6ifa_ifwithaddr() function instead of ip6_getdstifaddr(). Modified: user/ae/inet6/sys/netinet/tcp_input.c user/ae/inet6/sys/netinet6/frag6.c user/ae/inet6/sys/netinet6/icmp6.c user/ae/inet6/sys/netinet6/ip6_input.c user/ae/inet6/sys/netinet6/ip6_var.h Modified: user/ae/inet6/sys/netinet/tcp_input.c ============================================================================== --- user/ae/inet6/sys/netinet/tcp_input.c Thu Oct 17 09:57:09 2013 (r256672) +++ user/ae/inet6/sys/netinet/tcp_input.c Thu Oct 17 10:53:57 2013 (r256673) @@ -530,6 +530,7 @@ tcp6_input(struct mbuf **mp, int *offp, { struct mbuf *m = *mp; struct in6_ifaddr *ia6; + struct ip6_hdr *ip6; IP6_EXTHDR_CHECK(m, *offp, sizeof(struct tcphdr), IPPROTO_DONE); @@ -537,12 +538,12 @@ tcp6_input(struct mbuf **mp, int *offp, * draft-itojun-ipv6-tcp-to-anycast * better place to put this in? */ - ia6 = ip6_getdstifaddr(m); + ip6 = mtod(m, struct ip6_hdr *); + ia6 = in6ifa_ifwithaddr(&ip6->ip6_dst, + in6_getscopezone(m->m_pkthdr.rcvif, + in6_addrscope(&ip6->ip6_dst))); if (ia6 && (ia6->ia6_flags & IN6_IFF_ANYCAST)) { - struct ip6_hdr *ip6; - ifa_free(&ia6->ia_ifa); - ip6 = mtod(m, struct ip6_hdr *); icmp6_error(m, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADDR, (caddr_t)&ip6->ip6_dst - (caddr_t)ip6); return IPPROTO_DONE; @@ -1269,7 +1270,9 @@ relocked: if (isipv6 && !V_ip6_use_deprecated) { struct in6_ifaddr *ia6; - ia6 = ip6_getdstifaddr(m); + ia6 = in6ifa_ifwithaddr(&ip6->ip6_dst, + in6_getscopezone(m->m_pkthdr.rcvif, + in6_addrscope(&ip6->ip6_dst))); if (ia6 != NULL && (ia6->ia6_flags & IN6_IFF_DEPRECATED)) { ifa_free(&ia6->ia_ifa); Modified: user/ae/inet6/sys/netinet6/frag6.c ============================================================================== --- user/ae/inet6/sys/netinet6/frag6.c Thu Oct 17 09:57:09 2013 (r256672) +++ user/ae/inet6/sys/netinet6/frag6.c Thu Oct 17 10:53:57 2013 (r256673) @@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include /* for ECN definitions */ #include /* for ECN definitions */ @@ -184,7 +185,10 @@ frag6_input(struct mbuf **mp, int *offp, dstifp = NULL; #ifdef IN6_IFSTAT_STRICT /* find the destination interface of the packet. */ - if ((ia = ip6_getdstifaddr(m)) != NULL) { + ia = in6ifa_ifwithaddr(&ip6->ip6_dst, + in6_getscopezone(m->m_pkthdr.rcvif, + in6_addrscope(&ip6->ip6_dst))); + if (ia != NULL) { dstifp = ia->ia_ifp; ifa_free(&ia->ia_ifa); } Modified: user/ae/inet6/sys/netinet6/icmp6.c ============================================================================== --- user/ae/inet6/sys/netinet6/icmp6.c Thu Oct 17 09:57:09 2013 (r256672) +++ user/ae/inet6/sys/netinet6/icmp6.c Thu Oct 17 10:53:57 2013 (r256673) @@ -1309,7 +1309,10 @@ ni6_input(struct mbuf *m, int off) goto bad; /* else it's a link-local multicast, fine */ } else { /* unicast or anycast */ - if ((ia6 = ip6_getdstifaddr(m)) == NULL) + ia6 = in6ifa_ifwithaddr(&ip6->ip6_dst, + in6_getscopezone(m->m_pkthdr.rcvif, + in6_addrscope(&ip6->ip6_dst))); + if (ia6 == NULL) goto bad; /* XXX impossible */ if ((ia6->ia6_flags & IN6_IFF_TEMPORARY) && @@ -2198,32 +2201,15 @@ icmp6_reflect(struct mbuf *m, size_t off * The IN6_IFF_NOTREADY case should be VERY rare, but is possible * (for example) when we encounter an error while forwarding procedure * destined to a duplicated address of ours. - * Note that ip6_getdstifaddr() may fail if we are in an error handling - * procedure of an outgoing packet of our own, in which case we need - * to search in the ifaddr list. */ - if (!IN6_IS_ADDR_MULTICAST(&origdst)) { - if ((ia = ip6_getdstifaddr(m))) { - if (!(ia->ia6_flags & - (IN6_IFF_ANYCAST|IN6_IFF_NOTREADY))) - srcp = &ia->ia_addr.sin6_addr; - } else { - struct sockaddr_in6 d; - - bzero(&d, sizeof(d)); - d.sin6_family = AF_INET6; - d.sin6_len = sizeof(d); - d.sin6_addr = origdst; - ia = (struct in6_ifaddr *) - ifa_ifwithaddr((struct sockaddr *)&d); - if (ia && - !(ia->ia6_flags & - (IN6_IFF_ANYCAST|IN6_IFF_NOTREADY))) { - srcp = &ia->ia_addr.sin6_addr; - } - } + if (!IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) { + ia = in6ifa_ifwithaddr(&ip6->ip6_dst, + in6_getscopezone(m->m_pkthdr.rcvif, + in6_addrscope(&ip6->ip6_dst))); + if (ia != NULL && !(ia->ia6_flags & + (IN6_IFF_ANYCAST | IN6_IFF_NOTREADY))) + srcp = &ia->ia_addr.sin6_addr; } - if (srcp == NULL) { int e; struct sockaddr_in6 sin6; Modified: user/ae/inet6/sys/netinet6/ip6_input.c ============================================================================== --- user/ae/inet6/sys/netinet6/ip6_input.c Thu Oct 17 09:57:09 2013 (r256672) +++ user/ae/inet6/sys/netinet6/ip6_input.c Thu Oct 17 10:53:57 2013 (r256673) @@ -154,10 +154,6 @@ struct rwlock in6_ifaddr_lock; RW_SYSINIT(in6_ifaddr_lock, &in6_ifaddr_lock, "in6_ifaddr_lock"); static void ip6_init2(void *); -static struct ip6aux *ip6_setdstifaddr(struct mbuf *, struct in6_ifaddr *); -static struct ip6aux *ip6_addaux(struct mbuf *); -static struct ip6aux *ip6_findaux(struct mbuf *m); -static void ip6_delaux (struct mbuf *); static int ip6_hopopts_input(u_int32_t *, u_int32_t *, struct mbuf **, int *); #ifdef PULLDOWN_TEST static struct mbuf *ip6_pullexthdr(struct mbuf *, size_t, int); @@ -854,41 +850,6 @@ bad: } /* - * set/grab in6_ifaddr correspond to IPv6 destination address. - * XXX backward compatibility wrapper - * - * XXXRW: We should bump the refcount on ia6 before sticking it in the m_tag, - * and then bump it when the tag is copied, and release it when the tag is - * freed. Unfortunately, m_tags don't support deep copies (yet), so instead - * we just bump the ia refcount when we receive it. This should be fixed. - */ -static struct ip6aux * -ip6_setdstifaddr(struct mbuf *m, struct in6_ifaddr *ia6) -{ - struct ip6aux *ip6a; - - ip6a = ip6_addaux(m); - if (ip6a) - ip6a->ip6a_dstia6 = ia6; - return ip6a; /* NULL if failed to set */ -} - -struct in6_ifaddr * -ip6_getdstifaddr(struct mbuf *m) -{ - struct ip6aux *ip6a; - struct in6_ifaddr *ia; - - ip6a = ip6_findaux(m); - if (ip6a) { - ia = ip6a->ip6a_dstia6; - ifa_ref(&ia->ia_ifa); - return ia; - } else - return NULL; -} - -/* * Hop-by-Hop options header processing. If a valid jumbo payload option is * included, the real payload length will be stored in plenp. * @@ -1651,46 +1612,9 @@ ip6_lasthdr(struct mbuf *m, int off, int } } -static struct ip6aux * -ip6_addaux(struct mbuf *m) -{ - struct m_tag *mtag; - - mtag = m_tag_find(m, PACKET_TAG_IPV6_INPUT, NULL); - if (!mtag) { - mtag = m_tag_get(PACKET_TAG_IPV6_INPUT, sizeof(struct ip6aux), - M_NOWAIT); - if (mtag) { - m_tag_prepend(m, mtag); - bzero(mtag + 1, sizeof(struct ip6aux)); - } - } - return mtag ? (struct ip6aux *)(mtag + 1) : NULL; -} - -static struct ip6aux * -ip6_findaux(struct mbuf *m) -{ - struct m_tag *mtag; - - mtag = m_tag_find(m, PACKET_TAG_IPV6_INPUT, NULL); - return mtag ? (struct ip6aux *)(mtag + 1) : NULL; -} - -static void -ip6_delaux(struct mbuf *m) -{ - struct m_tag *mtag; - - mtag = m_tag_find(m, PACKET_TAG_IPV6_INPUT, NULL); - if (mtag) - m_tag_delete(m, mtag); -} - /* * System control for IP6 */ - u_char inet6ctlerrmap[PRC_NCMDS] = { 0, 0, 0, 0, 0, EMSGSIZE, EHOSTDOWN, EHOSTUNREACH, Modified: user/ae/inet6/sys/netinet6/ip6_var.h ============================================================================== --- user/ae/inet6/sys/netinet6/ip6_var.h Thu Oct 17 09:57:09 2013 (r256672) +++ user/ae/inet6/sys/netinet6/ip6_var.h Thu Oct 17 10:53:57 2013 (r256673) @@ -257,37 +257,6 @@ VNET_PCPUSTAT_DECLARE(struct ip6stat, ip #endif #ifdef _KERNEL -/* - * IPv6 onion peeling state. - * it will be initialized when we come into ip6_input(). - * XXX do not make it a kitchen sink! - */ -struct ip6aux { - u_int32_t ip6a_flags; -#define IP6A_SWAP 0x01 /* swapped home/care-of on packet */ -#define IP6A_HASEEN 0x02 /* HA was present */ -#define IP6A_BRUID 0x04 /* BR Unique Identifier was present */ -#define IP6A_RTALERTSEEN 0x08 /* rtalert present */ - - /* ip6.ip6_src */ - struct in6_addr ip6a_careof; /* care-of address of the peer */ - struct in6_addr ip6a_home; /* home address of the peer */ - u_int16_t ip6a_bruid; /* BR unique identifier */ - - /* ip6.ip6_dst */ - struct in6_ifaddr *ip6a_dstia6; /* my ifaddr that matches ip6_dst */ - - /* rtalert */ - u_int16_t ip6a_rtalert; /* rtalert option value */ - - /* - * decapsulation history will be here. - * with IPsec it may not be accurate. - */ -}; -#endif - -#ifdef _KERNEL /* flags passed to ip6_output as last parameter */ #define IPV6_UNSPECSRC 0x01 /* allow :: as the source address */ #define IPV6_FORWARDING 0x02 /* most of IPv6 header exists */ @@ -394,7 +363,6 @@ int ip6proto_register(short); int ip6proto_unregister(short); void ip6_input(struct mbuf *); -struct in6_ifaddr *ip6_getdstifaddr(struct mbuf *); void ip6_freepcbopts(struct ip6_pktopts *); int ip6_unknown_opt(u_int8_t *, struct mbuf *, int); @@ -402,10 +370,6 @@ char * ip6_get_prevhdr(struct mbuf *, in int ip6_nexthdr(struct mbuf *, int, int, int *); int ip6_lasthdr(struct mbuf *, int, int, int *); -#ifdef __notyet__ -struct ip6aux *ip6_findaux(struct mbuf *); -#endif - extern int (*ip6_mforward)(struct ip6_hdr *, struct ifnet *, struct mbuf *); From owner-svn-src-user@FreeBSD.ORG Thu Oct 17 11:33:17 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 022407C2; Thu, 17 Oct 2013 11:33:17 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id E434527B2; Thu, 17 Oct 2013 11:33:16 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9HBXG7I037878; Thu, 17 Oct 2013 11:33:16 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9HBXGZK037877; Thu, 17 Oct 2013 11:33:16 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310171133.r9HBXGZK037877@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Thu, 17 Oct 2013 11:33:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256674 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2013 11:33:17 -0000 Author: ae Date: Thu Oct 17 11:33:16 2013 New Revision: 256674 URL: http://svnweb.freebsd.org/changeset/base/256674 Log: Remove in6_setscope() calls and save ifnet pointer in the mbuf to be able disambiguate the scope. Modified: user/ae/inet6/sys/netinet6/icmp6.c Modified: user/ae/inet6/sys/netinet6/icmp6.c ============================================================================== --- user/ae/inet6/sys/netinet6/icmp6.c Thu Oct 17 10:53:57 2013 (r256673) +++ user/ae/inet6/sys/netinet6/icmp6.c Thu Oct 17 11:33:16 2013 (r256674) @@ -232,23 +232,7 @@ icmp6_error2(struct mbuf *m, int type, i if (ifp == NULL) return; -#ifndef PULLDOWN_TEST - IP6_EXTHDR_CHECK(m, 0, sizeof(struct ip6_hdr), ); -#else - if (m->m_len < sizeof(struct ip6_hdr)) { - m = m_pullup(m, sizeof(struct ip6_hdr)); - if (m == NULL) - return; - } -#endif - - ip6 = mtod(m, struct ip6_hdr *); - - if (in6_setscope(&ip6->ip6_src, ifp, NULL) != 0) - return; - if (in6_setscope(&ip6->ip6_dst, ifp, NULL) != 0) - return; - + m->m_pkthdr.rcvif = ifp; icmp6_error(m, type, code, param); } From owner-svn-src-user@FreeBSD.ORG Thu Oct 17 11:40:08 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id E55F9A06; Thu, 17 Oct 2013 11:40:08 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id C408A2809; Thu, 17 Oct 2013 11:40:08 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9HBe8vf040154; Thu, 17 Oct 2013 11:40:08 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9HBe8s2040153; Thu, 17 Oct 2013 11:40:08 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310171140.r9HBe8s2040153@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Thu, 17 Oct 2013 11:40:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256675 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2013 11:40:09 -0000 Author: ae Date: Thu Oct 17 11:40:08 2013 New Revision: 256675 URL: http://svnweb.freebsd.org/changeset/base/256675 Log: Rework icmp6_reflect(): * sort variables declarations; * when incoming packet was addressed directly for us, use interface where it is configured as outgoing interface (XXX: is it correct?); * otherwise, use SAS Algorithm and keep route information, that it returns. Use this route in ip6_output(). * since we always know outgoing interface, use IPV6_USEROIF flag for ip6_output() Modified: user/ae/inet6/sys/netinet6/icmp6.c Modified: user/ae/inet6/sys/netinet6/icmp6.c ============================================================================== --- user/ae/inet6/sys/netinet6/icmp6.c Thu Oct 17 11:33:16 2013 (r256674) +++ user/ae/inet6/sys/netinet6/icmp6.c Thu Oct 17 11:40:08 2013 (r256675) @@ -227,7 +227,6 @@ void icmp6_error2(struct mbuf *m, int type, int code, int param, struct ifnet *ifp) { - struct ip6_hdr *ip6; if (ifp == NULL) return; @@ -2119,13 +2118,14 @@ icmp6_rip6_input(struct mbuf **mp, int o void icmp6_reflect(struct mbuf *m, size_t off) { + struct route_in6 *ro, ro6; + struct in6_addr src, *srcp = NULL; struct ip6_hdr *ip6; struct icmp6_hdr *icmp6; struct in6_ifaddr *ia = NULL; - int plen; - int type, code; struct ifnet *outif = NULL; - struct in6_addr origdst, src, *srcp = NULL; + uint32_t zoneid; + int type, code, plen, error; /* too short to reflect */ if (off < sizeof(struct ip6_hdr)) { @@ -2172,13 +2172,6 @@ icmp6_reflect(struct mbuf *m, size_t off type = icmp6->icmp6_type; /* keep type for statistics */ code = icmp6->icmp6_code; /* ditto. */ - origdst = ip6->ip6_dst; - /* - * ip6_input() drops a packet if its src is multicast. - * So, the src is never multicast. - */ - ip6->ip6_dst = ip6->ip6_src; - /* * If the incoming packet was addressed directly to us (i.e. unicast), * use dst as the src for the reply. @@ -2186,56 +2179,59 @@ icmp6_reflect(struct mbuf *m, size_t off * (for example) when we encounter an error while forwarding procedure * destined to a duplicated address of ours. */ + zoneid = in6_getscopezone(m->m_pkthdr.rcvif, + in6_addrscope(&ip6->ip6_dst)); if (!IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) { - ia = in6ifa_ifwithaddr(&ip6->ip6_dst, - in6_getscopezone(m->m_pkthdr.rcvif, - in6_addrscope(&ip6->ip6_dst))); + ia = in6ifa_ifwithaddr(&ip6->ip6_dst, zoneid); if (ia != NULL && !(ia->ia6_flags & - (IN6_IFF_ANYCAST | IN6_IFF_NOTREADY))) + (IN6_IFF_ANYCAST | IN6_IFF_NOTREADY))) { srcp = &ia->ia_addr.sin6_addr; + outif = ia->ia_ifp; /* XXX: is it correct? */ + } } + ro = NULL; if (srcp == NULL) { - int e; struct sockaddr_in6 sin6; - struct route_in6 ro; /* * This case matches to multicasts, our anycast, or unicasts * that we do not own. Select a source address based on the * source address of the erroneous packet. */ + ro = &ro6; + bzero(&ro6, sizeof(ro6)); + outif = m->m_pkthdr.rcvif; + bzero(&sin6, sizeof(sin6)); sin6.sin6_family = AF_INET6; sin6.sin6_len = sizeof(sin6); - sin6.sin6_addr = ip6->ip6_dst; /* zone ID should be embedded */ - - bzero(&ro, sizeof(ro)); - e = in6_selectsrc(&sin6, NULL, NULL, &ro, NULL, &outif, &src); - if (ro.ro_rt) - RTFREE(ro.ro_rt); /* XXX: we could use this */ - if (e) { + sin6.sin6_addr = ip6->ip6_src; + sin6.sin6_scope_id = zoneid; + error = in6_selectsrc(&sin6, NULL, NULL, ro, NULL, + &outif, &src); + if (error != 0) { char ip6buf[INET6_ADDRSTRLEN]; nd6log((LOG_DEBUG, "icmp6_reflect: source can't be determined: " "dst=%s, error=%d\n", - ip6_sprintf(ip6buf, &sin6.sin6_addr), e)); + ip6_sprintf(ip6buf, &sin6.sin6_addr), error)); + RO_RTFREE(ro); goto bad; } srcp = &src; } - + KASSERT(outif != NULL, ("%s: outif is NULL", __func__)); + /* + * ip6_input() drops a packet if its src is multicast. + * So, the src is never multicast. + */ + ip6->ip6_dst = ip6->ip6_src; ip6->ip6_src = *srcp; ip6->ip6_flow = 0; ip6->ip6_vfc &= ~IPV6_VERSION_MASK; ip6->ip6_vfc |= IPV6_VERSION; ip6->ip6_nxt = IPPROTO_ICMPV6; - if (outif) - ip6->ip6_hlim = ND_IFINFO(outif)->chlim; - else if (m->m_pkthdr.rcvif) { - /* XXX: This may not be the outgoing interface */ - ip6->ip6_hlim = ND_IFINFO(m->m_pkthdr.rcvif)->chlim; - } else - ip6->ip6_hlim = V_ip6_defhlim; + ip6->ip6_hlim = ND_IFINFO(outif)->chlim; icmp6->icmp6_cksum = 0; icmp6->icmp6_cksum = in6_cksum(m, IPPROTO_ICMPV6, @@ -2247,12 +2243,12 @@ icmp6_reflect(struct mbuf *m, size_t off m->m_flags &= ~(M_BCAST|M_MCAST); - ip6_output(m, NULL, NULL, 0, NULL, &outif, NULL); - if (outif) - icmp6_ifoutstat_inc(outif, type, code); - + ip6_output(m, NULL, ro, IPV6_USEROIF, NULL, &outif, NULL); + icmp6_ifoutstat_inc(outif, type, code); if (ia != NULL) ifa_free(&ia->ia_ifa); + if (ro != NULL) + RO_RTFREE(ro); return; bad: From owner-svn-src-user@FreeBSD.ORG Thu Oct 17 11:43:55 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id EB67CB18; Thu, 17 Oct 2013 11:43:55 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id D96632846; Thu, 17 Oct 2013 11:43:55 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9HBhtx9043234; Thu, 17 Oct 2013 11:43:55 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9HBhtmY043233; Thu, 17 Oct 2013 11:43:55 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310171143.r9HBhtmY043233@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Thu, 17 Oct 2013 11:43:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256676 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2013 11:43:56 -0000 Author: ae Date: Thu Oct 17 11:43:55 2013 New Revision: 256676 URL: http://svnweb.freebsd.org/changeset/base/256676 Log: Remove in6_clearscope() calls. Don't clear ifnet pointer, now we don't have enough scope information in the IP header. Modified: user/ae/inet6/sys/netinet6/icmp6.c Modified: user/ae/inet6/sys/netinet6/icmp6.c ============================================================================== --- user/ae/inet6/sys/netinet6/icmp6.c Thu Oct 17 11:40:08 2013 (r256675) +++ user/ae/inet6/sys/netinet6/icmp6.c Thu Oct 17 11:43:55 2013 (r256676) @@ -360,26 +360,13 @@ icmp6_error(struct mbuf *m, int type, in nip6->ip6_src = oip6->ip6_src; nip6->ip6_dst = oip6->ip6_dst; - in6_clearscope(&oip6->ip6_src); - in6_clearscope(&oip6->ip6_dst); - icmp6 = (struct icmp6_hdr *)(nip6 + 1); icmp6->icmp6_type = type; icmp6->icmp6_code = code; icmp6->icmp6_pptr = htonl((u_int32_t)param); - /* - * icmp6_reflect() is designed to be in the input path. - * icmp6_error() can be called from both input and output path, - * and if we are in output path rcvif could contain bogus value. - * clear m->m_pkthdr.rcvif for safety, we should have enough scope - * information in ip header (nip6). - */ - m->m_pkthdr.rcvif = NULL; - ICMP6STAT_INC(icp6s_outhist[type]); icmp6_reflect(m, sizeof(struct ip6_hdr)); /* header order: IPv6 - ICMPv6 */ - return; freeit: From owner-svn-src-user@FreeBSD.ORG Thu Oct 17 11:45:32 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 40494C21; Thu, 17 Oct 2013 11:45:32 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 2E51C2860; Thu, 17 Oct 2013 11:45:32 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9HBjWL8043928; Thu, 17 Oct 2013 11:45:32 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9HBjWtT043925; Thu, 17 Oct 2013 11:45:32 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310171145.r9HBjWtT043925@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Thu, 17 Oct 2013 11:45:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256677 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2013 11:45:32 -0000 Author: ae Date: Thu Oct 17 11:45:31 2013 New Revision: 256677 URL: http://svnweb.freebsd.org/changeset/base/256677 Log: Fill sin6_scope_id instead of embedding zone id. Modified: user/ae/inet6/sys/netinet6/icmp6.c Modified: user/ae/inet6/sys/netinet6/icmp6.c ============================================================================== --- user/ae/inet6/sys/netinet6/icmp6.c Thu Oct 17 11:43:55 2013 (r256676) +++ user/ae/inet6/sys/netinet6/icmp6.c Thu Oct 17 11:45:31 2013 (r256677) @@ -927,11 +927,11 @@ icmp6_input(struct mbuf **mp, int *offp, static int icmp6_notify_error(struct mbuf **mp, int off, int icmp6len, int code) { + struct sockaddr_in6 icmp6src, icmp6dst; struct mbuf *m = *mp; struct icmp6_hdr *icmp6; struct ip6_hdr *eip6; u_int32_t notifymtu; - struct sockaddr_in6 icmp6src, icmp6dst; if (icmp6len < sizeof(struct icmp6_hdr) + sizeof(struct ip6_hdr)) { ICMP6STAT_INC(icp6s_tooshort); @@ -1113,14 +1113,15 @@ icmp6_notify_error(struct mbuf **mp, int icmp6dst.sin6_addr = eip6->ip6_dst; else icmp6dst.sin6_addr = *finaldst; - if (in6_setscope(&icmp6dst.sin6_addr, m->m_pkthdr.rcvif, NULL)) - goto freeit; + icmp6dst.sin6_scope_id = in6_getscopezone(m->m_pkthdr.rcvif, + in6_addrscope(&icmp6dst.sin6_addr)); + bzero(&icmp6src, sizeof(icmp6src)); icmp6src.sin6_len = sizeof(struct sockaddr_in6); icmp6src.sin6_family = AF_INET6; icmp6src.sin6_addr = eip6->ip6_src; - if (in6_setscope(&icmp6src.sin6_addr, m->m_pkthdr.rcvif, NULL)) - goto freeit; + icmp6src.sin6_scope_id = in6_getscopezone(m->m_pkthdr.rcvif, + in6_addrscope(&icmp6src.sin6_addr)); icmp6src.sin6_flowinfo = (eip6->ip6_flow & IPV6_FLOWLABEL_MASK); From owner-svn-src-user@FreeBSD.ORG Thu Oct 17 11:50:47 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id B209EF15; Thu, 17 Oct 2013 11:50:47 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 9FD6D28A9; Thu, 17 Oct 2013 11:50:47 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9HBolmP048303; Thu, 17 Oct 2013 11:50:47 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9HBolYV048302; Thu, 17 Oct 2013 11:50:47 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310171150.r9HBolYV048302@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Thu, 17 Oct 2013 11:50:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256679 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2013 11:50:47 -0000 Author: ae Date: Thu Oct 17 11:50:47 2013 New Revision: 256679 URL: http://svnweb.freebsd.org/changeset/base/256679 Log: Sort variables declarations, and initialize inc_fibnum and inc6_zoneid. Modified: user/ae/inet6/sys/netinet6/icmp6.c Modified: user/ae/inet6/sys/netinet6/icmp6.c ============================================================================== --- user/ae/inet6/sys/netinet6/icmp6.c Thu Oct 17 11:49:46 2013 (r256678) +++ user/ae/inet6/sys/netinet6/icmp6.c Thu Oct 17 11:50:47 2013 (r256679) @@ -1159,11 +1159,10 @@ icmp6_notify_error(struct mbuf **mp, int void icmp6_mtudisc_update(struct ip6ctlparam *ip6cp, int validated) { + struct in_conninfo inc; struct in6_addr *dst = ip6cp->ip6c_finaldst; struct icmp6_hdr *icmp6 = ip6cp->ip6c_icmp6; - struct mbuf *m = ip6cp->ip6c_m; /* will be necessary for scope issue */ u_int mtu = ntohl(icmp6->icmp6_mtu); - struct in_conninfo inc; #if 0 /* @@ -1198,11 +1197,11 @@ icmp6_mtudisc_update(struct ip6ctlparam mtu = IPV6_MMTU - 8; bzero(&inc, sizeof(inc)); + inc.inc_fibnum = M_GETFIB(ip6cp->ip6c_m); inc.inc_flags |= INC_ISIPV6; inc.inc6_faddr = *dst; - if (in6_setscope(&inc.inc6_faddr, m->m_pkthdr.rcvif, NULL)) - return; - + inc.inc6_zoneid = in6_getscopezone(ip6cp->ip6c_m->m_pkthdr.rcvif, + in6_addrscope(dst)); if (mtu < tcp_maxmtu6(&inc, NULL)) { tcp_hc_updatemtu(&inc, mtu); ICMP6STAT_INC(icp6s_pmtuchg); From owner-svn-src-user@FreeBSD.ORG Thu Oct 17 12:15:22 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 21449F47; Thu, 17 Oct 2013 12:15:22 +0000 (UTC) (envelope-from nwhitehorn@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 0ED1C2A7A; Thu, 17 Oct 2013 12:15:22 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9HCFLZf060936; Thu, 17 Oct 2013 12:15:21 GMT (envelope-from nwhitehorn@svn.freebsd.org) Received: (from nwhitehorn@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9HCFLHE060935; Thu, 17 Oct 2013 12:15:21 GMT (envelope-from nwhitehorn@svn.freebsd.org) Message-Id: <201310171215.r9HCFLHE060935@svn.freebsd.org> From: Nathan Whitehorn Date: Thu, 17 Oct 2013 12:15:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256681 - user/ed/newcons/sys/dev/vt/hw/ofwfb X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2013 12:15:22 -0000 Author: nwhitehorn Date: Thu Oct 17 12:15:21 2013 New Revision: 256681 URL: http://svnweb.freebsd.org/changeset/base/256681 Log: Sync with ofw_syscons.c: provide support for IBM framebuffers like that in the QEMU pSeries emulated platform. Modified: user/ed/newcons/sys/dev/vt/hw/ofwfb/ofwfb.c Modified: user/ed/newcons/sys/dev/vt/hw/ofwfb/ofwfb.c ============================================================================== --- user/ed/newcons/sys/dev/vt/hw/ofwfb/ofwfb.c Thu Oct 17 12:03:17 2013 (r256680) +++ user/ed/newcons/sys/dev/vt/hw/ofwfb/ofwfb.c Thu Oct 17 12:15:21 2013 (r256681) @@ -52,9 +52,7 @@ struct ofwfb_softc { int sc_depth; int sc_stride; -#ifdef __sparc64__ - bus_space_tag_t sc_memt; -#endif + bus_space_tag_t sc_memt; }; static vd_init_t ofwfb_init; @@ -194,7 +192,10 @@ ofwfb_init(struct vt_device *vd) ihandle_t stdout; phandle_t node; uint32_t depth, height, width; + struct ofw_pci_register pciaddrs[8]; + int n_pciaddrs; uint32_t fb_phys; + int i, len; #ifdef __sparc64__ static struct bus_space_tag ofwfb_memt[1]; bus_addr_t phys; @@ -218,8 +219,17 @@ ofwfb_init(struct vt_device *vd) /* Keep track of the OF node */ sc->sc_node = node; + /* Make sure we have needed properties */ + if (OF_getproplen(node, "height") != sizeof(height) || + OF_getproplen(node, "width") != sizeof(width) || + OF_getproplen(node, "depth") != sizeof(depth) || + OF_getproplen(node, "linebytes") != sizeof(sc->sc_stride)) + return (CN_DEAD); + /* Only support 8 and 32-bit framebuffers */ OF_getprop(node, "depth", &depth, sizeof(depth)); + if (depth != 8 && depth != 32) + return (CN_DEAD); sc->sc_depth = depth; OF_getprop(node, "height", &height, sizeof(height)); @@ -230,24 +240,77 @@ ofwfb_init(struct vt_device *vd) vd->vd_width = width; /* + * Get the PCI addresses of the adapter, if present. The node may be the + * child of the PCI device: in that case, try the parent for + * the assigned-addresses property. + */ + len = OF_getprop(node, "assigned-addresses", pciaddrs, + sizeof(pciaddrs)); + if (len == -1) { + len = OF_getprop(OF_parent(node), "assigned-addresses", + pciaddrs, sizeof(pciaddrs)); + } + if (len == -1) + len = 0; + n_pciaddrs = len / sizeof(struct ofw_pci_register); + + /* * Grab the physical address of the framebuffer, and then map it * into our memory space. If the MMU is not yet up, it will be * remapped for us when relocation turns on. + * + * XXX We assume #address-cells is 1 at this point. */ + if (OF_getproplen(node, "address") == sizeof(fb_phys)) { + OF_getprop(node, "address", &fb_phys, sizeof(fb_phys)); + #if defined(__powerpc__) + sc->sc_memt = &bs_be_tag; + bus_space_map(sc->sc_memt, fb_phys, height * sc->sc_stride, + BUS_SPACE_MAP_PREFETCHABLE, &sc->sc_addr); + #elif defined(__sparc64__) + OF_decode_addr(node, 0, &space, &phys); + sc->sc_memt = &ofwfb_memt[0]; + sc->sc_addr = sparc64_fake_bustag(space, fb_phys, sc->sc_memt); + #else + #error Unsupported platform! + #endif + } else { + /* + * Some IBM systems don't have an address property. Try to + * guess the framebuffer region from the assigned addresses. + * This is ugly, but there doesn't seem to be an alternative. + * Linux does the same thing. + */ - /* XXX We assume #address-cells is 1 at this point. */ - OF_getprop(node, "address", &fb_phys, sizeof(fb_phys)); + fb_phys = n_pciaddrs; + for (i = 0; i < n_pciaddrs; i++) { + /* If it is too small, not the framebuffer */ + if (pciaddrs[i].size_lo < sc->sc_stride*height) + continue; + /* If it is not memory, it isn't either */ + if (!(pciaddrs[i].phys_hi & + OFW_PCI_PHYS_HI_SPACE_MEM32)) + continue; -#if defined(__powerpc__) - bus_space_map(&bs_be_tag, fb_phys, height * sc->sc_stride, - BUS_SPACE_MAP_PREFETCHABLE, &sc->sc_addr); -#elif defined(__sparc64__) - OF_decode_addr(node, 0, &space, &phys); - sc->sc_memt = &ofwfb_memt[0]; - sc->sc_addr = sparc64_fake_bustag(space, fb_phys, sc->sc_memt); -#else - #error Unsupported platform! -#endif + /* This could be the framebuffer */ + fb_phys = i; + + /* If it is prefetchable, it certainly is */ + if (pciaddrs[i].phys_hi & OFW_PCI_PHYS_HI_PREFETCHABLE) + break; + } + + if (fb_phys == n_pciaddrs) /* No candidates found */ + return (CN_DEAD); + + #if defined(__powerpc__) + OF_decode_addr(node, fb_phys, &sc->sc_memt, &sc->sc_addr); + #elif defined(__sparc64__) + OF_decode_addr(node, fb_phys, &space, &phys); + sc->sc_memt = &ofwfb_memt[0]; + sc->sc_addr = sparc64_fake_bustag(space, phys, sc->sc_memt); + #endif + } ofwfb_initialize(vd); From owner-svn-src-user@FreeBSD.ORG Thu Oct 17 12:43:30 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 5F669DAC; Thu, 17 Oct 2013 12:43:30 +0000 (UTC) (envelope-from pho@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 336E32C80; Thu, 17 Oct 2013 12:43:30 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9HChUGW076019; Thu, 17 Oct 2013 12:43:30 GMT (envelope-from pho@svn.freebsd.org) Received: (from pho@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9HChUda076018; Thu, 17 Oct 2013 12:43:30 GMT (envelope-from pho@svn.freebsd.org) Message-Id: <201310171243.r9HChUda076018@svn.freebsd.org> From: Peter Holm Date: Thu, 17 Oct 2013 12:43:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256683 - user/pho/stress2/tools X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2013 12:43:30 -0000 Author: pho Date: Thu Oct 17 12:43:29 2013 New Revision: 256683 URL: http://svnweb.freebsd.org/changeset/base/256683 Log: Added tool for shuffling tests for hosts that does not have perl or random(6) installed. Sponsored by: EMC / Isilon storage division Added: user/pho/stress2/tools/shuffle (contents, props changed) Added: user/pho/stress2/tools/shuffle ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/pho/stress2/tools/shuffle Thu Oct 17 12:43:29 2013 (r256683) @@ -0,0 +1,49 @@ +#!/usr/bin/awk -f + +# +# Copyright (c) 2013 EMC Corp. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# + +# Shuffle arguments. Alternative to: +# perl -e 'print splice(@ARGV,rand(@ARGV),1), " " while @ARGV;' +# or +# echo $list | tr ' ' '\n' | random -w | tr '\n' ' ' + +BEGIN { + srand(); rand +} +{ + n = split($0, a, " ") + for (i = 1; i <= n ; i++) { + do + ix = int(rand * n) + 1 + while (! (ix in a)) + printf "%s ", a[ix] + delete a[ix] + } + printf "\n" +} From owner-svn-src-user@FreeBSD.ORG Thu Oct 17 12:58:41 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 591168E1; Thu, 17 Oct 2013 12:58:41 +0000 (UTC) (envelope-from nwhitehorn@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 464792D91; Thu, 17 Oct 2013 12:58:41 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9HCwfZ8081962; Thu, 17 Oct 2013 12:58:41 GMT (envelope-from nwhitehorn@svn.freebsd.org) Received: (from nwhitehorn@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9HCwf9D081961; Thu, 17 Oct 2013 12:58:41 GMT (envelope-from nwhitehorn@svn.freebsd.org) Message-Id: <201310171258.r9HCwf9D081961@svn.freebsd.org> From: Nathan Whitehorn Date: Thu, 17 Oct 2013 12:58:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256684 - user/ed/newcons/sys/dev/vt/hw/ofwfb X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2013 12:58:41 -0000 Author: nwhitehorn Date: Thu Oct 17 12:58:40 2013 New Revision: 256684 URL: http://svnweb.freebsd.org/changeset/base/256684 Log: Use vt_generate_vga_palette() instead of a hard-coded mapping. Modified: user/ed/newcons/sys/dev/vt/hw/ofwfb/ofwfb.c Modified: user/ed/newcons/sys/dev/vt/hw/ofwfb/ofwfb.c ============================================================================== --- user/ed/newcons/sys/dev/vt/hw/ofwfb/ofwfb.c Thu Oct 17 12:43:29 2013 (r256683) +++ user/ed/newcons/sys/dev/vt/hw/ofwfb/ofwfb.c Thu Oct 17 12:58:40 2013 (r256684) @@ -32,6 +32,7 @@ __FBSDID("$FreeBSD: user/ed/newcons/sys/ #include #include +#include #include #include @@ -52,7 +53,9 @@ struct ofwfb_softc { int sc_depth; int sc_stride; - bus_space_tag_t sc_memt; + bus_space_tag_t sc_memt; + + uint32_t sc_colormap[16]; }; static vd_init_t ofwfb_init; @@ -71,25 +74,6 @@ VT_CONSDEV_DECLARE(vt_ofwfb_driver, PIXE &ofwfb_conssoftc); /* XXX: hardcoded max size */ -static const uint32_t colormap[] = { - 0x00000000, /* Black */ - 0x00ff0000, /* Red */ - 0x0000ff00, /* Green */ - 0x00c0c000, /* Brown */ - 0x000000ff, /* Blue */ - 0x00c000c0, /* Magenta */ - 0x0000c0c0, /* Cyan */ - 0x00c0c0c0, /* Light grey */ - 0x00808080, /* Dark grey */ - 0x00ff8080, /* Light red */ - 0x0080ff80, /* Light green */ - 0x00ffff80, /* Yellow */ - 0x008080ff, /* Light blue */ - 0x00ff80ff, /* Light magenta */ - 0x0080ffff, /* Light cyan */ - 0x00ffffff, /* White */ -}; - static void ofwfb_blank(struct vt_device *vd, term_color_t color) { @@ -103,7 +87,7 @@ ofwfb_blank(struct vt_device *vd, term_c *(uint8_t *)(sc->sc_addr + ofs) = color; break; case 32: - c = colormap[color]; + c = sc->sc_colormap[color]; for (ofs = 0; ofs < sc->sc_stride*vd->vd_height; ofs++) *(uint32_t *)(sc->sc_addr + 4*ofs) = c; break; @@ -124,8 +108,8 @@ ofwfb_bitbltchr(struct vt_device *vd, co int c; uint8_t b = 0; - fgc = colormap[fg]; - bgc = colormap[bg]; + fgc = sc->sc_colormap[fg]; + bgc = sc->sc_colormap[bg]; line = (sc->sc_stride * top) + left * sc->sc_depth/8; for (; height > 0; height--) { @@ -160,23 +144,53 @@ ofwfb_initialize(struct vt_device *vd) ihandle_t ih; int i; cell_t retval; + uint32_t oldpix; /* Open display device, thereby initializing it */ memset(name, 0, sizeof(name)); OF_package_to_path(sc->sc_node, name, sizeof(name)); ih = OF_open(name); - if (sc->sc_depth == 8) { - /* - * Install the color map - */ + /* + * Set up the color map + */ + + switch (sc->sc_depth) { + case 8: + vt_generate_vga_palette(sc->sc_colormap, COLOR_FORMAT_RGB, 255, + 16, 255, 8, 255, 0); + for (i = 0; i < 16; i++) { OF_call_method("color!", ih, 4, 1, - (cell_t)((colormap[i] >> 16) & 0xff), - (cell_t)((colormap[i] >> 8) & 0xff), - (cell_t)((colormap[i] >> 0) & 0xff), + (cell_t)((sc->sc_colormap[i] >> 16) & 0xff), + (cell_t)((sc->sc_colormap[i] >> 8) & 0xff), + (cell_t)((sc->sc_colormap[i] >> 0) & 0xff), (cell_t)i, &retval); } + break; + + case 32: + /* + * We bypass the usual bus_space_() accessors here, mostly + * for performance reasons. In particular, we don't want + * any barrier operations that may be performed and handle + * endianness slightly different. Figure out the host-view + * endianness of the frame buffer. + */ + oldpix = bus_space_read_4(sc->sc_memt, sc->sc_addr, 0); + bus_space_write_4(sc->sc_memt, sc->sc_addr, 0, 0xff000000); + if (*(uint8_t *)(sc->sc_addr) == 0xff) + vt_generate_vga_palette(sc->sc_colormap, + COLOR_FORMAT_RGB, 255, 16, 255, 8, 255, 0); + else + vt_generate_vga_palette(sc->sc_colormap, + COLOR_FORMAT_RGB, 255, 0, 255, 8, 255, 16); + bus_space_write_4(sc->sc_memt, sc->sc_addr, 0, oldpix); + break; + + default: + panic("Unknown color space depth %d", sc->sc_depth); + break; } /* Clear the screen. */ @@ -258,11 +272,11 @@ ofwfb_init(struct vt_device *vd) * Grab the physical address of the framebuffer, and then map it * into our memory space. If the MMU is not yet up, it will be * remapped for us when relocation turns on. - * - * XXX We assume #address-cells is 1 at this point. */ if (OF_getproplen(node, "address") == sizeof(fb_phys)) { + /* XXX We assume #address-cells is 1 at this point. */ OF_getprop(node, "address", &fb_phys, sizeof(fb_phys)); + #if defined(__powerpc__) sc->sc_memt = &bs_be_tag; bus_space_map(sc->sc_memt, fb_phys, height * sc->sc_stride, From owner-svn-src-user@FreeBSD.ORG Thu Oct 17 13:28:57 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id E2C745A3; Thu, 17 Oct 2013 13:28:57 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id D182F2F7C; Thu, 17 Oct 2013 13:28:57 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9HDSvKE098419; Thu, 17 Oct 2013 13:28:57 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9HDSvlK098418; Thu, 17 Oct 2013 13:28:57 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310171328.r9HDSvlK098418@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Thu, 17 Oct 2013 13:28:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256685 - user/ae/inet6/sys/netinet X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2013 13:28:58 -0000 Author: ae Date: Thu Oct 17 13:28:57 2013 New Revision: 256685 URL: http://svnweb.freebsd.org/changeset/base/256685 Log: When connection has non zero scope zone id, use its link ifnet to determine maximum mtu. Modified: user/ae/inet6/sys/netinet/tcp_subr.c Modified: user/ae/inet6/sys/netinet/tcp_subr.c ============================================================================== --- user/ae/inet6/sys/netinet/tcp_subr.c Thu Oct 17 12:58:40 2013 (r256684) +++ user/ae/inet6/sys/netinet/tcp_subr.c Thu Oct 17 13:28:57 2013 (r256685) @@ -1828,21 +1828,26 @@ tcp_maxmtu6(struct in_conninfo *inc, str KASSERT(inc != NULL, ("tcp_maxmtu6 with NULL in_conninfo pointer")); - bzero(&sro6, sizeof(sro6)); - if (!IN6_IS_ADDR_UNSPECIFIED(&inc->inc6_faddr)) { + ifp = NULL; + if (inc->inc6_zoneid != 0) { + ifp = in6_getlinkifnet(inc->inc6_zoneid); + } else if (!IN6_IS_ADDR_UNSPECIFIED(&inc->inc6_faddr)) { + bzero(&sro6, sizeof(sro6)); sro6.ro_dst.sin6_family = AF_INET6; sro6.ro_dst.sin6_len = sizeof(struct sockaddr_in6); sro6.ro_dst.sin6_addr = inc->inc6_faddr; in6_rtalloc_ign(&sro6, 0, inc->inc_fibnum); + if (sro6.ro_rt != NULL) { + ifp = sro6.ro_rt->rt_ifp; + maxmtu = sro6.ro_rt->rt_rmx.rmx_mtu; + RTFREE(sro6.ro_rt); + } } - if (sro6.ro_rt != NULL) { - ifp = sro6.ro_rt->rt_ifp; - if (sro6.ro_rt->rt_rmx.rmx_mtu == 0) - maxmtu = IN6_LINKMTU(sro6.ro_rt->rt_ifp); + if (ifp != NULL) { + if (maxmtu != 0) + maxmtu = min(maxmtu, IN6_LINKMTU(ifp)); else - maxmtu = min(sro6.ro_rt->rt_rmx.rmx_mtu, - IN6_LINKMTU(sro6.ro_rt->rt_ifp)); - + maxmtu = IN6_LINKMTU(ifp); /* Report additional interface capabilities. */ if (cap != NULL) { if (ifp->if_capenable & IFCAP_TSO6 && @@ -1850,7 +1855,6 @@ tcp_maxmtu6(struct in_conninfo *inc, str cap->ifcap |= CSUM_TSO; cap->tsomax = ifp->if_hw_tsomax; } - RTFREE(sro6.ro_rt); } return (maxmtu); From owner-svn-src-user@FreeBSD.ORG Thu Oct 17 14:20:45 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 84191FB5; Thu, 17 Oct 2013 14:20:45 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 70B382431; Thu, 17 Oct 2013 14:20:45 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9HEKj1a027862; Thu, 17 Oct 2013 14:20:45 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9HEKj76027859; Thu, 17 Oct 2013 14:20:45 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310171420.r9HEKj76027859@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Thu, 17 Oct 2013 14:20:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256688 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2013 14:20:45 -0000 Author: ae Date: Thu Oct 17 14:20:44 2013 New Revision: 256688 URL: http://svnweb.freebsd.org/changeset/base/256688 Log: Remove in6_setscope() from ni6_input() and use m_pulldown() instead of m_copydata(). Modified: user/ae/inet6/sys/netinet6/icmp6.c Modified: user/ae/inet6/sys/netinet6/icmp6.c ============================================================================== --- user/ae/inet6/sys/netinet6/icmp6.c Thu Oct 17 14:18:11 2013 (r256687) +++ user/ae/inet6/sys/netinet6/icmp6.c Thu Oct 17 14:20:44 2013 (r256688) @@ -1231,7 +1231,6 @@ ni6_input(struct mbuf *m, int off) struct ni_reply_fqdn *fqdn; int addrs; /* for NI_QTYPE_NODEADDR */ struct ifnet *ifp = NULL; /* for NI_QTYPE_NODEADDR */ - struct in6_addr in6_subj; /* subject address */ struct ip6_hdr *ip6; int oldfqdn = 0; /* if 1, return pascal string (03 draft) */ char *subj = NULL; @@ -1283,8 +1282,7 @@ ni6_input(struct mbuf *m, int off) in6_getscopezone(m->m_pkthdr.rcvif, in6_addrscope(&ip6->ip6_dst))); if (ia6 == NULL) - goto bad; /* XXX impossible */ - + goto bad; if ((ia6->ia6_flags & IN6_IFF_TEMPORARY) && !(V_icmp6_nodeinfo & ICMP6_NODEINFO_TMPADDROK)) { ifa_free(&ia6->ia_ifa); @@ -1345,14 +1343,10 @@ ni6_input(struct mbuf *m, int off) * * We do not do proxy at this moment. */ - /* m_pulldown instead of copy? */ - m_copydata(m, off + sizeof(struct icmp6_nodeinfo), - subjlen, (caddr_t)&in6_subj); - if (in6_setscope(&in6_subj, m->m_pkthdr.rcvif, NULL)) - goto bad; - - subj = (char *)&in6_subj; - if (IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst, &in6_subj)) + subj = (char *)m_pulldown(m, off + + sizeof(struct icmp6_nodeinfo), subjlen, NULL); + if (IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst, + (struct in6_addr *)subj)) break; /* From owner-svn-src-user@FreeBSD.ORG Thu Oct 17 17:44:58 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 13F83E3D; Thu, 17 Oct 2013 17:44:58 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 01A8624C2; Thu, 17 Oct 2013 17:44:58 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9HHiv9O035490; Thu, 17 Oct 2013 17:44:57 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9HHiv4R035489; Thu, 17 Oct 2013 17:44:57 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310171744.r9HHiv4R035489@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Thu, 17 Oct 2013 17:44:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256693 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2013 17:44:58 -0000 Author: ae Date: Thu Oct 17 17:44:57 2013 New Revision: 256693 URL: http://svnweb.freebsd.org/changeset/base/256693 Log: Remove in6_clearscope() and initialize sin6_scope_id instead of sa6_recoverscope() Modified: user/ae/inet6/sys/netinet6/icmp6.c Modified: user/ae/inet6/sys/netinet6/icmp6.c ============================================================================== --- user/ae/inet6/sys/netinet6/icmp6.c Thu Oct 17 17:25:00 2013 (r256692) +++ user/ae/inet6/sys/netinet6/icmp6.c Thu Oct 17 17:44:57 2013 (r256693) @@ -1910,7 +1910,6 @@ ni6_store_addrs(struct icmp6_nodeinfo *n /* copy the address itself */ bcopy(&ifa6->ia_addr.sin6_addr, cp, sizeof(struct in6_addr)); - in6_clearscope((struct in6_addr *)cp); /* XXX */ cp += sizeof(struct in6_addr); resid -= (sizeof(struct in6_addr) + sizeof(u_int32_t)); @@ -1957,20 +1956,12 @@ icmp6_rip6_input(struct mbuf **mp, int o return (IPPROTO_DONE); } #endif - - /* - * XXX: the address may have embedded scope zone ID, which should be - * hidden from applications. - */ bzero(&fromsa, sizeof(fromsa)); fromsa.sin6_family = AF_INET6; fromsa.sin6_len = sizeof(struct sockaddr_in6); fromsa.sin6_addr = ip6->ip6_src; - if (sa6_recoverscope(&fromsa)) { - m_freem(m); - return (IPPROTO_DONE); - } - + fromsa.sin6_scope_id = in6_getscopezone(m->m_pkthdr.rcvif, + in6_addrscope(&ip6->ip6_src)); INP_INFO_RLOCK(&V_ripcbinfo); LIST_FOREACH(in6p, &V_ripcb, inp_list) { if ((in6p->inp_vflag & INP_IPV6) == 0) From owner-svn-src-user@FreeBSD.ORG Thu Oct 17 19:24:11 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 10297245; Thu, 17 Oct 2013 19:24:11 +0000 (UTC) (envelope-from pho@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id F1CF72BB9; Thu, 17 Oct 2013 19:24:10 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9HJOA3u088164; Thu, 17 Oct 2013 19:24:10 GMT (envelope-from pho@svn.freebsd.org) Received: (from pho@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9HJOAdF088162; Thu, 17 Oct 2013 19:24:10 GMT (envelope-from pho@svn.freebsd.org) Message-Id: <201310171924.r9HJOAdF088162@svn.freebsd.org> From: Peter Holm Date: Thu, 17 Oct 2013 19:24:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256696 - user/pho/stress2/misc X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2013 19:24:11 -0000 Author: pho Date: Thu Oct 17 19:24:10 2013 New Revision: 256696 URL: http://svnweb.freebsd.org/changeset/base/256696 Log: Added two ptrace(2) regression tests. Sponsored by: EMC / Isilon storage division Added: user/pho/stress2/misc/ptrace.sh (contents, props changed) user/pho/stress2/misc/ptrace2.sh (contents, props changed) Added: user/pho/stress2/misc/ptrace.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/pho/stress2/misc/ptrace.sh Thu Oct 17 19:24:10 2013 (r256696) @@ -0,0 +1,106 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# + +# wait4(2) / ptrace(2) regression test. + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > ptrace.c +cc -o ptrace -Wall -Wextra -g ptrace.c || exit 1 +rm -f ptrace.c +cd $here + +/tmp/ptrace + +rm -f /tmp/ptrace +exit + +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void +test(void) +{ + pid_t pid, rpid; + struct rusage ru; + int status; + + if ((pid = fork()) == 0) { + usleep(2000); + _exit(64); + } + if (pid == -1) + err(1, "fork()"); + if (ptrace(PT_ATTACH, pid, NULL, 0) == -1) + err(1, "ptrace(%d) attach", pid); + if (wait(NULL) == -1) + err(1, "wait"); + bzero(&ru, sizeof(ru)); + usleep(2000); + if ((rpid = wait4(-1, &status, WNOHANG, &ru)) == -1) { + if (errno == ECHILD) + warn("FAIL"); + else + err(1, "wait4"); + } + if (rpid == 0) { +// fprintf(stderr, "No rusage info.\n"); + if (ptrace(PT_DETACH, pid, NULL, 0) == -1) + err(1, "ptrace(%d) detach", pid); + if (wait(&status) == -1) + err(1, "wait"); + } else { + fprintf(stderr, "FAIL Got unexpected rusage.\n"); + if (ru.ru_utime.tv_sec != 0) + fprintf(stderr, "FAIL tv_sec\n"); + } + if (status != 0x4000) + fprintf(stderr, "FAIL Child exit status 0x%x\n", status); + + _exit(0); +} + +int +main(void) +{ + test(); + + return (0); +} Added: user/pho/stress2/misc/ptrace2.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/pho/stress2/misc/ptrace2.sh Thu Oct 17 19:24:10 2013 (r256696) @@ -0,0 +1,142 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# + +# Regression test for kern/142757, race condition in traced process signal +# handling. Fixed in r202692. + +# Test scenario by Tijl Coosemans, tijl@ + +cd /tmp + +cat > race1.c < +#include +#include +#include +#include +#include + +int +main(void) +{ + pid_t pid; + int i, status; + + alarm(120); + /* fork dummy child process */ + pid = fork(); + if (pid == 0) { + /* child does nothing */ + for (;;) { + sleep(1); + } + } else { + /* parent */ + sleep(1); + for (i = 0; i < 100000; i++) { + /* loop: attach, wait, detach */ + printf("attach "); + fflush(stdout); + ptrace(PT_ATTACH, pid, (caddr_t) 0, 0); + + printf("wait "); + fflush(stdout); + wait4(pid, &status, 0, NULL); + + printf("detach "); + fflush(stdout); + ptrace(PT_DETACH, pid, (caddr_t) 1, 0); + + printf("ok\n"); + fflush(stdout); + } + } + + return (0); +} +EOF + +cat > race2.c < +#include +#include +#include +#include +#include + +int +main(void) +{ + pid_t pid; + int i, status; + + alarm(120); + /* fork dummy child process */ + pid = fork(); + if (pid == 0) { + /* child does nothing */ + for (;;) { + sleep(1); + } + } else { + /* parent */ + sleep(1); + ptrace(PT_ATTACH, pid, (caddr_t) 0, 0); + wait4(pid, &status, 0, NULL); + for (i = 0; i < 100000; i++) { + /* loop: continue, kill, wait */ + printf("continue "); + fflush(stdout); + ptrace(PT_CONTINUE, pid, (caddr_t) 1, 0); + + printf("kill "); + fflush(stdout); + kill(pid, SIGINT); + + printf("wait "); + fflush(stdout); + wait4(pid, &status, 0, NULL); + + printf("ok\n"); + fflush(stdout); + } + } + + return (0); +} +EOF + +cc -o race1 -Wall -Wextra race1.c +cc -o race2 -Wall -Wextra race2.c + +./race1 > /dev/null || echo "FAIL #1" +./race2 > /dev/null || echo "FAIL #2" + +rm -f race1.c race1 race2.c race2 From owner-svn-src-user@FreeBSD.ORG Thu Oct 17 19:56:51 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id E393633B; Thu, 17 Oct 2013 19:56:50 +0000 (UTC) (envelope-from andre@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id C22E42DFD; Thu, 17 Oct 2013 19:56:50 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9HJuovn006026; Thu, 17 Oct 2013 19:56:50 GMT (envelope-from andre@svn.freebsd.org) Received: (from andre@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9HJuopc006020; Thu, 17 Oct 2013 19:56:50 GMT (envelope-from andre@svn.freebsd.org) Message-Id: <201310171956.r9HJuopc006020@svn.freebsd.org> From: Andre Oppermann Date: Thu, 17 Oct 2013 19:56:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256697 - in user/andre/mbuf_staging: kern sys X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2013 19:56:51 -0000 Author: andre Date: Thu Oct 17 19:56:50 2013 New Revision: 256697 URL: http://svnweb.freebsd.org/changeset/base/256697 Log: Internalize struct mb_args from sys/mbuf.h into kern/kern_mbuf.c which is the only place where it used now. Be consequent and move m_last() to a real function as well. Move the MCHTYPE() macro and m_chtype() inline function together and decide later what to do with them. The warning in the comment doesn't seem to be true. Modified: user/andre/mbuf_staging/kern/kern_mbuf.c user/andre/mbuf_staging/sys/mbuf.h Modified: user/andre/mbuf_staging/kern/kern_mbuf.c ============================================================================== --- user/andre/mbuf_staging/kern/kern_mbuf.c Thu Oct 17 19:24:10 2013 (r256696) +++ user/andre/mbuf_staging/kern/kern_mbuf.c Thu Oct 17 19:56:50 2013 (r256697) @@ -300,6 +300,15 @@ static void mb_reclaim(void *); static void *mbuf_jumbo_alloc(uma_zone_t, int, uint8_t *, int); /* + * Argument structure passed to UMA routines during mbuf and packet + * allocations. + */ +struct mb_args { + int flags; /* Flags for mbuf being allocated */ + short type; /* Type of mbuf being allocated */ +}; + +/* * Initialize FreeBSD Network buffer allocation. */ static void Modified: user/andre/mbuf_staging/sys/mbuf.h ============================================================================== --- user/andre/mbuf_staging/sys/mbuf.h Thu Oct 17 19:24:10 2013 (r256696) +++ user/andre/mbuf_staging/sys/mbuf.h Thu Oct 17 19:56:50 2013 (r256697) @@ -75,15 +75,6 @@ */ #define mtod(m, t) ((t)((m)->m_data)) #define mtodo(m, o) ((void *)(((m)->m_data) + (o))) - -/* - * Argument structure passed to UMA routines during mbuf and packet - * allocations. - */ -struct mb_args { - int flags; /* Flags for mbuf being allocated */ - short type; /* Type of mbuf being allocated */ -}; #endif /* _KERNEL */ /* @@ -523,6 +514,14 @@ struct mbuf *m_get2(int, int, short, int struct mbuf *m_getjcl(int, short, int, int); struct mbuf *m_getm2(struct mbuf *, int, int, short, int); + + +/* + * Change mbuf to new type. This is a relatively expensive operation and + * should be avoided. + */ +#define MCHTYPE(m, t) m_chtype((m), (t)) + static __inline void m_chtype(struct mbuf *m, short new_type) { @@ -537,15 +536,6 @@ m_clrprotoflags(struct mbuf *m) m->m_flags &= ~M_PROTOFLAGS; } -static __inline struct mbuf * -m_last(struct mbuf *m) -{ - - while (m->m_next) - m = m->m_next; - return (m); -} - /* * mbuf, cluster, and external object allocation macros (for compatibility * purposes). @@ -613,12 +603,6 @@ int _m_trailingspace(const struct mbuf * */ #define M_PREPEND(m, plen, how) (m = m_prepend(m, plen, how)) -/* - * Change mbuf to new type. This is a relatively expensive operation and - * should be avoided. - */ -#define MCHTYPE(m, t) m_chtype((m), (t)) - /* Length to m_copy to copy all. */ #define M_COPYALL 1000000000 @@ -660,6 +644,7 @@ int m_dup_pkthdr(struct mbuf *, struct u_int m_fixhdr(struct mbuf *); struct mbuf *m_fragment(struct mbuf *, int, int); struct mbuf *m_getptr(struct mbuf *, int, int *); +struct mbuf *m_last(struct mbuf *); u_int m_length(struct mbuf *, struct mbuf **); int m_mbuftouio(struct uio *, struct mbuf *, int); void m_move_pkthdr(struct mbuf *, struct mbuf *); From owner-svn-src-user@FreeBSD.ORG Thu Oct 17 20:15:15 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 064D635E; Thu, 17 Oct 2013 20:15:15 +0000 (UTC) (envelope-from andre@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id E86392F77; Thu, 17 Oct 2013 20:15:14 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9HKFEaV016381; Thu, 17 Oct 2013 20:15:14 GMT (envelope-from andre@svn.freebsd.org) Received: (from andre@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9HKFEFZ016380; Thu, 17 Oct 2013 20:15:14 GMT (envelope-from andre@svn.freebsd.org) Message-Id: <201310172015.r9HKFEFZ016380@svn.freebsd.org> From: Andre Oppermann Date: Thu, 17 Oct 2013 20:15:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256704 - user/andre/mbuf_staging/kern X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2013 20:15:15 -0000 Author: andre Date: Thu Oct 17 20:15:14 2013 New Revision: 256704 URL: http://svnweb.freebsd.org/changeset/base/256704 Log: Actually move m_last() to kern/uipc_mbuf.c. Modified: user/andre/mbuf_staging/kern/uipc_mbuf.c Modified: user/andre/mbuf_staging/kern/uipc_mbuf.c ============================================================================== --- user/andre/mbuf_staging/kern/uipc_mbuf.c Thu Oct 17 20:14:47 2013 (r256703) +++ user/andre/mbuf_staging/kern/uipc_mbuf.c Thu Oct 17 20:15:14 2013 (r256704) @@ -1276,6 +1276,15 @@ m_length(struct mbuf *m0, struct mbuf ** return (len); } +struct mbuf * +m_last(struct mbuf *m) +{ + + while (m->m_next) + m = m->m_next; + return (m); +} + /* * Defragment a mbuf chain, returning the shortest possible * chain of mbufs and clusters. If allocation fails and From owner-svn-src-user@FreeBSD.ORG Fri Oct 18 09:07:12 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id E354CAA9; Fri, 18 Oct 2013 09:07:11 +0000 (UTC) (envelope-from andre@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id C1B2D2DC7; Fri, 18 Oct 2013 09:07:11 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9I97B0E027896; Fri, 18 Oct 2013 09:07:11 GMT (envelope-from andre@svn.freebsd.org) Received: (from andre@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9I97BWt027893; Fri, 18 Oct 2013 09:07:11 GMT (envelope-from andre@svn.freebsd.org) Message-Id: <201310180907.r9I97BWt027893@svn.freebsd.org> From: Andre Oppermann Date: Fri, 18 Oct 2013 09:07:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256723 - in user/andre/mbuf_staging: kern netipx sys X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Oct 2013 09:07:12 -0000 Author: andre Date: Fri Oct 18 09:07:10 2013 New Revision: 256723 URL: http://svnweb.freebsd.org/changeset/base/256723 Log: Change the only user of the MCHTYPE macro to the m_chtype() function. Remove the MCHTYPE macro. Move the m_chtype() inline function to kern/kern_mbuf.c. Properly sort m_extadd() prototype. Modified: user/andre/mbuf_staging/kern/kern_mbuf.c user/andre/mbuf_staging/netipx/spx_reass.c user/andre/mbuf_staging/sys/mbuf.h Modified: user/andre/mbuf_staging/kern/kern_mbuf.c ============================================================================== --- user/andre/mbuf_staging/kern/kern_mbuf.c Fri Oct 18 07:48:20 2013 (r256722) +++ user/andre/mbuf_staging/kern/kern_mbuf.c Fri Oct 18 09:07:10 2013 (r256723) @@ -998,6 +998,13 @@ m_getm2(struct mbuf *m, int len, int how return (m); } +void +m_chtype(struct mbuf *m, short new_type) +{ + + m->m_type = new_type; +} + struct mbuf * m_free(struct mbuf *m) { Modified: user/andre/mbuf_staging/netipx/spx_reass.c ============================================================================== --- user/andre/mbuf_staging/netipx/spx_reass.c Fri Oct 18 07:48:20 2013 (r256722) +++ user/andre/mbuf_staging/netipx/spx_reass.c Fri Oct 18 09:07:10 2013 (r256723) @@ -413,7 +413,7 @@ present: } } if (sp->spx_cc & SPX_OB) { - MCHTYPE(mqsi, MT_OOBDATA); + m_chtype(mqsi, MT_OOBDATA); spx_newchecks[1]++; so->so_oobmark = 0; so->so_rcv.sb_state &= ~SBS_RCVATMARK; Modified: user/andre/mbuf_staging/sys/mbuf.h ============================================================================== --- user/andre/mbuf_staging/sys/mbuf.h Fri Oct 18 07:48:20 2013 (r256722) +++ user/andre/mbuf_staging/sys/mbuf.h Fri Oct 18 09:07:10 2013 (r256723) @@ -514,21 +514,6 @@ struct mbuf *m_get2(int, int, short, int struct mbuf *m_getjcl(int, short, int, int); struct mbuf *m_getm2(struct mbuf *, int, int, short, int); - - -/* - * Change mbuf to new type. This is a relatively expensive operation and - * should be avoided. - */ -#define MCHTYPE(m, t) m_chtype((m), (t)) - -static __inline void -m_chtype(struct mbuf *m, short new_type) -{ - - m->m_type = new_type; -} - static __inline void m_clrprotoflags(struct mbuf *m) { @@ -623,9 +608,7 @@ int m_apply(struct mbuf *, int, int, int (*)(void *, void *, u_int), void *); int m_append(struct mbuf *, int, c_caddr_t); void m_cat(struct mbuf *, struct mbuf *); -int m_extadd(struct mbuf *, caddr_t, u_int, - int (*)(struct mbuf *, void *, void *), void *, void *, - int, int, int); +void m_chtype(struct mbuf *, short); struct mbuf *m_collapse(struct mbuf *, int, int); void m_copyback(struct mbuf *, int, int, c_caddr_t); void m_copydata(const struct mbuf *, int, int, caddr_t); @@ -641,6 +624,9 @@ struct mbuf *m_devget(char *, int, int, void (*)(char *, caddr_t, u_int)); struct mbuf *m_dup(struct mbuf *, int); int m_dup_pkthdr(struct mbuf *, struct mbuf *, int); +int m_extadd(struct mbuf *, caddr_t, u_int, + int (*)(struct mbuf *, void *, void *), void *, void *, + int, int, int); u_int m_fixhdr(struct mbuf *); struct mbuf *m_fragment(struct mbuf *, int, int); struct mbuf *m_getptr(struct mbuf *, int, int *); From owner-svn-src-user@FreeBSD.ORG Fri Oct 18 09:32:17 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 12FD690E; Fri, 18 Oct 2013 09:32:17 +0000 (UTC) (envelope-from pho@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 00D792F98; Fri, 18 Oct 2013 09:32:17 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9I9WGV8042146; Fri, 18 Oct 2013 09:32:16 GMT (envelope-from pho@svn.freebsd.org) Received: (from pho@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9I9WGW5042145; Fri, 18 Oct 2013 09:32:16 GMT (envelope-from pho@svn.freebsd.org) Message-Id: <201310180932.r9I9WGW5042145@svn.freebsd.org> From: Peter Holm Date: Fri, 18 Oct 2013 09:32:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256727 - user/pho/stress2/misc X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Oct 2013 09:32:17 -0000 Author: pho Date: Fri Oct 18 09:32:16 2013 New Revision: 256727 URL: http://svnweb.freebsd.org/changeset/base/256727 Log: Added regression test based on kern/150138. Sponsored by: EMC / Isilon storage division Added: user/pho/stress2/misc/signal.sh (contents, props changed) Added: user/pho/stress2/misc/signal.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/pho/stress2/misc/signal.sh Fri Oct 18 09:32:16 2013 (r256727) @@ -0,0 +1,223 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# + +# Regression test for kern/150138: signal sent to stopped, traced process +# not immediately handled on continue. +# Fixed in r212047. + +# Test scenario by Dan McNulty + +cat > waitthread.c < +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct threadArg { + int id; + pthread_mutex_t *mutex; +}; + +void *entry(void *arg) { + struct threadArg *thisArg = (struct threadArg *)arg; + + long lwp_id = thisArg->id; + if( syscall(SYS_thr_self, &lwp_id) ) { + perror("syscall"); + } + + printf("%ld waiting on lock\n", lwp_id); + + if( pthread_mutex_lock(thisArg->mutex) != 0 ) { + perror("pthread_mutex_lock"); + return NULL; + } + + printf("%ld obtained lock\n", lwp_id); + + if( pthread_mutex_unlock(thisArg->mutex) != 0 ) { + perror("pthread_mutex_unlock"); + return NULL; + } + + printf("%ld released lock\n", lwp_id); + + return NULL; +} + +int main(int argc, char **argv) { + if( 2 != argc ) { + printf("Usage: %s \n", argv[0]); + return EXIT_FAILURE; + } + + printf("%d\n", getpid()); + + int numThreads; + sscanf(argv[1], "%d", &numThreads); + if( numThreads < 1 ) numThreads = 1; + + pthread_t *threads = (pthread_t *)malloc(sizeof(pthread_t)*numThreads); + + pthread_mutex_t *mutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t)); + + if( pthread_mutex_init(mutex, NULL) != 0 ) { + perror("pthread_mutex_init"); + return EXIT_FAILURE; + } + + if( pthread_mutex_lock(mutex) != 0 ) { + perror("pthread_mutex_lock"); + return EXIT_FAILURE; + } + + int i; + for(i = 0; i < numThreads; ++i) { + struct threadArg *arg = (struct threadArg *)malloc(sizeof(struct threadArg)); + arg->id = i; + arg->mutex = mutex; + assert( !pthread_create(&threads[i], NULL, &entry, (void *)arg) ); + } + + // Wait on the named pipe + unlink("/tmp/waitthread"); + if( mkfifo("/tmp/waitthread", S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) ) { + perror("mkfifo"); + return EXIT_FAILURE; + } + + FILE *fifo; + do { + if( (fifo = fopen("/tmp/waitthread", "r")) == NULL ) { + if( errno == EINTR ) continue; + + perror("fopen"); + return EXIT_FAILURE; + } + break; + }while(1); + + unsigned char byte; + if( fread(&byte, sizeof(unsigned char), 1, fifo) != 1 ) { + perror("fread"); + } + + fclose(fifo); + + unlink("/tmp/waitthread"); + + printf("Received notification\n"); + + if( pthread_mutex_unlock(mutex) != 0 ) { + perror("pthread_mutex_unlock"); + return EXIT_FAILURE; + } + + printf("Unlocked mutex, joining\n"); + + for(i = 0; i < numThreads; ++i ) { + assert( !pthread_join(threads[i], NULL) ); + } + + return EXIT_SUCCESS; +} +EOF +cat > tkill.c < +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + if( argc != 4 ) { + printf("Usage: %s \n", argv[0]); + return EXIT_FAILURE; + } + + pid_t pid; + sscanf(argv[1], "%d", &pid); + + long id; + sscanf(argv[2], "%ld", &id); + + int sig; + sscanf(argv[3], "%d", &sig); + + if( syscall(SYS_thr_kill2, pid, id, sig) ) { + perror("syscall"); + } + + return EXIT_SUCCESS; +} +EOF +cc -o waitthread -Wall -Wextra waitthread.c -lpthread || exit +cc -o tkill -Wall -Wextra tkill.c || exit +rm -f waitthread.c tkill.c + +rm -f gdbfifo gdbout pstat +mkfifo gdbfifo +sleep 300 > gdbfifo & # Keep the fifo open +fifopid=$! + +gdb ./waitthread < gdbfifo > gdbout 2>&1 & +echo "set args 8" > gdbfifo +echo "run" > gdbfifo +sleep .2 + +pid=`ps | grep -v grep | grep "waitthread 8" | sed 's/ .*//'` +procstat -t $pid > pstat + +t1=`grep fifo pstat | awk '{print $2}'` +t2=`grep umtxn pstat | awk '{print $2}' | tail -1` + +./tkill $pid $t1 5 # SIGTRAP +./tkill $pid $t2 2 # SIGINT + +echo "c" > gdbfifo +echo "quit" > gdbfifo + +kill $fifopid + +if grep -q "signal SIGINT" gdbout; then + rm -f gdbfifo gdbout pstat waitthread tkill +else + echo FAIL +fi From owner-svn-src-user@FreeBSD.ORG Fri Oct 18 11:51:37 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 3AA3C349; Fri, 18 Oct 2013 11:51:37 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 0EADE29B3; Fri, 18 Oct 2013 11:51:37 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9IBpahF015964; Fri, 18 Oct 2013 11:51:36 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9IBpaOa015963; Fri, 18 Oct 2013 11:51:36 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310181151.r9IBpaOa015963@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Fri, 18 Oct 2013 11:51:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256731 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Oct 2013 11:51:37 -0000 Author: ae Date: Fri Oct 18 11:51:36 2013 New Revision: 256731 URL: http://svnweb.freebsd.org/changeset/base/256731 Log: Scope related cleanup in icmp6_redirect_input() * Don't use in6_setscope(). We don't embed scope zones, thus these checks are useless. * Move check for multicast dst. It can be checked earlier. * Fill sin6_scope_id before pfctlinput(). It used in the PCB code. Modified: user/ae/inet6/sys/netinet6/icmp6.c Modified: user/ae/inet6/sys/netinet6/icmp6.c ============================================================================== --- user/ae/inet6/sys/netinet6/icmp6.c Fri Oct 18 11:26:40 2013 (r256730) +++ user/ae/inet6/sys/netinet6/icmp6.c Fri Oct 18 11:51:36 2013 (r256731) @@ -2300,11 +2300,6 @@ icmp6_redirect_input(struct mbuf *m, int redtgt6 = nd_rd->nd_rd_target; reddst6 = nd_rd->nd_rd_dst; - if (in6_setscope(&redtgt6, m->m_pkthdr.rcvif, NULL) || - in6_setscope(&reddst6, m->m_pkthdr.rcvif, NULL)) { - goto freeit; - } - /* validation */ if (!IN6_IS_ADDR_LINKLOCAL(&src6)) { nd6log((LOG_ERR, @@ -2320,7 +2315,14 @@ icmp6_redirect_input(struct mbuf *m, int ip6_sprintf(ip6buf, &src6), ip6->ip6_hlim)); goto bad; } - { + if (IN6_IS_ADDR_MULTICAST(&reddst6)) { + nd6log((LOG_ERR, + "ICMP6 redirect rejected; " + "redirect dst must be unicast: %s\n", + icmp6_redirect_diag(&src6, &reddst6, &redtgt6))); + goto bad; + } + if (!IN6_IS_ADDR_LINKLOCAL(&reddst6)) { /* ip6->ip6_src must be equal to gw for icmp6->icmp6_reddst */ struct sockaddr_in6 sin6; struct in6_addr *gw6; @@ -2362,13 +2364,6 @@ icmp6_redirect_input(struct mbuf *m, int RTFREE_LOCKED(rt); rt = NULL; } - if (IN6_IS_ADDR_MULTICAST(&reddst6)) { - nd6log((LOG_ERR, - "ICMP6 redirect rejected; " - "redirect dst must be unicast: %s\n", - icmp6_redirect_diag(&src6, &reddst6, &redtgt6))); - goto bad; - } is_router = is_onlink = 0; if (IN6_IS_ADDR_LINKLOCAL(&redtgt6)) @@ -2441,6 +2436,7 @@ icmp6_redirect_input(struct mbuf *m, int sdst.sin6_family = AF_INET6; sdst.sin6_len = sizeof(struct sockaddr_in6); bcopy(&reddst6, &sdst.sin6_addr, sizeof(struct in6_addr)); + sdst.sin6_scope_id = in6_getscopezone(ifp, in6_addrscope(&reddst6)); pfctlinput(PRC_REDIRECT_HOST, (struct sockaddr *)&sdst); #ifdef IPSEC key_sa_routechange((struct sockaddr *)&sdst); From owner-svn-src-user@FreeBSD.ORG Fri Oct 18 12:08:43 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 1B551F7D; Fri, 18 Oct 2013 12:08:43 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 0929C2AFF; Fri, 18 Oct 2013 12:08:43 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9IC8gsS024703; Fri, 18 Oct 2013 12:08:42 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9IC8ggi024702; Fri, 18 Oct 2013 12:08:42 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310181208.r9IC8ggi024702@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Fri, 18 Oct 2013 12:08:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256732 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Oct 2013 12:08:43 -0000 Author: ae Date: Fri Oct 18 12:08:42 2013 New Revision: 256732 URL: http://svnweb.freebsd.org/changeset/base/256732 Log: Since we already know outgoing interface, pass it to ip6_output and use IPV6_USEROIF flag in icmp6_redirect_output. Also remove in6_clearscope calls. Modified: user/ae/inet6/sys/netinet6/icmp6.c Modified: user/ae/inet6/sys/netinet6/icmp6.c ============================================================================== --- user/ae/inet6/sys/netinet6/icmp6.c Fri Oct 18 11:51:36 2013 (r256731) +++ user/ae/inet6/sys/netinet6/icmp6.c Fri Oct 18 12:08:42 2013 (r256732) @@ -2466,7 +2466,6 @@ icmp6_redirect_output(struct mbuf *m0, s struct llentry *ln = NULL; size_t maxlen; u_char *p; - struct ifnet *outif = NULL; struct sockaddr_in6 src_sa; icmp6_errcount(ND_REDIRECT, 0); @@ -2704,15 +2703,7 @@ noredhdropt:; m_freem(m0); m0 = NULL; } - - /* XXX: clear embedded link IDs in the inner header */ - in6_clearscope(&sip6->ip6_src); - in6_clearscope(&sip6->ip6_dst); - in6_clearscope(&nd_rd->nd_rd_target); - in6_clearscope(&nd_rd->nd_rd_dst); - ip6->ip6_plen = htons(m->m_pkthdr.len - sizeof(struct ip6_hdr)); - nd_rd->nd_rd_cksum = 0; nd_rd->nd_rd_cksum = in6_cksum(m, IPPROTO_ICMPV6, sizeof(*ip6), ntohs(ip6->ip6_plen)); @@ -2727,13 +2718,11 @@ noredhdropt:; } /* send the packet to outside... */ - ip6_output(m, NULL, NULL, 0, NULL, &outif, NULL); - if (outif) { - icmp6_ifstat_inc(outif, ifs6_out_msg); - icmp6_ifstat_inc(outif, ifs6_out_redirect); + if (ip6_output(m, NULL, NULL, IPV6_USEROIF, NULL, &ifp, NULL) == 0) { + icmp6_ifstat_inc(ifp, ifs6_out_msg); + icmp6_ifstat_inc(ifp, ifs6_out_redirect); } ICMP6STAT_INC(icp6s_outhist[ND_REDIRECT]); - return; fail: From owner-svn-src-user@FreeBSD.ORG Fri Oct 18 12:24:25 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 17BB58C1; Fri, 18 Oct 2013 12:24:25 +0000 (UTC) (envelope-from andre@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 04A902C47; Fri, 18 Oct 2013 12:24:25 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9ICOO3K033076; Fri, 18 Oct 2013 12:24:24 GMT (envelope-from andre@svn.freebsd.org) Received: (from andre@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9ICOOae033075; Fri, 18 Oct 2013 12:24:24 GMT (envelope-from andre@svn.freebsd.org) Message-Id: <201310181224.r9ICOOae033075@svn.freebsd.org> From: Andre Oppermann Date: Fri, 18 Oct 2013 12:24:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256733 - user/andre/mbuf_staging/sys X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Oct 2013 12:24:25 -0000 Author: andre Date: Fri Oct 18 12:24:24 2013 New Revision: 256733 URL: http://svnweb.freebsd.org/changeset/base/256733 Log: Make mbuf.h more comprehensible to non-insiders by functionally grouping and sorting of macros and function definitions. Update and improve comments. Modified: user/andre/mbuf_staging/sys/mbuf.h Modified: user/andre/mbuf_staging/sys/mbuf.h ============================================================================== --- user/andre/mbuf_staging/sys/mbuf.h Fri Oct 18 12:08:42 2013 (r256732) +++ user/andre/mbuf_staging/sys/mbuf.h Fri Oct 18 12:24:24 2013 (r256733) @@ -42,6 +42,7 @@ #ifdef WITNESS #include #endif +struct uio; #endif /* @@ -459,14 +460,6 @@ struct mbuf { a non-initialized mbuf */ /* - * Compatibility with historic mbuf allocator. - */ -#define MBTOM(how) (how) -#define M_DONTWAIT M_NOWAIT -#define M_TRYWAIT M_WAITOK -#define M_WAIT M_WAITOK - -/* * String names of mbuf-related UMA(9) and malloc(9) types. Exposed to * !_KERNEL so that monitoring tools can look up the zones with * libmemstat(3). @@ -481,23 +474,16 @@ struct mbuf { #define MBUF_EXTREFCNT_MEM_NAME "mbuf_ext_refcnt" #ifdef _KERNEL - -#ifdef WITNESS -#define MBUF_CHECKSLEEP(how) do { \ - if (how == M_WAITOK) \ - WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, \ - "Sleeping in \"%s\"", __func__); \ -} while (0) -#else -#define MBUF_CHECKSLEEP(how) -#endif - /* - * Network buffer allocation API is defined in kern/kern_mbuf.c + * Mbuf network buffer allocation and construction functions API + * as implemented in kern/kern_mbuf.c. */ void mb_free_ext(struct mbuf *); int m_pkthdr_init(struct mbuf *, int); int m_gettype(int); +int m_extadd(struct mbuf *, caddr_t, u_int, + int (*)(struct mbuf *, void *, void *), void *, void *, + int, int, int); void m_extaddref(struct mbuf *, caddr_t, u_int, u_int *, int (*)(struct mbuf *, void *, void *), void *, void *); int m_init(struct mbuf *, int, int, short, int); @@ -513,44 +499,33 @@ void m_freem(struct mbuf *); struct mbuf *m_get2(int, int, short, int); struct mbuf *m_getjcl(int, short, int, int); struct mbuf *m_getm2(struct mbuf *, int, int, short, int); - -static __inline void -m_clrprotoflags(struct mbuf *m) -{ - - m->m_flags &= ~M_PROTOFLAGS; -} +struct mbuf *m_uiotombuf(struct uio *, int, int, int, int); /* - * mbuf, cluster, and external object allocation macros (for compatibility - * purposes). + * Allocator (and compatibility) macros. */ -#define M_MOVE_PKTHDR(to, from) m_move_pkthdr((to), (from)) #define MGET(m, how, type) ((m) = m_get((how), (type))) #define MGETHDR(m, how, type) ((m) = m_gethdr((how), (type))) #define MCLGET(m, how) m_clget((m), (how)) +#define m_getm(m, len, how, type) \ + m_getm2((m), (len), (how), (type), M_PKTHDR) #define MEXTADD(m, buf, size, free, arg1, arg2, flags, type) \ (void )m_extadd((m), (caddr_t)(buf), (size), (free), (arg1), (arg2),\ (flags), (type), M_NOWAIT) -#define m_getm(m, len, how, type) \ - m_getm2((m), (len), (how), (type), M_PKTHDR) +#define MBTOM(how) (how) +#define M_DONTWAIT M_NOWAIT +#define M_TRYWAIT M_WAITOK +#define M_WAIT M_WAITOK /* - * Evaluate TRUE if it's safe to write to the mbuf m's data region (this can - * be both the local data payload, or an external buffer area, depending on - * whether M_EXT is set). + * Assert that the supplied mbuf has a packet header, or else panic. */ -int _m_writable(const struct mbuf *); -#define M_WRITABLE(m) _m_writable(m) - -/* Check if the supplied mbuf has a packet header, or else panic. */ #define M_ASSERTPKTHDR(m) \ KASSERT((m) != NULL && (m)->m_flags & M_PKTHDR, \ ("%s: no mbuf packet header!", __func__)) /* - * Ensure that the supplied mbuf is a valid, non-free mbuf. - * + * Assert that the supplied mbuf is a valid, non-free mbuf. * XXX: Broken at the moment. Need some UMA magic to make it work again. */ #define M_ASSERTVALID(m) \ @@ -558,28 +533,49 @@ int _m_writable(const struct mbuf *); ("%s: attempted use of a free mbuf!", __func__)) /* + * Assert that the mbuf allocation attempt does not violate the + * sleeping rules. + */ +#ifdef WITNESS +#define MBUF_CHECKSLEEP(how) do { \ + if (how == M_WAITOK) \ + WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, \ + "Sleeping in \"%s\"", __func__); \ +} while (0) +#else +#define MBUF_CHECKSLEEP(how) +#endif + +/* + * Mbuf and data manipulation functions and macros: + * + * Evaluate TRUE if it's safe to write to the mbuf m's data region (this can + * be both the local data payload, or an external buffer area, depending on + * whether M_EXT is set). + */ +#define M_WRITABLE(m) _m_writable(m) + +/* * Set the m_data pointer of a newly-allocated mbuf (m_get/MGET) to place an - * object of the specified size at the end of the mbuf, longword aligned. - * As above, for mbufs allocated with m_gethdr/MGETHDR or initialized by - * M_DUP/MOVE_PKTHDR. - * As above, for mbuf with external storage. + * object of the specified size at the end of the mbuf of various types, + * longword aligned. */ #define M_ALIGN(m, len) m_align(m, len) #define MH_ALIGN(m, len) m_align(m, len) #define MEXT_ALIGN(m, len) m_align(m, len) /* - * Compute the amount of space available before the current start of data in - * an mbuf. + * Compute the amount of space available before or after the current start + * of data in an mbuf. */ -int _m_leadingspace(const struct mbuf *); #define M_LEADINGSPACE(m) _m_leadingspace(m) +#define M_TRAILINGSPACE(m) _m_trailingspace(m) /* - * Compute the amount of space available after the end of data in an mbuf. + * Move the mbuf packet header information from one mbuf to another one, + * including tags. */ -int _m_trailingspace(const struct mbuf *); -#define M_TRAILINGSPACE(m) _m_trailingspace(m) +#define M_MOVE_PKTHDR(to, from) m_move_pkthdr((to), (from)) /* * Arrange to prepend space of size plen to mbuf m. If a new mbuf must be @@ -588,19 +584,38 @@ int _m_trailingspace(const struct mbuf * */ #define M_PREPEND(m, plen, how) (m = m_prepend(m, plen, how)) -/* Length to m_copy to copy all. */ -#define M_COPYALL 1000000000 +/* + * Clear the protocol layer specific when passing a packet up or down the + * stack. + */ +static __inline void +m_clrprotoflags(struct mbuf *m) +{ -/* Compatibility with 4.3. */ -#define m_copy(m, o, l) m_copym((m), (o), (l), M_NOWAIT) + m->m_flags &= ~M_PROTOFLAGS; +} -extern int max_datalen; /* MHLEN - max_hdr */ -extern int max_hdr; /* Largest link + protocol header */ -extern int max_linkhdr; /* Largest link-level header */ -extern int max_protohdr; /* Largest protocol header */ -extern int nmbclusters; /* Maximum number of clusters */ +/* + * Accessor macros for getting and setting the associated FIB number of + * a packet. + */ +#define M_GETFIB(m) _m_getfib(m) +static __inline uint16_t +_m_getfib(const struct mbuf *m) +{ \ + KASSERT((m)->m_flags & M_PKTHDR, \ + ("%s: Attempt to get FIB from non header mbuf", __func__)); \ + return ((m)->m_pkthdr.fibnum); \ +} + +#define M_SETFIB(m, fib) do { \ + KASSERT((m)->m_flags & M_PKTHDR, \ + ("%s: Attempt to set FIB on non header mbuf", __func__)); \ + ((m)->m_pkthdr.fibnum) = (fib); \ +} while (0) -struct uio; +#define M_COPYALL 1000000000 /* Length to m_copy to copy all. */ +#define m_copy(m, o, l) m_copym((m), (o), (l), M_NOWAIT) /* compat with 4.3 */ void m_adj(struct mbuf *, int); void m_align(struct mbuf *, int); @@ -624,9 +639,6 @@ struct mbuf *m_devget(char *, int, int, void (*)(char *, caddr_t, u_int)); struct mbuf *m_dup(struct mbuf *, int); int m_dup_pkthdr(struct mbuf *, struct mbuf *, int); -int m_extadd(struct mbuf *, caddr_t, u_int, - int (*)(struct mbuf *, void *, void *), void *, void *, - int, int, int); u_int m_fixhdr(struct mbuf *); struct mbuf *m_fragment(struct mbuf *, int, int); struct mbuf *m_getptr(struct mbuf *, int, int *); @@ -640,9 +652,19 @@ struct mbuf *m_pulldown(struct mbuf *, i struct mbuf *m_pullup(struct mbuf *, int); int m_sanity(struct mbuf *, int); struct mbuf *m_split(struct mbuf *, int, int); -struct mbuf *m_uiotombuf(struct uio *, int, int, int, int); struct mbuf *m_unshare(struct mbuf *, int); +/* Only to be used through macros. */ +int _m_leadingspace(const struct mbuf *); +int _m_trailingspace(const struct mbuf *); +int _m_writable(const struct mbuf *); + +extern int max_datalen; /* MHLEN - max_hdr */ +extern int max_hdr; /* Largest link + protocol header */ +extern int max_linkhdr; /* Largest link-level header */ +extern int max_protohdr; /* Largest protocol header */ +extern int nmbclusters; /* Maximum number of clusters */ + /*- * Network packets may have annotations attached by affixing a list of * "packet tags" to the pkthdr structure. Packet tags are dynamically @@ -824,22 +846,6 @@ m_tag_find(struct mbuf *m, int type, str m_tag_locate(m, MTAG_ABI_COMPAT, type, start)); } -static int inline -rt_m_getfib(struct mbuf *m) -{ - KASSERT(m->m_flags & M_PKTHDR , ("Attempt to get FIB from non header mbuf.")); - return (m->m_pkthdr.fibnum); -} - -#define M_GETFIB(_m) rt_m_getfib(_m) - -#define M_SETFIB(_m, _fib) do { \ - KASSERT((_m)->m_flags & M_PKTHDR, ("Attempt to set FIB on non header mbuf.")); \ - ((_m)->m_pkthdr.fibnum) = (_fib); \ -} while (0) - -#endif /* _KERNEL */ - #ifdef MBUF_PROFILING void m_profile(struct mbuf *m); #define M_PROFILE(m) m_profile(m) @@ -847,5 +853,5 @@ rt_m_getfib(struct mbuf *m) #define M_PROFILE(m) #endif - +#endif /* _KERNEL */ #endif /* !_SYS_MBUF_H_ */ From owner-svn-src-user@FreeBSD.ORG Fri Oct 18 12:31:33 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 090F9D4A; Fri, 18 Oct 2013 12:31:33 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id EA2172CEE; Fri, 18 Oct 2013 12:31:32 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9ICVW3e037916; Fri, 18 Oct 2013 12:31:32 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9ICVWH5037915; Fri, 18 Oct 2013 12:31:32 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310181231.r9ICVWH5037915@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Fri, 18 Oct 2013 12:31:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256734 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Oct 2013 12:31:33 -0000 Author: ae Date: Fri Oct 18 12:31:32 2013 New Revision: 256734 URL: http://svnweb.freebsd.org/changeset/base/256734 Log: Refactor ip6_forward(): * for link-local destinations use recv interface as outgoing; * if outgoing and recv interfaces are different, check that packet doesn't leave the zone of source address; * remove in6_setscope() calls. Modified: user/ae/inet6/sys/netinet6/ip6_forward.c Modified: user/ae/inet6/sys/netinet6/ip6_forward.c ============================================================================== --- user/ae/inet6/sys/netinet6/ip6_forward.c Fri Oct 18 12:24:24 2013 (r256733) +++ user/ae/inet6/sys/netinet6/ip6_forward.c Fri Oct 18 12:31:32 2013 (r256734) @@ -98,9 +98,9 @@ ip6_forward(struct mbuf *m, int srcrt) struct route_in6 rin6; int error, type = 0, code = 0; struct mbuf *mcopy = NULL; - struct ifnet *origifp; /* maybe unnecessary */ - u_int32_t inzone, outzone; - struct in6_addr src_in6, dst_in6, odst; + struct ifnet *ifp, *origifp; /* maybe unnecessary */ + int srcscope, dstscope; + struct in6_addr odst; #ifdef IPSEC struct secpolicy *sp = NULL; int ipsecrt = 0; @@ -344,6 +344,7 @@ ip6_forward(struct mbuf *m, int srcrt) /* adjust pointer */ dst = (struct sockaddr_in6 *)state.dst; rt = state.ro ? state.ro->ro_rt : NULL; + ifp = rt ? rt->rt_ifp: NULL; if (dst != NULL && rt != NULL) ipsecrt = 1; } @@ -357,53 +358,65 @@ again: dst->sin6_len = sizeof(struct sockaddr_in6); dst->sin6_family = AF_INET6; dst->sin6_addr = ip6->ip6_dst; + dst->sin6_scope_id = in6_getscopezone(m->m_pkthdr.rcvif, + in6_addrscope(&ip6->ip6_dst)); again2: - rin6.ro_rt = in6_rtalloc1((struct sockaddr *)dst, 0, 0, M_GETFIB(m)); - if (rin6.ro_rt != NULL) - RT_UNLOCK(rin6.ro_rt); - else { - IP6STAT_INC(ip6s_noroute); - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_noroute); - if (mcopy) { - icmp6_error(mcopy, ICMP6_DST_UNREACH, - ICMP6_DST_UNREACH_NOROUTE, 0); + /* + * We don't need to do route lookup for link-local addresses. + */ + if (IN6_IS_ADDR_LINKLOCAL(&dst->sin6_addr)) { + /* + * If a router receives a packet with a link-local destination + * address that is not one of the router's own link-local + * addresses on the arrival link, the router is expected to + * try to forward the packet to the destination on that link. + * + * XXX: type = ND_REDIRECT; + */ + ifp = m->m_pkthdr.rcvif; + rt = NULL; + /* + * XXX: Should we do lla_lookup here? + */ + } else { + in6_rtalloc(&rin6, M_GETFIB(m)); + if (rin6.ro_rt == NULL) { + IP6STAT_INC(ip6s_noroute); + in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_noroute); + if (mcopy) + icmp6_error(mcopy, ICMP6_DST_UNREACH, + ICMP6_DST_UNREACH_NOROUTE, 0); + goto bad; } - goto bad; + ifp = rin6.ro_rt->rt_ifp; + rt = rin6.ro_rt; } - rt = rin6.ro_rt; #ifdef IPSEC skip_routing: #endif /* - * Source scope check: if a packet can't be delivered to its - * destination for the reason that the destination is beyond the scope - * of the source address, discard the packet and return an icmp6 - * destination unreachable error with Code 2 (beyond scope of source - * address). We use a local copy of ip6_src, since in6_setscope() - * will possibly modify its first argument. - * [draft-ietf-ipngwg-icmp-v3-04.txt, Section 3.1] - */ - src_in6 = ip6->ip6_src; - if (in6_setscope(&src_in6, rt->rt_ifp, &outzone)) { - /* XXX: this should not happen */ - IP6STAT_INC(ip6s_cantforward); - IP6STAT_INC(ip6s_badscope); - goto bad; - } - if (in6_setscope(&src_in6, m->m_pkthdr.rcvif, &inzone)) { - IP6STAT_INC(ip6s_cantforward); - IP6STAT_INC(ip6s_badscope); - goto bad; - } - if (inzone != outzone + * RFC 4007: + * If transmitting the packet on the chosen next-hop interface + * would cause the packet to leave the zone of the source address, + * i.e., cross a zone boundary of the scope of the source address, + * then the packet is discarded. Additionally, if the packet's + * destination address is a unicast address, an ICMP destination + * Unreachable message with Code 2 ("beyond scope of source address") + * is sent to the source of the original packet. + */ + srcscope = in6_addrscope(&ip6->ip6_src); + dstscope = in6_addrscope(&ip6->ip6_dst); + if (m->m_pkthdr.rcvif != ifp && + in6_getscopezone(m->m_pkthdr.rcvif, srcscope) != + in6_getscopezone(ifp, dstscope) #ifdef IPSEC && !ipsecrt #endif ) { IP6STAT_INC(ip6s_cantforward); IP6STAT_INC(ip6s_badscope); - in6_ifstat_inc(rt->rt_ifp, ifs6_in_discard); + in6_ifstat_inc(ifp, ifs6_in_discard); if (V_ip6_log_time + V_ip6_log_interval < time_uptime) { V_ip6_log_time = time_uptime; @@ -413,7 +426,7 @@ skip_routing: ip6_sprintf(ip6bufs, &ip6->ip6_src), ip6_sprintf(ip6bufd, &ip6->ip6_dst), ip6->ip6_nxt, - if_name(m->m_pkthdr.rcvif), if_name(rt->rt_ifp)); + if_name(m->m_pkthdr.rcvif), if_name(ifp)); } if (mcopy) icmp6_error(mcopy, ICMP6_DST_UNREACH, @@ -421,24 +434,8 @@ skip_routing: goto bad; } - /* - * Destination scope check: if a packet is going to break the scope - * zone of packet's destination address, discard it. This case should - * usually be prevented by appropriately-configured routing table, but - * we need an explicit check because we may mistakenly forward the - * packet to a different zone by (e.g.) a default route. - */ - dst_in6 = ip6->ip6_dst; - if (in6_setscope(&dst_in6, m->m_pkthdr.rcvif, &inzone) != 0 || - in6_setscope(&dst_in6, rt->rt_ifp, &outzone) != 0 || - inzone != outzone) { - IP6STAT_INC(ip6s_cantforward); - IP6STAT_INC(ip6s_badscope); - goto bad; - } - - if (m->m_pkthdr.len > IN6_LINKMTU(rt->rt_ifp)) { - in6_ifstat_inc(rt->rt_ifp, ifs6_in_toobig); + if (m->m_pkthdr.len > IN6_LINKMTU(ifp)) { + in6_ifstat_inc(ifp, ifs6_in_toobig); if (mcopy) { u_long mtu; #ifdef IPSEC @@ -447,7 +444,7 @@ skip_routing: size_t ipsechdrsiz; #endif /* IPSEC */ - mtu = IN6_LINKMTU(rt->rt_ifp); + mtu = IN6_LINKMTU(ifp); #ifdef IPSEC /* * When we do IPsec tunnel ingress, we need to play @@ -477,7 +474,7 @@ skip_routing: goto bad; } - if (rt->rt_flags & RTF_GATEWAY) + if (rt && (rt->rt_flags & RTF_GATEWAY)) dst = (struct sockaddr_in6 *)rt->rt_gateway; /* @@ -489,12 +486,13 @@ skip_routing: * Also, don't send redirect if forwarding using a route * modified by a redirect. */ - if (V_ip6_sendredirects && rt->rt_ifp == m->m_pkthdr.rcvif && !srcrt && + if (V_ip6_sendredirects && ifp == m->m_pkthdr.rcvif && !srcrt && #ifdef IPSEC !ipsecrt && #endif /* IPSEC */ - (rt->rt_flags & (RTF_DYNAMIC|RTF_MODIFIED)) == 0) { - if ((rt->rt_ifp->if_flags & IFF_POINTOPOINT) != 0) { + rin6.ro_rt && + (rin6.ro_rt->rt_flags & (RTF_DYNAMIC|RTF_MODIFIED)) == 0) { + if ((ifp->if_flags & IFF_POINTOPOINT) != 0) { /* * If the incoming interface is equal to the outgoing * one, and the link attached to the interface is @@ -506,7 +504,7 @@ skip_routing: * not sure if it is the best pick. */ icmp6_error(mcopy, ICMP6_DST_UNREACH, - ICMP6_DST_UNREACH_ADDR, 0); + ICMP6_DST_UNREACH_ADDR, 0); goto bad; } type = ND_REDIRECT; @@ -520,7 +518,7 @@ skip_routing: * link identifiers, we can do this stuff after making a copy for * returning an error. */ - if ((rt->rt_ifp->if_flags & IFF_LOOPBACK) != 0) { + if ((ifp->if_flags & IFF_LOOPBACK) != 0) { /* * See corresponding comments in ip6_output. * XXX: but is it possible that ip6_forward() sends a packet @@ -533,7 +531,8 @@ skip_routing: #if 1 if (0) #else - if ((rt->rt_flags & (RTF_BLACKHOLE|RTF_REJECT)) == 0) + if (rin6.ro_rt && + (rin6.ro_rt->rt_flags & (RTF_BLACKHOLE|RTF_REJECT)) == 0) #endif { printf("ip6_forward: outgoing interface is loopback. " @@ -541,20 +540,14 @@ skip_routing: ip6_sprintf(ip6bufs, &ip6->ip6_src), ip6_sprintf(ip6bufd, &ip6->ip6_dst), ip6->ip6_nxt, if_name(m->m_pkthdr.rcvif), - if_name(rt->rt_ifp)); + if_name(ifp)); } /* we can just use rcvif in forwarding. */ origifp = m->m_pkthdr.rcvif; } else - origifp = rt->rt_ifp; - /* - * clear embedded scope identifiers if necessary. - * in6_clearscope will touch the addresses only when necessary. - */ - in6_clearscope(&ip6->ip6_src); - in6_clearscope(&ip6->ip6_dst); + origifp = ifp; /* Jump over all PFIL processing if hooks are not active. */ if (!PFIL_HOOKED(&V_inet6_pfil_hook)) @@ -562,7 +555,7 @@ skip_routing: odst = ip6->ip6_dst; /* Run through list of hooks for output packets. */ - error = pfil_run_hooks(&V_inet6_pfil_hook, &m, rt->rt_ifp, PFIL_OUT, NULL); + error = pfil_run_hooks(&V_inet6_pfil_hook, &m, ifp, PFIL_OUT, NULL); if (error != 0) goto senderr; if (m == NULL) @@ -612,6 +605,11 @@ skip_routing: if ((m->m_flags & M_IP6_NEXTHOP) && (fwd_tag = m_tag_find(m, PACKET_TAG_IPFORWARD, NULL)) != NULL) { dst = (struct sockaddr_in6 *)&rin6.ro_dst; + if (rin6.ro_rt != NULL && ( + (rin6.ro_rt->rt_flags & RTF_UP) == 0 || + !IN6_ARE_ADDR_EQUAL(&dst->sin6_addr, + &((struct sockaddr_in6*)(fwd_tag + 1))->sin6_addr))) + RO_RTFREE(&rin6); bcopy((fwd_tag+1), dst, sizeof(struct sockaddr_in6)); m->m_flags |= M_SKIP_FIREWALL; m->m_flags &= ~M_IP6_NEXTHOP; @@ -620,13 +618,13 @@ skip_routing: } pass: - error = nd6_output(rt->rt_ifp, origifp, m, dst, NULL); + error = nd6_output(ifp, origifp, m, dst, NULL); if (error) { - in6_ifstat_inc(rt->rt_ifp, ifs6_out_discard); + in6_ifstat_inc(ifp, ifs6_out_discard); IP6STAT_INC(ip6s_cantforward); } else { IP6STAT_INC(ip6s_forward); - in6_ifstat_inc(rt->rt_ifp, ifs6_out_forward); + in6_ifstat_inc(ifp, ifs6_out_forward); if (type) IP6STAT_INC(ip6s_redirectsent); else { From owner-svn-src-user@FreeBSD.ORG Fri Oct 18 12:35:48 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 79D211FB; Fri, 18 Oct 2013 12:35:48 +0000 (UTC) (envelope-from andre@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 67C412D3F; Fri, 18 Oct 2013 12:35:48 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9ICZmku039651; Fri, 18 Oct 2013 12:35:48 GMT (envelope-from andre@svn.freebsd.org) Received: (from andre@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9ICZmZ9039646; Fri, 18 Oct 2013 12:35:48 GMT (envelope-from andre@svn.freebsd.org) Message-Id: <201310181235.r9ICZmZ9039646@svn.freebsd.org> From: Andre Oppermann Date: Fri, 18 Oct 2013 12:35:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256736 - in user/andre/mbuf_staging: kern sys X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Oct 2013 12:35:48 -0000 Author: andre Date: Fri Oct 18 12:35:47 2013 New Revision: 256736 URL: http://svnweb.freebsd.org/changeset/base/256736 Log: Internalize mb_free_ext() to kern/kern_mbuf.c. Remove m_gettype() prototype from sys/mbuf.h. Modified: user/andre/mbuf_staging/kern/kern_mbuf.c user/andre/mbuf_staging/sys/mbuf.h Modified: user/andre/mbuf_staging/kern/kern_mbuf.c ============================================================================== --- user/andre/mbuf_staging/kern/kern_mbuf.c Fri Oct 18 12:35:12 2013 (r256735) +++ user/andre/mbuf_staging/kern/kern_mbuf.c Fri Oct 18 12:35:47 2013 (r256736) @@ -297,6 +297,7 @@ static int mb_zinit_pack(void *, int, in static void mb_zfini_pack(void *, int); static void mb_reclaim(void *); +static void mb_free_ext(struct mbuf *) static void *mbuf_jumbo_alloc(uma_zone_t, int, uint8_t *, int); /* @@ -1105,7 +1106,7 @@ m_extaddref(struct mbuf *m, caddr_t buf, * Non-directly-exported function to clean up after mbufs with M_EXT * storage attached to them if the reference count hits 1. */ -void +static void mb_free_ext(struct mbuf *m) { int skipmbuf; Modified: user/andre/mbuf_staging/sys/mbuf.h ============================================================================== --- user/andre/mbuf_staging/sys/mbuf.h Fri Oct 18 12:35:12 2013 (r256735) +++ user/andre/mbuf_staging/sys/mbuf.h Fri Oct 18 12:35:47 2013 (r256736) @@ -478,9 +478,7 @@ struct mbuf { * Mbuf network buffer allocation and construction functions API * as implemented in kern/kern_mbuf.c. */ -void mb_free_ext(struct mbuf *); int m_pkthdr_init(struct mbuf *, int); -int m_gettype(int); int m_extadd(struct mbuf *, caddr_t, u_int, int (*)(struct mbuf *, void *, void *), void *, void *, int, int, int); From owner-svn-src-user@FreeBSD.ORG Fri Oct 18 12:51:28 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id E4EF9A80; Fri, 18 Oct 2013 12:51:28 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id D30CE2E6F; Fri, 18 Oct 2013 12:51:28 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9ICpS9T048202; Fri, 18 Oct 2013 12:51:28 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9ICpSjD048201; Fri, 18 Oct 2013 12:51:28 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310181251.r9ICpSjD048201@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Fri, 18 Oct 2013 12:51:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256737 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Oct 2013 12:51:29 -0000 Author: ae Date: Fri Oct 18 12:51:28 2013 New Revision: 256737 URL: http://svnweb.freebsd.org/changeset/base/256737 Log: Disable scope6 related ioctls. Modified: user/ae/inet6/sys/netinet6/in6.c Modified: user/ae/inet6/sys/netinet6/in6.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6.c Fri Oct 18 12:35:47 2013 (r256736) +++ user/ae/inet6/sys/netinet6/in6.c Fri Oct 18 12:51:28 2013 (r256737) @@ -360,6 +360,11 @@ in6_control(struct socket *so, u_long cm switch (cmd) { case SIOCSSCOPE6: + case SIOCGSCOPE6: + case SIOCGSCOPE6DEF: + return (EOPNOTSUPP); +#if 0 + case SIOCSSCOPE6: if (td != NULL) { error = priv_check(td, PRIV_NETINET_SCOPE6); if (error) @@ -373,6 +378,7 @@ in6_control(struct socket *so, u_long cm case SIOCGSCOPE6DEF: return (scope6_get_default((struct scope6_id *) ifr->ifr_ifru.ifru_scope_id)); +#endif } switch (cmd) { From owner-svn-src-user@FreeBSD.ORG Fri Oct 18 13:02:09 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id D2523EA8; Fri, 18 Oct 2013 13:02:09 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id A5D432F0A; Fri, 18 Oct 2013 13:02:09 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9ID29NZ054361; Fri, 18 Oct 2013 13:02:09 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9ID29Ud054360; Fri, 18 Oct 2013 13:02:09 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310181302.r9ID29Ud054360@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Fri, 18 Oct 2013 13:02:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256738 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Oct 2013 13:02:09 -0000 Author: ae Date: Fri Oct 18 13:02:09 2013 New Revision: 256738 URL: http://svnweb.freebsd.org/changeset/base/256738 Log: Scope related cleanup in in6_control(): * remove sa6_embedscope(), sa6_recoverscope() and in6_setscope() calls; * use sa6_checkzone() to check sockaddr_in6 structure. Before this check initialize sin6_scope_id if it is zero. We can do this, because we know interface and can use ifnet to determine zone id. Modified: user/ae/inet6/sys/netinet6/in6.c Modified: user/ae/inet6/sys/netinet6/in6.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6.c Fri Oct 18 12:51:28 2013 (r256737) +++ user/ae/inet6/sys/netinet6/in6.c Fri Oct 18 13:02:09 2013 (r256738) @@ -454,10 +454,10 @@ in6_control(struct socket *so, u_long cm break; } if (sa6 && sa6->sin6_family == AF_INET6) { - if (sa6->sin6_scope_id != 0) - error = sa6_embedscope(sa6, 0); - else - error = in6_setscope(&sa6->sin6_addr, ifp, NULL); + if (sa6->sin6_scope_id == 0) + sa6->sin6_scope_id = in6_getscopezone(ifp, + in6_addrscope(&sa6->sin6_addr)); + error = sa6_checkzone(sa6); if (error != 0) return (error); if (td != NULL && (error = prison_check_ip6(td->td_ucred, @@ -557,8 +557,6 @@ in6_control(struct socket *so, u_long cm switch (cmd) { case SIOCGIFADDR_IN6: ifr->ifr_addr = ia->ia_addr; - if ((error = sa6_recoverscope(&ifr->ifr_addr)) != 0) - goto out; break; case SIOCGIFDSTADDR_IN6: @@ -571,8 +569,6 @@ in6_control(struct socket *so, u_long cm * an error? */ ifr->ifr_dstaddr = ia->ia_dstaddr; - if ((error = sa6_recoverscope(&ifr->ifr_dstaddr)) != 0) - goto out; break; case SIOCGIFNETMASK_IN6: @@ -1818,26 +1814,11 @@ in6_lifaddr_ioctl(struct socket *so, u_l ia = ifa2ia6(ifa); if (cmd == SIOCGLIFADDR) { - int error; - /* fill in the if_laddrreq structure */ bcopy(&ia->ia_addr, &iflr->addr, ia->ia_addr.sin6_len); - error = sa6_recoverscope( - (struct sockaddr_in6 *)&iflr->addr); - if (error != 0) { - ifa_free(ifa); - return (error); - } - if ((ifp->if_flags & IFF_POINTOPOINT) != 0) { bcopy(&ia->ia_dstaddr, &iflr->dstaddr, ia->ia_dstaddr.sin6_len); - error = sa6_recoverscope( - (struct sockaddr_in6 *)&iflr->dstaddr); - if (error != 0) { - ifa_free(ifa); - return (error); - } } else bzero(&iflr->dstaddr, sizeof(iflr->dstaddr)); From owner-svn-src-user@FreeBSD.ORG Fri Oct 18 13:05:19 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 6272FBE; Fri, 18 Oct 2013 13:05:19 +0000 (UTC) (envelope-from andre@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4FFEA2F2C; Fri, 18 Oct 2013 13:05:19 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9ID5J6F055054; Fri, 18 Oct 2013 13:05:19 GMT (envelope-from andre@svn.freebsd.org) Received: (from andre@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9ID5JiS055053; Fri, 18 Oct 2013 13:05:19 GMT (envelope-from andre@svn.freebsd.org) Message-Id: <201310181305.r9ID5JiS055053@svn.freebsd.org> From: Andre Oppermann Date: Fri, 18 Oct 2013 13:05:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256739 - user/andre/mbuf_staging/kern X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Oct 2013 13:05:19 -0000 Author: andre Date: Fri Oct 18 13:05:18 2013 New Revision: 256739 URL: http://svnweb.freebsd.org/changeset/base/256739 Log: Add/update/improve comments. Convert M_EXT test in m_clget() to KASSERT. Modified: user/andre/mbuf_staging/kern/kern_mbuf.c Modified: user/andre/mbuf_staging/kern/kern_mbuf.c ============================================================================== --- user/andre/mbuf_staging/kern/kern_mbuf.c Fri Oct 18 13:02:09 2013 (r256738) +++ user/andre/mbuf_staging/kern/kern_mbuf.c Fri Oct 18 13:05:18 2013 (r256739) @@ -297,7 +297,7 @@ static int mb_zinit_pack(void *, int, in static void mb_zfini_pack(void *, int); static void mb_reclaim(void *); -static void mb_free_ext(struct mbuf *) +static void mb_free_ext(struct mbuf *); static void *mbuf_jumbo_alloc(uma_zone_t, int, uint8_t *, int); /* @@ -310,15 +310,13 @@ struct mb_args { }; /* - * Initialize FreeBSD Network buffer allocation. + * Initialize FreeBSD network buffer allocation and + * configure UMA zones for mbufs, clusters, and packets. */ static void mbuf_init(void *dummy) { - /* - * Configure UMA zones for Mbufs, Clusters, and Packets. - */ zone_mbuf = uma_zcreate(MBUF_MEM_NAME, MSIZE, mb_ctor_mbuf, mb_dtor_mbuf, #ifdef INVARIANTS @@ -660,6 +658,9 @@ mb_ctor_pack(void *mem, int size, void * return (error); } +/* + * Find the UMA zone based on the size of an cluster allocation. + */ static uma_zone_t m_getzone(int size) { @@ -689,14 +690,9 @@ m_getzone(int size) /* * Initialize an mbuf with linear storage. - * - * Inline because the consumer text overhead will be roughly the same to - * initialize or call a function with this many parameters and M_PKTHDR - * should go away with constant propagation for !MGETHDR. */ int -m_init(struct mbuf *m, int size, int how, short type, - int flags) +m_init(struct mbuf *m, int size, int how, short type, int flags) { int error; @@ -714,6 +710,9 @@ m_init(struct mbuf *m, int size, int how return (0); } +/* + * Initialize the mh_pkthdr of an mbuf. + */ int m_pkthdr_init(struct mbuf *m, int how) { @@ -745,6 +744,9 @@ m_pkthdr_init(struct mbuf *m, int how) return (0); } +/* + * Allocate a stand-alone mbuf. + */ struct mbuf * m_get(int how, short type) { @@ -756,7 +758,8 @@ m_get(int how, short type) } /* - * XXX This should be deprecated, very little use. + * Allocate a stand-alone mbuf with the data field zeroed. + * XXX: This should be deprecated, very little use. */ struct mbuf * m_getclr(int how, short type) @@ -772,6 +775,9 @@ m_getclr(int how, short type) return (m); } +/* + * Allocate a stand-alone packet header mbuf. + */ struct mbuf * m_gethdr(int how, short type) { @@ -782,6 +788,9 @@ m_gethdr(int how, short type) return (uma_zalloc_arg(zone_mbuf, &args, how)); } +/* + * Allocate an mbuf+cluster package. + */ struct mbuf * m_getcl(int how, short type, int flags) { @@ -822,12 +831,16 @@ m_getjcl(int how, short type, int flags, return (m); } +/* + * Allocate a 2K cluster and attach it to an mbuf. + */ void m_clget(struct mbuf *m, int how) { - if (m->m_flags & M_EXT) - printf("%s: %p mbuf already has cluster\n", __func__, m); + KASSERT((m->m_flags & M_EXT) == 0, + ("%s: %p mbuf already has cluster", __func__, m)); + m->m_ext.ext_buf = (char *)NULL; uma_zalloc_arg(zone_clust, m, how); /* @@ -861,6 +874,9 @@ m_cljget(struct mbuf *m, int how, int si return (uma_zalloc_arg(zone, m, how)); } +/* + * Attach a previously allocated cluster to an mbuf. + */ void m_cljset(struct mbuf *m, void *cl, int type) { @@ -902,7 +918,9 @@ m_cljset(struct mbuf *m, void *cl, int t } /* - * m_get2() allocates minimum mbuf that would fit "size" argument. + * m_get2() allocates the smallest single mbuf, with external storage if + * necessray, that fits "size" argument. Returns NULL if the requested + * size exceeds the largest available size. */ struct mbuf * m_get2(int size, int how, short type, int flags) @@ -999,6 +1017,9 @@ m_getm2(struct mbuf *m, int len, int how return (m); } +/* + * Change the type of an mbuf. + */ void m_chtype(struct mbuf *m, short new_type) { @@ -1006,6 +1027,10 @@ m_chtype(struct mbuf *m, short new_type) m->m_type = new_type; } +/* + * Free a single mbuf or an entire chain of mbufs and associated external + * buffers, if applicable. + */ struct mbuf * m_free(struct mbuf *m) { @@ -1020,10 +1045,6 @@ m_free(struct mbuf *m) return (n); } -/* - * Free an entire chain of mbufs and associated external buffers, if - * applicable. - */ void m_freem(struct mbuf *mb) { From owner-svn-src-user@FreeBSD.ORG Fri Oct 18 13:27:35 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id BFB6E830; Fri, 18 Oct 2013 13:27:35 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id AB3C520CA; Fri, 18 Oct 2013 13:27:35 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9IDRZ9i066793; Fri, 18 Oct 2013 13:27:35 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9IDRYKC066790; Fri, 18 Oct 2013 13:27:34 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310181327.r9IDRYKC066790@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Fri, 18 Oct 2013 13:27:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256740 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Oct 2013 13:27:35 -0000 Author: ae Date: Fri Oct 18 13:27:34 2013 New Revision: 256740 URL: http://svnweb.freebsd.org/changeset/base/256740 Log: Constify mcaddr argument in in6_joingroup() and rework in6_update_ifa_join_mc() function: * don't install routes for multicast addresses; * remove in6_setscope() calls; Modified: user/ae/inet6/sys/netinet6/in6.c user/ae/inet6/sys/netinet6/in6_mcast.c user/ae/inet6/sys/netinet6/in6_var.h Modified: user/ae/inet6/sys/netinet6/in6.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6.c Fri Oct 18 13:05:18 2013 (r256739) +++ user/ae/inet6/sys/netinet6/in6.c Fri Oct 18 13:27:34 2013 (r256740) @@ -852,27 +852,19 @@ in6_update_ifa_join_mc(struct ifnet *ifp struct in6_ifaddr *ia, int flags, struct in6_multi **in6m_sol) { char ip6buf[INET6_ADDRSTRLEN]; - struct sockaddr_in6 mltaddr, mltmask; - struct in6_addr llsol; + struct in6_addr mladdr; struct in6_multi_mship *imm; - struct rtentry *rt; int delay, error; KASSERT(in6m_sol != NULL, ("%s: in6m_sol is NULL", __func__)); /* Join solicited multicast addr for new host id. */ - bzero(&llsol, sizeof(struct in6_addr)); - llsol.s6_addr32[0] = IPV6_ADDR_INT32_MLL; - llsol.s6_addr32[1] = 0; - llsol.s6_addr32[2] = htonl(1); - llsol.s6_addr32[3] = ifra->ifra_addr.sin6_addr.s6_addr32[3]; - llsol.s6_addr8[12] = 0xff; - if ((error = in6_setscope(&llsol, ifp, NULL)) != 0) { - /* XXX: should not happen */ - log(LOG_ERR, "%s: in6_setscope failed\n", __func__); - goto cleanup; - } - delay = 0; + bzero(&mladdr, sizeof(struct in6_addr)); + mladdr.s6_addr32[0] = IPV6_ADDR_INT32_MLL; + mladdr.s6_addr32[2] = htonl(1); + mladdr.s6_addr32[3] = ifra->ifra_addr.sin6_addr.s6_addr32[3]; + mladdr.s6_addr8[12] = 0xff; + delay = error = 0; if ((flags & IN6_IFAUPDATE_DADDELAY)) { /* * We need a random delay for DAD on the address being @@ -882,64 +874,27 @@ in6_update_ifa_join_mc(struct ifnet *ifp */ delay = arc4random() % (MAX_RTR_SOLICITATION_DELAY * hz); } - imm = in6_joingroup(ifp, &llsol, &error, delay); + imm = in6_joingroup(ifp, &mladdr, &error, delay); if (imm == NULL) { nd6log((LOG_WARNING, "%s: addmulti failed for %s on %s " - "(errno=%d)\n", __func__, ip6_sprintf(ip6buf, &llsol), + "(errno=%d)\n", __func__, ip6_sprintf(ip6buf, &mladdr), if_name(ifp), error)); goto cleanup; } + /* XXX: locking */ LIST_INSERT_HEAD(&ia->ia6_memberships, imm, i6mm_chain); *in6m_sol = imm->i6mm_maddr; - - bzero(&mltmask, sizeof(mltmask)); - mltmask.sin6_len = sizeof(struct sockaddr_in6); - mltmask.sin6_family = AF_INET6; - mltmask.sin6_addr = in6mask32; -#define MLTMASK_LEN 4 /* mltmask's masklen (=32bit=4octet) */ - /* * Join link-local all-nodes address. */ - bzero(&mltaddr, sizeof(mltaddr)); - mltaddr.sin6_len = sizeof(struct sockaddr_in6); - mltaddr.sin6_family = AF_INET6; - mltaddr.sin6_addr = in6addr_linklocal_allnodes; - if ((error = in6_setscope(&mltaddr.sin6_addr, ifp, NULL)) != 0) - goto cleanup; /* XXX: should not fail */ - - /* - * XXX: do we really need this automatic routes? We should probably - * reconsider this stuff. Most applications actually do not need the - * routes, since they usually specify the outgoing interface. - */ - rt = in6_rtalloc1((struct sockaddr *)&mltaddr, 0, 0UL, RT_DEFAULT_FIB); - if (rt != NULL) { - /* XXX: only works in !SCOPEDROUTING case. */ - if (memcmp(&mltaddr.sin6_addr, - &((struct sockaddr_in6 *)rt_key(rt))->sin6_addr, - MLTMASK_LEN)) { - RTFREE_LOCKED(rt); - rt = NULL; - } - } - if (rt == NULL) { - error = in6_rtrequest(RTM_ADD, (struct sockaddr *)&mltaddr, - (struct sockaddr *)&ia->ia_addr, - (struct sockaddr *)&mltmask, RTF_UP, - (struct rtentry **)0, RT_DEFAULT_FIB); - if (error) - goto cleanup; - } else - RTFREE_LOCKED(rt); - - imm = in6_joingroup(ifp, &mltaddr.sin6_addr, &error, 0); + imm = in6_joingroup(ifp, &in6addr_linklocal_allnodes, &error, 0); if (imm == NULL) { nd6log((LOG_WARNING, "%s: addmulti failed for %s on %s " "(errno=%d)\n", __func__, ip6_sprintf(ip6buf, - &mltaddr.sin6_addr), if_name(ifp), error)); + &in6addr_linklocal_allnodes), if_name(ifp), error)); goto cleanup; } + /* XXX: locking */ LIST_INSERT_HEAD(&ia->ia6_memberships, imm, i6mm_chain); /* @@ -953,24 +908,24 @@ in6_update_ifa_join_mc(struct ifnet *ifp */ delay = arc4random() % (MAX_RTR_SOLICITATION_DELAY * hz); } - if (in6_nigroup(ifp, NULL, -1, &mltaddr.sin6_addr) == 0) { + if (in6_nigroup(ifp, NULL, -1, &mladdr) == 0) { /* XXX jinmei */ - imm = in6_joingroup(ifp, &mltaddr.sin6_addr, &error, delay); + imm = in6_joingroup(ifp, &mladdr, &error, delay); if (imm == NULL) nd6log((LOG_WARNING, "%s: addmulti failed for %s on %s " "(errno=%d)\n", __func__, ip6_sprintf(ip6buf, - &mltaddr.sin6_addr), if_name(ifp), error)); + &mladdr), if_name(ifp), error)); /* XXX not very fatal, go on... */ else LIST_INSERT_HEAD(&ia->ia6_memberships, imm, i6mm_chain); } if (V_icmp6_nodeinfo_oldmcprefix && - in6_nigroup_oldmcprefix(ifp, NULL, -1, &mltaddr.sin6_addr) == 0) { - imm = in6_joingroup(ifp, &mltaddr.sin6_addr, &error, delay); + in6_nigroup_oldmcprefix(ifp, NULL, -1, &mladdr) == 0) { + imm = in6_joingroup(ifp, &mladdr, &error, delay); if (imm == NULL) nd6log((LOG_WARNING, "%s: addmulti failed for %s on %s " "(errno=%d)\n", __func__, ip6_sprintf(ip6buf, - &mltaddr.sin6_addr), if_name(ifp), error)); + &mladdr), if_name(ifp), error)); /* XXX not very fatal, go on... */ else LIST_INSERT_HEAD(&ia->ia6_memberships, imm, i6mm_chain); @@ -980,38 +935,15 @@ in6_update_ifa_join_mc(struct ifnet *ifp * Join interface-local all-nodes address. * (ff01::1%ifN, and ff01::%ifN/32) */ - mltaddr.sin6_addr = in6addr_nodelocal_allnodes; - if ((error = in6_setscope(&mltaddr.sin6_addr, ifp, NULL)) != 0) - goto cleanup; /* XXX: should not fail */ - /* XXX: again, do we really need the route? */ - rt = in6_rtalloc1((struct sockaddr *)&mltaddr, 0, 0UL, RT_DEFAULT_FIB); - if (rt != NULL) { - if (memcmp(&mltaddr.sin6_addr, - &((struct sockaddr_in6 *)rt_key(rt))->sin6_addr, - MLTMASK_LEN)) { - RTFREE_LOCKED(rt); - rt = NULL; - } - } - if (rt == NULL) { - error = in6_rtrequest(RTM_ADD, (struct sockaddr *)&mltaddr, - (struct sockaddr *)&ia->ia_addr, - (struct sockaddr *)&mltmask, RTF_UP, - (struct rtentry **)0, RT_DEFAULT_FIB); - if (error) - goto cleanup; - } else - RTFREE_LOCKED(rt); - - imm = in6_joingroup(ifp, &mltaddr.sin6_addr, &error, 0); + imm = in6_joingroup(ifp, &in6addr_nodelocal_allnodes, &error, 0); if (imm == NULL) { nd6log((LOG_WARNING, "%s: addmulti failed for %s on %s " "(errno=%d)\n", __func__, ip6_sprintf(ip6buf, - &mltaddr.sin6_addr), if_name(ifp), error)); + &in6addr_nodelocal_allnodes), if_name(ifp), error)); goto cleanup; } + /* XXX: locking */ LIST_INSERT_HEAD(&ia->ia6_memberships, imm, i6mm_chain); -#undef MLTMASK_LEN cleanup: return (error); @@ -1349,135 +1281,17 @@ in6_update_ifa(struct ifnet *ifp, struct } /* - * Leave multicast groups. Factored out from in6_purgeaddr(). - * This entire work should only be done once, for the default FIB. + * Leave from multicast groups we have joined for the interface. */ static int in6_purgeaddr_mc(struct ifnet *ifp, struct in6_ifaddr *ia, struct ifaddr *ifa0) { - struct sockaddr_in6 mltaddr, mltmask; struct in6_multi_mship *imm; - struct rtentry *rt; - struct sockaddr_in6 sin6; - int error; - /* - * Leave from multicast groups we have joined for the interface. - */ while ((imm = LIST_FIRST(&ia->ia6_memberships)) != NULL) { LIST_REMOVE(imm, i6mm_chain); in6_leavegroup(imm); } - - /* - * Remove the link-local all-nodes address. - */ - bzero(&mltmask, sizeof(mltmask)); - mltmask.sin6_len = sizeof(struct sockaddr_in6); - mltmask.sin6_family = AF_INET6; - mltmask.sin6_addr = in6mask32; - - bzero(&mltaddr, sizeof(mltaddr)); - mltaddr.sin6_len = sizeof(struct sockaddr_in6); - mltaddr.sin6_family = AF_INET6; - mltaddr.sin6_addr = in6addr_linklocal_allnodes; - - if ((error = in6_setscope(&mltaddr.sin6_addr, ifp, NULL)) != 0) - return (error); - - /* - * As for the mltaddr above, proactively prepare the sin6 to avoid - * rtentry un- and re-locking. - */ - if (ifa0 != NULL) { - bzero(&sin6, sizeof(sin6)); - sin6.sin6_len = sizeof(sin6); - sin6.sin6_family = AF_INET6; - memcpy(&sin6.sin6_addr, &satosin6(ifa0->ifa_addr)->sin6_addr, - sizeof(sin6.sin6_addr)); - error = in6_setscope(&sin6.sin6_addr, ifa0->ifa_ifp, NULL); - if (error != 0) - return (error); - } - - rt = in6_rtalloc1((struct sockaddr *)&mltaddr, 0, 0UL, RT_DEFAULT_FIB); - if (rt != NULL && rt->rt_gateway != NULL && - (memcmp(&satosin6(rt->rt_gateway)->sin6_addr, - &ia->ia_addr.sin6_addr, - sizeof(ia->ia_addr.sin6_addr)) == 0)) { - /* - * If no more IPv6 address exists on this interface then - * remove the multicast address route. - */ - if (ifa0 == NULL) { - memcpy(&mltaddr.sin6_addr, - &satosin6(rt_key(rt))->sin6_addr, - sizeof(mltaddr.sin6_addr)); - RTFREE_LOCKED(rt); - error = in6_rtrequest(RTM_DELETE, - (struct sockaddr *)&mltaddr, - (struct sockaddr *)&ia->ia_addr, - (struct sockaddr *)&mltmask, RTF_UP, - (struct rtentry **)0, RT_DEFAULT_FIB); - if (error) - log(LOG_INFO, "%s: link-local all-nodes " - "multicast address deletion error\n", - __func__); - } else { - /* - * Replace the gateway of the route. - */ - memcpy(rt->rt_gateway, &sin6, sizeof(sin6)); - RTFREE_LOCKED(rt); - } - } else { - if (rt != NULL) - RTFREE_LOCKED(rt); - } - - /* - * Remove the node-local all-nodes address. - */ - mltaddr.sin6_addr = in6addr_nodelocal_allnodes; - if ((error = in6_setscope(&mltaddr.sin6_addr, ifp, NULL)) != 0) - return (error); - - rt = in6_rtalloc1((struct sockaddr *)&mltaddr, 0, 0UL, RT_DEFAULT_FIB); - if (rt != NULL && rt->rt_gateway != NULL && - (memcmp(&satosin6(rt->rt_gateway)->sin6_addr, - &ia->ia_addr.sin6_addr, - sizeof(ia->ia_addr.sin6_addr)) == 0)) { - /* - * If no more IPv6 address exists on this interface then - * remove the multicast address route. - */ - if (ifa0 == NULL) { - memcpy(&mltaddr.sin6_addr, - &satosin6(rt_key(rt))->sin6_addr, - sizeof(mltaddr.sin6_addr)); - - RTFREE_LOCKED(rt); - error = in6_rtrequest(RTM_DELETE, - (struct sockaddr *)&mltaddr, - (struct sockaddr *)&ia->ia_addr, - (struct sockaddr *)&mltmask, RTF_UP, - (struct rtentry **)0, RT_DEFAULT_FIB); - if (error) - log(LOG_INFO, "%s: node-local all-nodes" - "multicast address deletion error\n", - __func__); - } else { - /* - * Replace the gateway of the route. - */ - memcpy(rt->rt_gateway, &sin6, sizeof(sin6)); - RTFREE_LOCKED(rt); - } - } else { - if (rt != NULL) - RTFREE_LOCKED(rt); - } - return (0); } Modified: user/ae/inet6/sys/netinet6/in6_mcast.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6_mcast.c Fri Oct 18 13:05:18 2013 (r256739) +++ user/ae/inet6/sys/netinet6/in6_mcast.c Fri Oct 18 13:27:34 2013 (r256740) @@ -1080,7 +1080,7 @@ in6m_purge(struct in6_multi *inm) * SMPng: Assume no mc locks held by caller. */ struct in6_multi_mship * -in6_joingroup(struct ifnet *ifp, struct in6_addr *mcaddr, +in6_joingroup(struct ifnet *ifp, const struct in6_addr *mcaddr, int *errorp, int delay) { struct in6_multi_mship *imm; Modified: user/ae/inet6/sys/netinet6/in6_var.h ============================================================================== --- user/ae/inet6/sys/netinet6/in6_var.h Fri Oct 18 13:05:18 2013 (r256739) +++ user/ae/inet6/sys/netinet6/in6_var.h Fri Oct 18 13:27:34 2013 (r256740) @@ -793,7 +793,7 @@ int ip6_setmoptions(struct inpcb *, stru /* Legacy KAME multicast KPIs. */ struct in6_multi_mship * - in6_joingroup(struct ifnet *, struct in6_addr *, int *, int); + in6_joingroup(struct ifnet *, const struct in6_addr *, int *, int); int in6_leavegroup(struct in6_multi_mship *); /* flags to in6_update_ifa */ From owner-svn-src-user@FreeBSD.ORG Fri Oct 18 13:54:58 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id A78B83AD; Fri, 18 Oct 2013 13:54:58 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 9556622FB; Fri, 18 Oct 2013 13:54:58 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9IDswiu081706; Fri, 18 Oct 2013 13:54:58 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9IDswqp081705; Fri, 18 Oct 2013 13:54:58 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310181354.r9IDswqp081705@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Fri, 18 Oct 2013 13:54:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256741 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Oct 2013 13:54:58 -0000 Author: ae Date: Fri Oct 18 13:54:58 2013 New Revision: 256741 URL: http://svnweb.freebsd.org/changeset/base/256741 Log: Use in6_getscopezone() instead of in6_setscope() and sa6_embedscope(). Modified: user/ae/inet6/sys/netinet6/in6.c Modified: user/ae/inet6/sys/netinet6/in6.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6.c Fri Oct 18 13:27:34 2013 (r256740) +++ user/ae/inet6/sys/netinet6/in6.c Fri Oct 18 13:54:58 2013 (r256741) @@ -1010,25 +1010,11 @@ in6_update_ifa(struct ifnet *ifp, struct * zone identifier. */ dst6 = ifra->ifra_dstaddr; - if ((ifp->if_flags & (IFF_POINTOPOINT|IFF_LOOPBACK)) != 0 && - (dst6.sin6_family == AF_INET6)) { - struct in6_addr in6_tmp; - u_int32_t zoneid; - - in6_tmp = dst6.sin6_addr; - if (in6_setscope(&in6_tmp, ifp, &zoneid)) - return (EINVAL); /* XXX: should be impossible */ - - if (dst6.sin6_scope_id != 0) { - if (dst6.sin6_scope_id != zoneid) - return (EINVAL); - } else /* user omit to specify the ID. */ - dst6.sin6_scope_id = zoneid; - - /* convert into the internal form */ - if (sa6_embedscope(&dst6, 0)) - return (EINVAL); /* XXX: should be impossible */ - } + if ((ifp->if_flags & (IFF_POINTOPOINT | IFF_LOOPBACK)) != 0 && + dst6.sin6_family == AF_INET6 && dst6.sin6_scope_id != 0 && + dst6.sin6_scope_id != in6_getscopezone(ifp, + in6_addrscope(&dst6.sin6_addr))) + return (EINVAL); /* * The destination address can be specified only for a p2p or a * loopback interface. If specified, the corresponding prefix length From owner-svn-src-user@FreeBSD.ORG Fri Oct 18 14:43:04 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 1E38F3BD; Fri, 18 Oct 2013 14:43:04 +0000 (UTC) (envelope-from andre@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 0C5C1271F; Fri, 18 Oct 2013 14:43:04 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9IEh3aH008620; Fri, 18 Oct 2013 14:43:03 GMT (envelope-from andre@svn.freebsd.org) Received: (from andre@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9IEh3ld008619; Fri, 18 Oct 2013 14:43:03 GMT (envelope-from andre@svn.freebsd.org) Message-Id: <201310181443.r9IEh3ld008619@svn.freebsd.org> From: Andre Oppermann Date: Fri, 18 Oct 2013 14:43:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256742 - user/andre/mbuf_staging/kern X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Oct 2013 14:43:04 -0000 Author: andre Date: Fri Oct 18 14:43:03 2013 New Revision: 256742 URL: http://svnweb.freebsd.org/changeset/base/256742 Log: Add/update/improve comments. Wrap long lines. Remove unused variables and simplify logic. Convert/extend M_EXT KASSERT in m_cljget() and m_clget(). Modified: user/andre/mbuf_staging/kern/kern_mbuf.c Modified: user/andre/mbuf_staging/kern/kern_mbuf.c ============================================================================== --- user/andre/mbuf_staging/kern/kern_mbuf.c Fri Oct 18 13:54:58 2013 (r256741) +++ user/andre/mbuf_staging/kern/kern_mbuf.c Fri Oct 18 14:43:03 2013 (r256742) @@ -460,13 +460,12 @@ static void mb_dtor_mbuf(void *mem, int size, void *arg) { struct mbuf *m; - unsigned long flags; m = (struct mbuf *)mem; - flags = (unsigned long)arg; if ((m->m_flags & M_PKTHDR) && !SLIST_EMPTY(&m->m_pkthdr.tags)) m_tag_delete_chain(m, NULL); + KASSERT((m->m_flags & M_EXT) == 0, ("%s: M_EXT set", __func__)); KASSERT((m->m_flags & M_NOFREE) == 0, ("%s: M_NOFREE set", __func__)); #ifdef INVARIANTS @@ -492,8 +491,10 @@ mb_dtor_pack(void *mem, int size, void * KASSERT(m->m_ext.ext_free == NULL, ("%s: ext_free != NULL", __func__)); KASSERT(m->m_ext.ext_arg1 == NULL, ("%s: ext_arg1 != NULL", __func__)); KASSERT(m->m_ext.ext_arg2 == NULL, ("%s: ext_arg2 != NULL", __func__)); - KASSERT(m->m_ext.ext_size == MCLBYTES, ("%s: ext_size != MCLBYTES", __func__)); - KASSERT(m->m_ext.ext_type == EXT_PACKET, ("%s: ext_type != EXT_PACKET", __func__)); + KASSERT(m->m_ext.ext_size == MCLBYTES, + ("%s: ext_size != MCLBYTES", __func__)); + KASSERT(m->m_ext.ext_type == EXT_PACKET, + ("%s: ext_type != EXT_PACKET", __func__)); KASSERT(*m->m_ext.ref_cnt == 1, ("%s: ref_cnt != 1", __func__)); #ifdef INVARIANTS trash_dtor(m->m_ext.ext_buf, MCLBYTES, arg); @@ -580,11 +581,11 @@ mb_dtor_clust(void *mem, int size, void { #ifdef INVARIANTS uma_zone_t zone; + u_int refcnt; zone = m_getzone(size); - KASSERT(*(uma_find_refcnt(zone, mem)) <= 1, - ("%s: refcnt incorrect %u", __func__, - *(uma_find_refcnt(zone, mem))) ); + refcnt = *(uma_find_refcnt(zone, mem)); + KASSERT(refcnt <= 1, ("%s: refcnt incorrect %u", __func__, refcnt)); trash_dtor(mem, size, arg); #endif @@ -832,24 +833,28 @@ m_getjcl(int how, short type, int flags, } /* - * Allocate a 2K cluster and attach it to an mbuf. + * Allocate a 2K cluster and attach it to the supplied mbuf. + * The caller has to check for the M_EXT flag or m->m_ext.ext_buf + * to see if we were successful. */ void m_clget(struct mbuf *m, int how) { - KASSERT((m->m_flags & M_EXT) == 0, + KASSERT((m->m_flags & M_EXT) == 0 && m->m_ext.ext_buf == NULL, ("%s: %p mbuf already has cluster", __func__, m)); - m->m_ext.ext_buf = (char *)NULL; - uma_zalloc_arg(zone_clust, m, how); - /* - * On a cluster allocation failure, drain the packet zone and retry, - * we might be able to loosen a few clusters up on the drain. - */ - if ((how & M_NOWAIT) && (m->m_ext.ext_buf == NULL)) { - zone_drain(zone_pack); - uma_zalloc_arg(zone_clust, m, how); + if (uma_zalloc_arg(zone_clust, m, how) == NULL) { + /* + * On a cluster allocation failure, drain the packet zone + * and retry, we might be able to loosen a few clusters up + * on the drain. + */ + m->m_ext.ext_buf = NULL; + if (how & M_NOWAIT) { + zone_drain(zone_pack); + uma_zalloc_arg(zone_clust, m, how); + } } } @@ -865,8 +870,9 @@ m_cljget(struct mbuf *m, int how, int si { uma_zone_t zone; - if (m && m->m_flags & M_EXT) - printf("%s: %p mbuf already has cluster\n", __func__, m); + KASSERT(m == NULL || + ((m->m_flags & M_EXT) == 0 && m->m_ext.ext_buf == NULL), + ("%s: %p mbuf already has cluster", __func__, m)); if (m != NULL) m->m_ext.ext_buf = NULL; @@ -926,7 +932,7 @@ struct mbuf * m_get2(int size, int how, short type, int flags) { struct mb_args args; - struct mbuf *m, *n; + struct mbuf *m; args.flags = flags; args.type = type; @@ -939,12 +945,9 @@ m_get2(int size, int how, short type, in if (size > MJUMPAGESIZE) return (NULL); - m = uma_zalloc_arg(zone_mbuf, &args, how); - if (m == NULL) + if ((m = uma_zalloc_arg(zone_mbuf, &args, how)) == NULL) return (NULL); - - n = uma_zalloc_arg(zone_jumbop, m, how); - if (n == NULL) { + if (uma_zalloc_arg(zone_jumbop, m, how) == NULL) { uma_zfree(zone_mbuf, m); return (NULL); } @@ -1120,6 +1123,7 @@ m_extaddref(struct mbuf *m, caddr_t buf, m->m_ext.ext_free = freef; m->m_ext.ext_arg1 = arg1; m->m_ext.ext_arg2 = arg2; + m->m_ext.ext_flags = 0; m->m_ext.ext_type = EXT_EXTREF; }