Changeset e10d1cd in rtems-libbsd
- Timestamp:
- 12/13/13 09:57:03 (10 years ago)
- Branches:
- 4.11, 5, 5-freebsd-12, 6-freebsd-12, freebsd-9.3, master
- Children:
- 06ad80c
- Parents:
- 1fea8c4
- git-author:
- Sebastian Huber <sebastian.huber@…> (12/13/13 09:57:03)
- git-committer:
- Sebastian Huber <sebastian.huber@…> (12/16/13 14:35:51)
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
freebsd/sys/net/bpf.c
r1fea8c4 re10d1cd 89 89 90 90 #include <security/mac/mac_framework.h> 91 #ifdef __rtems__ 92 #include <rtems/imfs.h> 93 #define devfs_get_cdevpriv(x) 0 94 #define devtoname(x) "bpf" 95 #endif /* __rtems__ */ 91 96 92 97 MALLOC_DEFINE(M_BPF, "BPF", "BPF data"); … … 174 179 SYSCTL_INT(_net_bpf, OID_AUTO, maxinsns, CTLFLAG_RW, 175 180 &bpf_maxinsns, 0, "Maximum bpf program instructions"); 181 #ifndef __rtems__ 176 182 static int bpf_zerocopy_enable = 0; 177 183 SYSCTL_INT(_net_bpf, OID_AUTO, zerocopy_enable, CTLFLAG_RW, 178 184 &bpf_zerocopy_enable, 0, "Enable new zero-copy BPF buffer sessions"); 185 #endif /* __rtems__ */ 179 186 static SYSCTL_NODE(_net_bpf, OID_AUTO, stats, CTLFLAG_MPSAFE | CTLFLAG_RW, 180 187 bpf_stats_sysctl, "bpf statistics portal"); … … 186 193 "Do not send packets until BPF program is set"); 187 194 195 #ifndef __rtems__ 188 196 static d_open_t bpfopen; 189 197 static d_read_t bpfread; … … 203 211 .d_kqfilter = bpfkqfilter, 204 212 }; 213 #endif /* __rtems__ */ 205 214 206 215 static struct filterops bpfread_filtops = { … … 257 266 return (bpf_buffer_append_bytes(d, buf, offset, src, len)); 258 267 268 #ifndef __rtems__ 259 269 case BPF_BUFMODE_ZBUF: 260 270 d->bd_zcopy++; 261 271 return (bpf_zerocopy_append_bytes(d, buf, offset, src, len)); 272 #endif /* __rtems__ */ 262 273 263 274 default: … … 277 288 return (bpf_buffer_append_mbuf(d, buf, offset, src, len)); 278 289 290 #ifndef __rtems__ 279 291 case BPF_BUFMODE_ZBUF: 280 292 d->bd_zcopy++; 281 293 return (bpf_zerocopy_append_mbuf(d, buf, offset, src, len)); 294 #endif /* __rtems__ */ 282 295 283 296 default: … … 299 312 return; 300 313 314 #ifndef __rtems__ 301 315 case BPF_BUFMODE_ZBUF: 302 316 bpf_zerocopy_buf_reclaimed(d); 303 317 return; 318 #endif /* __rtems__ */ 304 319 305 320 default: … … 319 334 BPFD_LOCK_ASSERT(d); 320 335 336 #ifndef __rtems__ 321 337 switch (d->bd_bufmode) { 322 338 case BPF_BUFMODE_ZBUF: 323 339 return (bpf_zerocopy_canfreebuf(d)); 324 340 } 341 #endif /* __rtems__ */ 325 342 return (0); 326 343 } … … 336 353 BPFD_LOCK_ASSERT(d); 337 354 355 #ifndef __rtems__ 338 356 switch (d->bd_bufmode) { 339 357 case BPF_BUFMODE_ZBUF: 340 358 return (bpf_zerocopy_canwritebuf(d)); 341 359 } 360 #endif /* __rtems__ */ 342 361 return (1); 343 362 } … … 354 373 BPFD_LOCK_ASSERT(d); 355 374 375 #ifndef __rtems__ 356 376 switch (d->bd_bufmode) { 357 377 case BPF_BUFMODE_ZBUF: … … 359 379 break; 360 380 } 381 #endif /* __rtems__ */ 361 382 } 362 383 … … 370 391 BPFD_LOCK_ASSERT(d); 371 392 393 #ifndef __rtems__ 372 394 switch (d->bd_bufmode) { 373 395 case BPF_BUFMODE_ZBUF: … … 375 397 break; 376 398 } 399 #endif /* __rtems__ */ 377 400 } 378 401 … … 385 408 return (bpf_buffer_free(d)); 386 409 410 #ifndef __rtems__ 387 411 case BPF_BUFMODE_ZBUF: 388 412 return (bpf_zerocopy_free(d)); 413 #endif /* __rtems__ */ 389 414 390 415 default: … … 415 440 { 416 441 442 #ifndef __rtems__ 417 443 if (d->bd_bufmode != BPF_BUFMODE_ZBUF) 418 444 return (EOPNOTSUPP); 419 445 return (bpf_zerocopy_ioctl_getzmax(td, d, i)); 446 #else /* __rtems__ */ 447 return (EOPNOTSUPP); 448 #endif /* __rtems__ */ 420 449 } 421 450 … … 424 453 { 425 454 455 #ifndef __rtems__ 426 456 if (d->bd_bufmode != BPF_BUFMODE_ZBUF) 427 457 return (EOPNOTSUPP); 428 458 return (bpf_zerocopy_ioctl_rotzbuf(td, d, bz)); 459 #else /* __rtems__ */ 460 return (EOPNOTSUPP); 461 #endif /* __rtems__ */ 429 462 } 430 463 … … 433 466 { 434 467 468 #ifndef __rtems__ 435 469 if (d->bd_bufmode != BPF_BUFMODE_ZBUF) 436 470 return (EOPNOTSUPP); 437 471 return (bpf_zerocopy_ioctl_setzbuf(td, d, bz)); 472 #else /* __rtems__ */ 473 return (EOPNOTSUPP); 474 #endif /* __rtems__ */ 438 475 } 439 476 … … 803 840 */ 804 841 /* ARGSUSED */ 842 #ifndef __rtems__ 805 843 static int 844 #else /* __rtems__ */ 845 static struct bpf_d * 846 #endif /* __rtems__ */ 806 847 bpfopen(struct cdev *dev, int flags, int fmt, struct thread *td) 807 848 { 808 849 struct bpf_d *d; 850 #ifndef __rtems__ 809 851 int error, size; 810 852 … … 815 857 return (error); 816 858 } 859 #else /* __rtems__ */ 860 u_int size; 861 862 d = malloc(sizeof(*d), M_BPF, M_NOWAIT | M_ZERO); 863 if (d == NULL) { 864 return (d); 865 } 866 #endif /* __rtems__ */ 817 867 818 868 /* … … 839 889 bpf_buffer_ioctl_sblen(d, &size); 840 890 891 #ifndef __rtems__ 841 892 return (0); 893 #else /* __rtems__ */ 894 return (d); 895 #endif /* __rtems__ */ 842 896 } 843 897 … … 846 900 */ 847 901 static int 902 #ifndef __rtems__ 848 903 bpfread(struct cdev *dev, struct uio *uio, int ioflag) 849 { 904 #else /* __rtems__ */ 905 bpfread(struct bpf_d *d, struct uio *uio, int ioflag) 906 #endif /* __rtems__ */ 907 { 908 #ifndef __rtems__ 850 909 struct bpf_d *d; 910 #endif /* __rtems__ */ 851 911 int error; 852 912 int non_block; … … 991 1051 } 992 1052 wakeup(d); 1053 #ifndef __rtems__ 993 1054 if (d->bd_async && d->bd_sig && d->bd_sigio) 994 1055 pgsigio(&d->bd_sigio, d->bd_sig, 0); 1056 #endif /* __rtems__ */ 995 1057 996 1058 selwakeuppri(&d->bd_sel, PRINET); … … 1029 1091 1030 1092 static int 1093 #ifndef __rtems__ 1031 1094 bpfwrite(struct cdev *dev, struct uio *uio, int ioflag) 1032 { 1095 #else /* __rtems__ */ 1096 bpfwrite(struct bpf_d *d, struct uio *uio, int ioflag) 1097 #endif /* __rtems__ */ 1098 { 1099 #ifndef __rtems__ 1033 1100 struct bpf_d *d; 1101 #endif /* __rtems__ */ 1034 1102 struct ifnet *ifp; 1035 1103 struct mbuf *m, *mc; … … 1181 1249 /* ARGSUSED */ 1182 1250 static int 1251 #ifndef __rtems__ 1183 1252 bpfioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flags, 1184 1253 struct thread *td) 1185 { 1254 #else /* __rtems__ */ 1255 bpfioctl(struct bpf_d *d, u_long cmd, caddr_t addr, int flags, 1256 struct thread *td) 1257 #endif /* __rtems__ */ 1258 { 1259 #ifndef __rtems__ 1186 1260 struct bpf_d *d; 1261 #endif /* __rtems__ */ 1187 1262 int error; 1188 1263 … … 1616 1691 break; 1617 1692 1693 #ifndef __rtems__ 1618 1694 case FIOASYNC: /* Send signal on receive packets */ 1619 1695 BPFD_LOCK(d); … … 1621 1697 BPFD_UNLOCK(d); 1622 1698 break; 1699 #endif /* __rtems__ */ 1623 1700 1624 1701 case FIOSETOWN: … … 1685 1762 break; 1686 1763 1764 #ifndef __rtems__ 1687 1765 case BPF_BUFMODE_ZBUF: 1688 1766 if (bpf_zerocopy_enable) 1689 1767 break; 1690 1768 /* FALLSTHROUGH */ 1769 #endif /* __rtems__ */ 1691 1770 1692 1771 default: … … 1886 1965 switch (d->bd_bufmode) { 1887 1966 case BPF_BUFMODE_BUFFER: 1967 #ifndef __rtems__ 1888 1968 case BPF_BUFMODE_ZBUF: 1969 #endif /* __rtems__ */ 1889 1970 if (d->bd_sbuf == NULL) 1890 1971 return (EINVAL); … … 1909 1990 */ 1910 1991 static int 1992 #ifndef __rtems__ 1911 1993 bpfpoll(struct cdev *dev, int events, struct thread *td) 1912 { 1994 #else /* __rtems__ */ 1995 bpfpoll(struct bpf_d *d, int events, struct thread *td) 1996 #endif /* __rtems__ */ 1997 { 1998 #ifndef __rtems__ 1913 1999 struct bpf_d *d; 2000 #endif /* __rtems__ */ 1914 2001 int revents; 1915 2002 … … 1945 2032 * reject all others. 1946 2033 */ 2034 #ifdef __rtems__ 2035 static 2036 #endif /* __rtems__ */ 1947 2037 int 2038 #ifndef __rtems__ 1948 2039 bpfkqfilter(struct cdev *dev, struct knote *kn) 1949 { 2040 #else /* __rtems__ */ 2041 bpfkqfilter(struct bpf_d *d, struct knote *kn) 2042 #endif /* __rtems__ */ 2043 { 2044 #ifndef __rtems__ 1950 2045 struct bpf_d *d; 2046 #endif /* __rtems__ */ 1951 2047 1952 2048 if (devfs_get_cdevpriv((void **)&d) != 0 || … … 2672 2768 return (bp == NULL ? EINVAL : 0); 2673 2769 } 2770 #ifdef __rtems__ 2771 static struct bpf_d * 2772 bpf_imfs_get_context_by_iop(const rtems_libio_t *iop) 2773 { 2774 return iop->data1; 2775 } 2776 2777 static int 2778 bpf_imfs_open(rtems_libio_t *iop, const char *path, int oflag, mode_t mode) 2779 { 2780 struct bpf_d *d; 2781 2782 d = bpfopen(NULL, 0, 0, NULL); 2783 iop->data1 = d; 2784 2785 if (d != NULL) { 2786 return (0); 2787 } else { 2788 rtems_set_errno_and_return_minus_one(ENOMEM); 2789 } 2790 } 2791 2792 static int 2793 bpf_imfs_close(rtems_libio_t *iop) 2794 { 2795 struct bpf_d *d = bpf_imfs_get_context_by_iop(iop); 2796 2797 bpf_dtor(d); 2798 2799 return (0); 2800 } 2801 2802 static ssize_t 2803 bpf_imfs_readv(rtems_libio_t *iop, const struct iovec *iov, int iovcnt, ssize_t total) 2804 { 2805 struct bpf_d *d = bpf_imfs_get_context_by_iop(iop); 2806 struct thread *td = rtems_bsd_get_curthread_or_null(); 2807 struct uio uio = { 2808 .uio_iov = iov, 2809 .uio_iovcnt = iovcnt, 2810 .uio_offset = 0, 2811 .uio_resid = total, 2812 .uio_segflg = UIO_USERSPACE, 2813 .uio_rw = UIO_READ, 2814 .uio_td = td 2815 }; 2816 int error; 2817 2818 if (td != NULL) { 2819 error = bpfread(d, &uio, 2820 rtems_libio_to_fcntl_flags(iop->flags)); 2821 } else { 2822 error = ENOMEM; 2823 } 2824 2825 if (error == 0) { 2826 return (total - uio.uio_resid); 2827 } else { 2828 rtems_set_errno_and_return_minus_one(error); 2829 } 2830 } 2831 2832 static ssize_t 2833 bpf_imfs_read(rtems_libio_t *iop, void *buffer, size_t count) 2834 { 2835 struct iovec iov = { 2836 .iov_base = buffer, 2837 .iov_len = count 2838 }; 2839 2840 return bpf_imfs_readv(iop, &iov, 1, count); 2841 } 2842 2843 static ssize_t 2844 bpf_imfs_writev(rtems_libio_t *iop, const struct iovec *iov, int iovcnt, ssize_t total) 2845 { 2846 struct bpf_d *d = bpf_imfs_get_context_by_iop(iop); 2847 struct thread *td = rtems_bsd_get_curthread_or_null(); 2848 struct uio uio = { 2849 .uio_iov = iov, 2850 .uio_iovcnt = iovcnt, 2851 .uio_offset = 0, 2852 .uio_resid = total, 2853 .uio_segflg = UIO_USERSPACE, 2854 .uio_rw = UIO_WRITE, 2855 .uio_td = td 2856 }; 2857 int error; 2858 2859 if (td != NULL) { 2860 error = bpfwrite(d, &uio, 2861 rtems_libio_to_fcntl_flags(iop->flags)); 2862 } else { 2863 error = ENOMEM; 2864 } 2865 2866 if (error == 0) { 2867 return (total - uio.uio_resid); 2868 } else { 2869 rtems_set_errno_and_return_minus_one(error); 2870 } 2871 } 2872 2873 static ssize_t 2874 bpf_imfs_write(rtems_libio_t *iop, const void *buffer, size_t count) 2875 { 2876 struct iovec iov = { 2877 .iov_base = buffer, 2878 .iov_len = count 2879 }; 2880 2881 return bpf_imfs_writev(iop, &iov, 1, count); 2882 } 2883 2884 static int 2885 bpf_imfs_ioctl(rtems_libio_t *iop, ioctl_command_t request, void *buffer) 2886 { 2887 struct bpf_d *d = bpf_imfs_get_context_by_iop(iop); 2888 struct thread *td = rtems_bsd_get_curthread_or_null(); 2889 int error; 2890 2891 if (td != 0) { 2892 error = bpfioctl(d, request, buffer, 0, td); 2893 } else { 2894 error = ENOMEM; 2895 } 2896 2897 return rtems_bsd_error_to_status_and_errno(error); 2898 } 2899 2900 static int 2901 bpf_imfs_poll(rtems_libio_t *iop, int events) 2902 { 2903 struct bpf_d *d = bpf_imfs_get_context_by_iop(iop); 2904 2905 return (bpfpoll(d, events, rtems_bsd_get_curthread_or_wait_forever())); 2906 } 2907 2908 static int 2909 bpf_imfs_kqfilter(rtems_libio_t *iop, struct knote *kn) 2910 { 2911 struct bpf_d *d = bpf_imfs_get_context_by_iop(iop); 2912 2913 return (bpfkqfilter(d, kn)); 2914 } 2915 2916 static const rtems_filesystem_file_handlers_r bpf_imfs_handlers = { 2917 .open_h = bpf_imfs_open, 2918 .close_h = bpf_imfs_close, 2919 .read_h = bpf_imfs_read, 2920 .write_h = bpf_imfs_write, 2921 .ioctl_h = bpf_imfs_ioctl, 2922 .lseek_h = rtems_filesystem_default_lseek_file, 2923 .fstat_h = rtems_filesystem_default_fstat, 2924 .ftruncate_h = rtems_filesystem_default_ftruncate, 2925 .fsync_h = rtems_filesystem_default_fsync_or_fdatasync, 2926 .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync, 2927 .fcntl_h = rtems_filesystem_default_fcntl, 2928 .poll_h = bpf_imfs_poll, 2929 .kqfilter_h = bpf_imfs_kqfilter, 2930 .readv_h = bpf_imfs_readv, 2931 .writev_h = bpf_imfs_writev 2932 }; 2933 2934 static const IMFS_node_control bpf_imfs_control = { 2935 .imfs_type = IMFS_GENERIC, 2936 .handlers = &bpf_imfs_handlers, 2937 .node_initialize = IMFS_node_initialize_default, 2938 .node_remove = IMFS_node_remove_default, 2939 .node_destroy = IMFS_node_destroy_default 2940 }; 2941 #endif /* __rtems__ */ 2674 2942 2675 2943 static void 2676 2944 bpf_drvinit(void *unused) 2677 2945 { 2946 #ifndef __rtems__ 2678 2947 struct cdev *dev; 2948 #else /* __rtems__ */ 2949 mode_t mode = S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO; 2950 int rv; 2951 #endif /* __rtems__ */ 2679 2952 2680 2953 mtx_init(&bpf_mtx, "bpf global lock", NULL, MTX_DEF); 2681 2954 LIST_INIT(&bpf_iflist); 2682 2955 2956 #ifndef __rtems__ 2683 2957 dev = make_dev(&bpf_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "bpf"); 2684 2958 /* For compatibility */ 2685 2959 make_dev_alias(dev, "bpf0"); 2960 #else /* __rtems__ */ 2961 rv = IMFS_make_generic_node("/dev/bpf", mode, &bpf_imfs_control, NULL); 2962 BSD_ASSERT(rv == 0); 2963 #endif /* __rtems__ */ 2686 2964 2687 2965 /* Register interface departure handler */ … … 2736 3014 d->bd_direction = bd->bd_direction; 2737 3015 d->bd_feedback = bd->bd_feedback; 3016 #ifndef __rtems__ 2738 3017 d->bd_async = bd->bd_async; 3018 #endif /* __rtems__ */ 2739 3019 d->bd_rcount = bd->bd_rcount; 2740 3020 d->bd_dcount = bd->bd_dcount; -
freebsd/sys/net/bpfdesc.h
r1fea8c4 re10d1cd 86 86 int bd_tstamp; /* select time stamping function */ 87 87 int bd_feedback; /* true to feed back sent packets */ 88 #ifndef __rtems__ 88 89 int bd_async; /* non-zero if packet reception should generate signal */ 90 #endif /* __rtems__ */ 89 91 int bd_sig; /* signal to send upon packet reception */ 90 92 struct sigio * bd_sigio; /* information for async I/O */ … … 113 115 #define BPFD_LOCK_ASSERT(bd) mtx_assert(&(bd)->bd_lock, MA_OWNED) 114 116 117 #ifndef __rtems__ 115 118 #define BPF_PID_REFRESH(bd, td) (bd)->bd_pid = (td)->td_proc->p_pid 116 119 #define BPF_PID_REFRESH_CUR(bd) (bd)->bd_pid = curthread->td_proc->p_pid 120 #else /* __rtems__ */ 121 #define BPF_PID_REFRESH(bd, td) do { } while (0) 122 #define BPF_PID_REFRESH_CUR(bd) do { } while (0) 123 #endif /* __rtems__ */ 117 124 118 125 #define BPF_LOCK() mtx_lock(&bpf_mtx) … … 130 137 int bd_direction; 131 138 int bd_feedback; 139 #ifndef __rtems__ 132 140 int bd_async; 141 #endif /* __rtems__ */ 133 142 u_int64_t bd_rcount; 134 143 u_int64_t bd_dcount; -
freebsd/usr.bin/netstat/bpf.c
r1fea8c4 re10d1cd 90 90 ((bd->bd_direction == BPF_D_OUT) ? 'o' : 's'); 91 91 *flagbuf++ = bd->bd_feedback ? 'b' : '-'; 92 #ifndef __rtems__ 92 93 *flagbuf++ = bd->bd_async ? 'a' : '-'; 94 #endif /* __rtems__ */ 93 95 *flagbuf++ = bd->bd_locked ? 'l' : '-'; 94 96 *flagbuf++ = '\0'; -
libbsd.txt
r1fea8c4 re10d1cd 109 109 110 110 * <sys/param.h>: Update Newlib to use a MSIZE of 256. 111 112 * BPF(4): Add support for zero-copy buffers. 111 113 112 114 [listing] -
rtemsbsd/include/rtems/bsd/local/opt_bpf.h
r1fea8c4 re10d1cd 1 #define DEV_BPF 1
Note: See TracChangeset
for help on using the changeset viewer.