@@ -382,7 +382,7 @@ bpf_icmp(const struct bpf *bpf)
382382
383383struct bpf *
384384bpf_open (const struct interface * ifp , int (* filter )(const struct bpf * ),
385- unsigned int flags )
385+ int flags )
386386{
387387 struct bpf * bpf ;
388388#ifdef __linux__
@@ -442,13 +442,13 @@ bpf_open(const struct interface *ifp, int (*filter)(const struct bpf *),
442442#else /* !__linux__ */
443443
444444#ifdef O_CLOEXEC
445- #define BPF_OPEN_FLAGS O_RDWR | O_NONBLOCK | O_CLOEXEC
445+ #define BPF_OPEN_FLAGS O_NONBLOCK | O_CLOEXEC
446446#else
447- #define BPF_OPEN_FLAGS O_RDWR | O_NONBLOCK
447+ #define BPF_OPEN_FLAGS O_NONBLOCK
448448#endif
449449
450450 /* /dev/bpf is a cloner on modern kernels */
451- bpf -> bpf_fd = open ("/dev/bpf" , BPF_OPEN_FLAGS );
451+ bpf -> bpf_fd = open ("/dev/bpf" , flags | BPF_OPEN_FLAGS );
452452
453453 /* Support older kernels where /dev/bpf is not a cloner */
454454 if (bpf -> bpf_fd == -1 ) {
@@ -459,7 +459,7 @@ bpf_open(const struct interface *ifp, int (*filter)(const struct bpf *),
459459 r = snprintf (device , sizeof (device ), "/dev/bpf%d" , n ++ );
460460 if (r == -1 )
461461 break ;
462- bpf -> bpf_fd = open (device , BPF_OPEN_FLAGS );
462+ bpf -> bpf_fd = open (device , flags | BPF_OPEN_FLAGS );
463463 } while (bpf -> bpf_fd == -1 && errno == EBUSY );
464464 }
465465
@@ -503,10 +503,10 @@ bpf_open(const struct interface *ifp, int (*filter)(const struct bpf *),
503503 goto eexit ;
504504
505505/* As we are only writing to BPF, we don't need a buffer */
506- #if 0
507506#ifdef __linux__
508507 UNUSED (flags );
509508#else
509+ #if 0
510510 if (flags & (O_RDONLY | O_RDWR )) {
511511 /* Get the required BPF buffer length from the kernel. */
512512 if (ioctl (bpf -> bpf_fd , BIOCGBLEN , & ibuf_len ) == -1 )
@@ -518,8 +518,6 @@ bpf_open(const struct interface *ifp, int (*filter)(const struct bpf *),
518518 goto eexit ;
519519 }
520520#endif
521- #else
522- UNUSED (flags );
523521#endif
524522
525523 return bpf ;
0 commit comments