17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5f4b3ec61Sdh155122 * Common Development and Distribution License (the "License").
6f4b3ec61Sdh155122 * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22bd670b35SErik Nordmark * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate #include <sys/types.h>
277c478bd9Sstevel@tonic-gate #include <sys/stream.h>
287c478bd9Sstevel@tonic-gate #include <sys/dlpi.h>
297c478bd9Sstevel@tonic-gate #include <sys/strsun.h>
307c478bd9Sstevel@tonic-gate #include <netinet/in.h>
317c478bd9Sstevel@tonic-gate #include <netinet/ip6.h>
327c478bd9Sstevel@tonic-gate #include <inet/common.h>
337c478bd9Sstevel@tonic-gate #include <inet/ip.h>
347c478bd9Sstevel@tonic-gate #include <inet/ip6.h>
357c478bd9Sstevel@tonic-gate #include <inet/ip_if.h>
367c478bd9Sstevel@tonic-gate #include <ipp/dlcosmk/dlcosmk_impl.h>
377c478bd9Sstevel@tonic-gate
387c478bd9Sstevel@tonic-gate /* Module to mark the 802.1d user priority field for a given packet */
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate /* Debug level */
417c478bd9Sstevel@tonic-gate int dlcosmk_debug = 0;
427c478bd9Sstevel@tonic-gate
437c478bd9Sstevel@tonic-gate /*
447c478bd9Sstevel@tonic-gate * Given a packet, this module marks the mblk with the appropriate b_band or
457c478bd9Sstevel@tonic-gate * dl_max value so that the VLAN driver marks the outgoing frame with the
467c478bd9Sstevel@tonic-gate * configured 802.1D user_priority value. For non-VLAN devices or for inbound
477c478bd9Sstevel@tonic-gate * packets, this module does not do anything (i.e. the packet is processed by
487c478bd9Sstevel@tonic-gate * the next action in the list, if present).
497c478bd9Sstevel@tonic-gate * This module does not free any mblks or packets in case or errors.
507c478bd9Sstevel@tonic-gate */
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate int
dlcosmk_process(mblk_t ** mpp,dlcosmk_data_t * dlcosmk_data,uint32_t ill_index,ip_proc_t proc)537c478bd9Sstevel@tonic-gate dlcosmk_process(mblk_t **mpp, dlcosmk_data_t *dlcosmk_data, uint32_t ill_index,
547c478bd9Sstevel@tonic-gate ip_proc_t proc)
557c478bd9Sstevel@tonic-gate {
567c478bd9Sstevel@tonic-gate ill_t *ill = NULL;
577c478bd9Sstevel@tonic-gate mblk_t *mp;
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate ASSERT((mpp != NULL) && (*mpp != NULL));
607c478bd9Sstevel@tonic-gate mp = *mpp;
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate * The action module will receive an M_DATA or an M_CTL followed
647c478bd9Sstevel@tonic-gate * by an M_DATA. In the latter case skip the M_CTL.
657c478bd9Sstevel@tonic-gate */
667c478bd9Sstevel@tonic-gate if (mp->b_datap->db_type != M_DATA) {
677c478bd9Sstevel@tonic-gate if ((mp->b_cont == NULL) ||
687c478bd9Sstevel@tonic-gate (mp->b_cont->b_datap->db_type != M_DATA)) {
69*1a5e258fSJosef 'Jeff' Sipek atomic_inc_64(&dlcosmk_data->epackets);
707c478bd9Sstevel@tonic-gate dlcosmk0dbg(("dlcosmk_process: no data\n"));
717c478bd9Sstevel@tonic-gate return (EINVAL);
727c478bd9Sstevel@tonic-gate }
737c478bd9Sstevel@tonic-gate }
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate /* Update global stats */
76*1a5e258fSJosef 'Jeff' Sipek atomic_inc_64(&dlcosmk_data->npackets);
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate /*
797c478bd9Sstevel@tonic-gate * This should only be called for outgoing packets. For inbound, just
807c478bd9Sstevel@tonic-gate * send it along.
817c478bd9Sstevel@tonic-gate */
827c478bd9Sstevel@tonic-gate if ((proc == IPP_LOCAL_IN) || (proc == IPP_FWD_IN)) {
837c478bd9Sstevel@tonic-gate dlcosmk2dbg(("dlcosmk_process:cannot mark incoming packets\n"));
84*1a5e258fSJosef 'Jeff' Sipek atomic_inc_64(&dlcosmk_data->ipackets);
857c478bd9Sstevel@tonic-gate return (0);
867c478bd9Sstevel@tonic-gate }
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate if ((ill_index == 0) ||
89bd670b35SErik Nordmark ((ill = ill_lookup_on_ifindex_global_instance(ill_index,
90bd670b35SErik Nordmark B_FALSE)) == NULL)) {
917c478bd9Sstevel@tonic-gate dlcosmk2dbg(("dlcosmk_process:invalid ill index %u\n",
927c478bd9Sstevel@tonic-gate ill_index));
93*1a5e258fSJosef 'Jeff' Sipek atomic_inc_64(&dlcosmk_data->ipackets);
947c478bd9Sstevel@tonic-gate return (0);
957c478bd9Sstevel@tonic-gate }
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate /*
987c478bd9Sstevel@tonic-gate * Check if the interface supports CoS marking. If not send it to the
997c478bd9Sstevel@tonic-gate * next action in the chain
1007c478bd9Sstevel@tonic-gate */
1017c478bd9Sstevel@tonic-gate if (!(ill->ill_flags & ILLF_COS_ENABLED)) {
1027c478bd9Sstevel@tonic-gate dlcosmk2dbg(("dlcosmk_process:ill %u does not support CoS\n",
1037c478bd9Sstevel@tonic-gate ill_index));
104*1a5e258fSJosef 'Jeff' Sipek atomic_inc_64(&dlcosmk_data->ipackets);
1057c478bd9Sstevel@tonic-gate ill_refrele(ill);
1067c478bd9Sstevel@tonic-gate return (0);
1077c478bd9Sstevel@tonic-gate }
1087c478bd9Sstevel@tonic-gate ill_refrele(ill);
1097c478bd9Sstevel@tonic-gate
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate /*
1127c478bd9Sstevel@tonic-gate * Mark the b_band for fastpath messages or dl_priority.dl_max for
1137c478bd9Sstevel@tonic-gate * DL_UNITDATA_REQ messages. For, others just pass it along.
1147c478bd9Sstevel@tonic-gate */
1157c478bd9Sstevel@tonic-gate switch (DB_TYPE(mp)) {
1167c478bd9Sstevel@tonic-gate case M_PROTO:
1177c478bd9Sstevel@tonic-gate case M_PCPROTO:
1187c478bd9Sstevel@tonic-gate { /* DL_UNITDATA */
1197c478bd9Sstevel@tonic-gate dl_unitdata_req_t *dlur;
1207c478bd9Sstevel@tonic-gate dlur = (dl_unitdata_req_t *)mp->b_rptr;
1217c478bd9Sstevel@tonic-gate
1227c478bd9Sstevel@tonic-gate /* DL_UNITDATA message?? */
1237c478bd9Sstevel@tonic-gate if (dlur->dl_primitive == DL_UNITDATA_REQ) {
1247c478bd9Sstevel@tonic-gate dlur->dl_priority.dl_max =
1257c478bd9Sstevel@tonic-gate dlcosmk_data->dl_max;
1267c478bd9Sstevel@tonic-gate } else {
127*1a5e258fSJosef 'Jeff' Sipek atomic_inc_64(&dlcosmk_data->ipackets);
1287c478bd9Sstevel@tonic-gate }
1297c478bd9Sstevel@tonic-gate break;
1307c478bd9Sstevel@tonic-gate }
1317c478bd9Sstevel@tonic-gate case M_DATA:
1327c478bd9Sstevel@tonic-gate /* fastpath message */
1337c478bd9Sstevel@tonic-gate mp->b_band = dlcosmk_data->b_band;
1347c478bd9Sstevel@tonic-gate break;
1357c478bd9Sstevel@tonic-gate default:
136*1a5e258fSJosef 'Jeff' Sipek atomic_inc_64(&dlcosmk_data->ipackets);
1377c478bd9Sstevel@tonic-gate break;
1387c478bd9Sstevel@tonic-gate }
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate return (0);
1417c478bd9Sstevel@tonic-gate }
142