4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 #include <sys/types.h>
27 #include <sys/t_lock.h>
28 #include <sys/param.h>
29 #include <sys/systm.h>
30 #include <sys/sysmacros.h>
31 #include <sys/cmn_err.h>
32 #include <sys/list.h>
33
34 #include <sys/stropts.h>
35 #include <sys/socket.h>
36 #include <sys/socketvar.h>
37
38 #include <fs/sockfs/sockcommon.h>
39 #include <fs/sockfs/sockfilter_impl.h>
40 #include <fs/sockfs/socktpi.h>
41
42 /*
43 * Socket Parameters
44 *
45 * Socket parameter (struct sockparams) entries represent the socket types
46 * available on the system.
47 *
48 * Flags (sp_flags):
49 *
50 * SOCKPARAMS_EPHEMERAL: A temporary sockparams entry that will be deleted
51 * as soon as its' ref count drops to zero. In addition, ephemeral entries will
52 * never be hooked onto the global sockparams list. Ephemeral entries are
806 sp = list_next(list, sp)) {
807 if ((err = sof_entry_proc_sockparams(ent, sp)) != 0) {
808 sockparams_filter_cleanup(ent);
809 return (err);
810 }
811 }
812 return (0);
813 }
814
815 int
816 sockparams_new_filter(sof_entry_t *ent)
817 {
818 int error;
819
820 if ((error = sockparams_new_filter_impl(ent, &sphead)) != 0)
821 return (error);
822
823 if ((error = sockparams_new_filter_impl(ent, &sp_ephem_list)) != 0)
824 sockparams_filter_cleanup_impl(ent, &sphead);
825 return (error);
826 }
|
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
25 */
26
27 #include <sys/types.h>
28 #include <sys/t_lock.h>
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/sysmacros.h>
32 #include <sys/cmn_err.h>
33 #include <sys/list.h>
34 #include <sys/sunddi.h>
35
36 #include <sys/stropts.h>
37 #include <sys/socket.h>
38 #include <sys/socketvar.h>
39
40 #include <fs/sockfs/sockcommon.h>
41 #include <fs/sockfs/sockfilter_impl.h>
42 #include <fs/sockfs/socktpi.h>
43
44 /*
45 * Socket Parameters
46 *
47 * Socket parameter (struct sockparams) entries represent the socket types
48 * available on the system.
49 *
50 * Flags (sp_flags):
51 *
52 * SOCKPARAMS_EPHEMERAL: A temporary sockparams entry that will be deleted
53 * as soon as its' ref count drops to zero. In addition, ephemeral entries will
54 * never be hooked onto the global sockparams list. Ephemeral entries are
808 sp = list_next(list, sp)) {
809 if ((err = sof_entry_proc_sockparams(ent, sp)) != 0) {
810 sockparams_filter_cleanup(ent);
811 return (err);
812 }
813 }
814 return (0);
815 }
816
817 int
818 sockparams_new_filter(sof_entry_t *ent)
819 {
820 int error;
821
822 if ((error = sockparams_new_filter_impl(ent, &sphead)) != 0)
823 return (error);
824
825 if ((error = sockparams_new_filter_impl(ent, &sp_ephem_list)) != 0)
826 sockparams_filter_cleanup_impl(ent, &sphead);
827 return (error);
828 }
829
830 /*
831 * Setup and return socket configuration table.
832 */
833 int
834 sockparams_copyout_socktable(uintptr_t socktable)
835 {
836 STRUCT_DECL(sockconfig_socktable, st);
837 struct sockparams *sp;
838 uint_t count;
839 uint_t i = 0;
840 int ret = 0;
841 sockconfig_socktable_entry_t *se;
842
843 STRUCT_INIT(st, get_udatamodel());
844 if (ddi_copyin((void *)socktable, STRUCT_BUF(st),
845 STRUCT_SIZE(st), 0) != 0)
846 return (EFAULT);
847
848 rw_enter(&sockconf_lock, RW_READER);
849
850 count = STRUCT_FGET(st, num_of_entries);
851 /*
852 * If the output buffer is size zero, just copy out the count.
853 */
854 if (count == 0) {
855 for (sp = list_head(&sphead); sp != NULL;
856 sp = list_next(&sphead, sp)) {
857 count++;
858 }
859 STRUCT_FSET(st, num_of_entries, count);
860
861 rw_exit(&sockconf_lock);
862 if (ddi_copyout(STRUCT_BUF(st), (void *)socktable,
863 STRUCT_SIZE(st), 0) != 0)
864 return (EFAULT);
865
866 return (0);
867 }
868
869 se = kmem_alloc(count * sizeof (sockconfig_socktable_entry_t),
870 KM_SLEEP);
871 for (sp = list_head(&sphead); sp != NULL;
872 sp = list_next(&sphead, sp)) {
873 if (i >= count) {
874 /*
875 * Return if the number of entries has changed.
876 */
877 rw_exit(&sockconf_lock);
878 kmem_free(se,
879 count * sizeof (sockconfig_socktable_entry_t));
880 return (EAGAIN);
881 }
882 se[i].se_family = sp->sp_family;
883 se[i].se_type = sp->sp_type;
884 se[i].se_protocol = sp->sp_protocol;
885 (void) strncpy(se[i].se_modname, sp->sp_smod_name,
886 MODMAXNAMELEN);
887 if (sp->sp_sdev_info.sd_devpath != NULL)
888 (void) strncpy(se[i].se_strdev,
889 sp->sp_sdev_info.sd_devpath, MAXPATHLEN);
890 se[i].se_refcnt = sp->sp_refcnt;
891 se[i].se_flags = sp->sp_flags;
892 i++;
893 }
894 rw_exit(&sockconf_lock);
895 if (ddi_copyout(se, STRUCT_FGETP(st, st_entries),
896 i * sizeof (sockconfig_socktable_entry_t), 0) != 0)
897 ret = EFAULT;
898
899 STRUCT_FSET(st, num_of_entries, i);
900 kmem_free(se, count * sizeof (sockconfig_socktable_entry_t));
901
902 if (ddi_copyout(STRUCT_BUF(st), (void *)socktable,
903 STRUCT_SIZE(st), 0) != 0)
904 ret = EFAULT;
905
906 return (ret);
907 }
|