* Set the data link type of a BPF instance. */
| 2818 | * Set the data link type of a BPF instance. |
| 2819 | */ |
| 2820 | static int |
| 2821 | bpf_setdlt(struct bpf_d *d, u_int dlt) |
| 2822 | { |
| 2823 | int error, opromisc; |
| 2824 | struct ifnet *ifp; |
| 2825 | struct bpf_if *bp; |
| 2826 | |
| 2827 | BPF_LOCK_ASSERT(); |
| 2828 | MPASS(d->bd_bif != NULL); |
| 2829 | |
| 2830 | /* |
| 2831 | * It is safe to check bd_bif without BPFD_LOCK, it can not be |
| 2832 | * changed while we hold global lock. |
| 2833 | */ |
| 2834 | if (d->bd_bif->bif_dlt == dlt) |
| 2835 | return (0); |
| 2836 | |
| 2837 | ifp = d->bd_bif->bif_ifp; |
| 2838 | CK_LIST_FOREACH(bp, &bpf_iflist, bif_next) { |
| 2839 | if (bp->bif_ifp == ifp && bp->bif_dlt == dlt) |
| 2840 | break; |
| 2841 | } |
| 2842 | if (bp == NULL) |
| 2843 | return (EINVAL); |
| 2844 | |
| 2845 | opromisc = d->bd_promisc; |
| 2846 | bpf_attachd(d, bp); |
| 2847 | if (opromisc) { |
| 2848 | error = ifpromisc(bp->bif_ifp, 1); |
| 2849 | if (error) |
| 2850 | if_printf(bp->bif_ifp, "%s: ifpromisc failed (%d)\n", |
| 2851 | __func__, error); |
| 2852 | else |
| 2853 | d->bd_promisc = 1; |
| 2854 | } |
| 2855 | return (0); |
| 2856 | } |
| 2857 | |
| 2858 | static void |
| 2859 | bpf_drvinit(void *unused) |
no test coverage detected