xref: /onnv-gate/usr/src/uts/common/ipp/dlcosmk/dlcosmk.c (revision 11042:2d6e217af1b4)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
53448Sdh155122  * Common Development and Distribution License (the "License").
63448Sdh155122  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*11042SErik.Nordmark@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #include <sys/types.h>
270Sstevel@tonic-gate #include <sys/stream.h>
280Sstevel@tonic-gate #include <sys/dlpi.h>
290Sstevel@tonic-gate #include <sys/strsun.h>
300Sstevel@tonic-gate #include <netinet/in.h>
310Sstevel@tonic-gate #include <netinet/ip6.h>
320Sstevel@tonic-gate #include <inet/common.h>
330Sstevel@tonic-gate #include <inet/ip.h>
340Sstevel@tonic-gate #include <inet/ip6.h>
350Sstevel@tonic-gate #include <inet/ip_if.h>
360Sstevel@tonic-gate #include <ipp/dlcosmk/dlcosmk_impl.h>
370Sstevel@tonic-gate 
380Sstevel@tonic-gate /* Module to mark the 802.1d user priority field for a given packet */
390Sstevel@tonic-gate 
400Sstevel@tonic-gate /* Debug level */
410Sstevel@tonic-gate int dlcosmk_debug = 0;
420Sstevel@tonic-gate 
430Sstevel@tonic-gate /*
440Sstevel@tonic-gate  * Given a packet, this module marks the mblk with the appropriate b_band or
450Sstevel@tonic-gate  * dl_max value so that the VLAN driver marks the outgoing frame with the
460Sstevel@tonic-gate  * configured 802.1D user_priority value. For non-VLAN devices or for inbound
470Sstevel@tonic-gate  * packets, this module does not do anything (i.e. the packet is processed by
480Sstevel@tonic-gate  * the next action in the list, if present).
490Sstevel@tonic-gate  * This module does not free any mblks or packets in case or errors.
500Sstevel@tonic-gate  */
510Sstevel@tonic-gate 
520Sstevel@tonic-gate int
dlcosmk_process(mblk_t ** mpp,dlcosmk_data_t * dlcosmk_data,uint32_t ill_index,ip_proc_t proc)530Sstevel@tonic-gate dlcosmk_process(mblk_t **mpp, dlcosmk_data_t *dlcosmk_data, uint32_t ill_index,
540Sstevel@tonic-gate     ip_proc_t proc)
550Sstevel@tonic-gate {
560Sstevel@tonic-gate 	ill_t *ill = NULL;
570Sstevel@tonic-gate 	mblk_t *mp;
580Sstevel@tonic-gate 
590Sstevel@tonic-gate 	ASSERT((mpp != NULL) && (*mpp != NULL));
600Sstevel@tonic-gate 	mp = *mpp;
610Sstevel@tonic-gate 
620Sstevel@tonic-gate 	/*
630Sstevel@tonic-gate 	 * The action module will receive an M_DATA or an M_CTL followed
640Sstevel@tonic-gate 	 * by an M_DATA. In the latter case skip the M_CTL.
650Sstevel@tonic-gate 	 */
660Sstevel@tonic-gate 	if (mp->b_datap->db_type != M_DATA) {
670Sstevel@tonic-gate 		if ((mp->b_cont == NULL) ||
680Sstevel@tonic-gate 		    (mp->b_cont->b_datap->db_type != M_DATA)) {
690Sstevel@tonic-gate 			atomic_add_64(&dlcosmk_data->epackets, 1);
700Sstevel@tonic-gate 			dlcosmk0dbg(("dlcosmk_process: no data\n"));
710Sstevel@tonic-gate 			return (EINVAL);
720Sstevel@tonic-gate 		}
730Sstevel@tonic-gate 	}
740Sstevel@tonic-gate 
750Sstevel@tonic-gate 	/* Update global stats */
760Sstevel@tonic-gate 	atomic_add_64(&dlcosmk_data->npackets, 1);
770Sstevel@tonic-gate 
780Sstevel@tonic-gate 	/*
790Sstevel@tonic-gate 	 * This should only be called for outgoing packets. For inbound, just
800Sstevel@tonic-gate 	 * send it along.
810Sstevel@tonic-gate 	 */
820Sstevel@tonic-gate 	if ((proc == IPP_LOCAL_IN) || (proc == IPP_FWD_IN)) {
830Sstevel@tonic-gate 		dlcosmk2dbg(("dlcosmk_process:cannot mark incoming packets\n"));
840Sstevel@tonic-gate 		atomic_add_64(&dlcosmk_data->ipackets, 1);
850Sstevel@tonic-gate 		return (0);
860Sstevel@tonic-gate 	}
870Sstevel@tonic-gate 
880Sstevel@tonic-gate 	if ((ill_index == 0) ||
89*11042SErik.Nordmark@Sun.COM 	    ((ill = ill_lookup_on_ifindex_global_instance(ill_index,
90*11042SErik.Nordmark@Sun.COM 	    B_FALSE)) == NULL)) {
910Sstevel@tonic-gate 		dlcosmk2dbg(("dlcosmk_process:invalid ill index %u\n",
920Sstevel@tonic-gate 		    ill_index));
930Sstevel@tonic-gate 		atomic_add_64(&dlcosmk_data->ipackets, 1);
940Sstevel@tonic-gate 		return (0);
950Sstevel@tonic-gate 	}
960Sstevel@tonic-gate 
970Sstevel@tonic-gate 	/*
980Sstevel@tonic-gate 	 * Check if the interface supports CoS marking. If not send it to the
990Sstevel@tonic-gate 	 * next action in the chain
1000Sstevel@tonic-gate 	 */
1010Sstevel@tonic-gate 	if (!(ill->ill_flags & ILLF_COS_ENABLED)) {
1020Sstevel@tonic-gate 		dlcosmk2dbg(("dlcosmk_process:ill %u does not support CoS\n",
1030Sstevel@tonic-gate 		    ill_index));
1040Sstevel@tonic-gate 		atomic_add_64(&dlcosmk_data->ipackets, 1);
1050Sstevel@tonic-gate 		ill_refrele(ill);
1060Sstevel@tonic-gate 		return (0);
1070Sstevel@tonic-gate 	}
1080Sstevel@tonic-gate 	ill_refrele(ill);
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate 	/*
1120Sstevel@tonic-gate 	 * Mark the b_band for fastpath messages or dl_priority.dl_max for
1130Sstevel@tonic-gate 	 * DL_UNITDATA_REQ messages. For, others just pass it along.
1140Sstevel@tonic-gate 	 */
1150Sstevel@tonic-gate 	switch (DB_TYPE(mp)) {
1160Sstevel@tonic-gate 		case M_PROTO:
1170Sstevel@tonic-gate 		case M_PCPROTO:
1180Sstevel@tonic-gate 			{ 	/* DL_UNITDATA */
1190Sstevel@tonic-gate 				dl_unitdata_req_t *dlur;
1200Sstevel@tonic-gate 				dlur = (dl_unitdata_req_t *)mp->b_rptr;
1210Sstevel@tonic-gate 
1220Sstevel@tonic-gate 				/* DL_UNITDATA message?? */
1230Sstevel@tonic-gate 				if (dlur->dl_primitive == DL_UNITDATA_REQ) {
1240Sstevel@tonic-gate 					dlur->dl_priority.dl_max =
1250Sstevel@tonic-gate 					    dlcosmk_data->dl_max;
1260Sstevel@tonic-gate 				} else {
1270Sstevel@tonic-gate 					atomic_add_64(&dlcosmk_data->ipackets,
1280Sstevel@tonic-gate 					    1);
1290Sstevel@tonic-gate 				}
1300Sstevel@tonic-gate 				break;
1310Sstevel@tonic-gate 			}
1320Sstevel@tonic-gate 		case M_DATA:
1330Sstevel@tonic-gate 			/* fastpath message */
1340Sstevel@tonic-gate 			mp->b_band = dlcosmk_data->b_band;
1350Sstevel@tonic-gate 			break;
1360Sstevel@tonic-gate 		default:
1370Sstevel@tonic-gate 			atomic_add_64(&dlcosmk_data->ipackets, 1);
1380Sstevel@tonic-gate 			break;
1390Sstevel@tonic-gate 	}
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate 	return (0);
1420Sstevel@tonic-gate }
143