bpf

å称
     bpf — ãã¼ã¯ã¬ã¤ãã±ãããã£ã«ã¿

æ¸å¼
     pseudo-device bpfilter

解説
     ãã¼ã¯ã¬ã¤ãã±ãããã£ã«ã¿ã¯ããã¼ã¿ãªã³ã¯å±¤ã«ããã¦ãããã³ã«éä¾åã®
     çã®å½¢ã®ã¤ã³ã¿ãã§ã¼ã¹ãæä¾ãã¾ãã ãããã¯ã¼ã¯ä¸ã®ãã±ããã¯ããã¨ãä»ã®ãã¹ãã«åãããã
     ãã®ã§ãã£ã¦ãããã¹ã¦ãã®æ©æ§ãéãã¦ã¢ã¯ã»ã¹ãããã¨ãã§ãã¾ãã

     ãã®ãã±ãããã£ã«ã¿ã¯ /dev/bpf0, /dev/bpf1 ãªã©ã® ã‐
     ã£ã©ã¯ã¿åç¹æ®ããã¤ã¹ã«è¦ãã¾ãã ãã®ããã¤ã¹ããªã¼ãã³ããå¾ããã¡ã¤ã«è¨è¿°åã¯
     BIOCSETIF ioctl
     ã«ãã£ã¦ãç¹å®ã®ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ã«çµã³ã¤ããªããã°ãªãã¾ããã
     æ示ãããã¤ã³ã¿ãã§ã¼ã¹ã¯è¤æ°ã®ç£è¦èã§å±æãããã¨ãã§ãã åè¨è¿°å‐
     ã®ä¸ã«ãããã£ã«ã¿ã¯ãåããã±ããã®æµããè¦ããã¨ã«ãªãã¾ãã ãªã¼ãã³ã§ãããã¡ã¤ã«ã®ä¸éã¯ã
     ã«ã¼ãã«ã®è¨å®ã§ä¸ããããå¤ã«å¶éããã¾ãã ä¸ã® æ¸å¼ ã§ä¸ããããä¾ã§ã¯ãå¶é㯠16
     ã«ãªã£ã¦ãã¾ãã

     ããããã®ãã¤ãããã¤ã¹ã«ã¯ãå¥ãã®ããã¤ã¹ãã¡ã¤ã«ãå¿è¦ã§ãã ããã¤ã¹ãã¡ã¤ã«ã使ç¨ä¸‐
     ã§ãããªãã°ããªã¼ãã³ã¯å¤±æãã errno ã«ã¯ EBUSY ãã»ããããã¾ãã

     ãªã¼ãã³ããã bpf ãã¡ã¤ã«ã®å®ä½ããããã«é¢é£ã¥ãããã¦ããã®ãã ã¦ã¼ã¶ãè¨‐
     å®å¯è½ãªãã±ãããã£ã«ã¿ã§ãã
     ããã¤ã³ã¿ãã§ã¼ã¹ã§ãã±ãããåä¿¡ããã¨ãã¯ãã¤ã§ãããã®ã¤ã³ã¿ãã§ã¼ã¹ã
     ç£è¦ãã¦ãããã¡ã¤ã«è¨è¿°åã¯ãã¹ã¦èªèº«ã®ãã£ã«ã¿ãé©ç¨ãã¾ãã ãã±ãããåãåãåè¨è¿°å‐
     ã¯ãèªåç¨ã®ã³ãã¼ãåãåãã¾ãã

     ããããã®ãã¡ã¤ã«ããã®å¥åã¯ããã£ã«ã¿ã§ããããããã±ãã㮠次ã®ã°ã«ã¼ããè¿ãã¾ãã
     æ§è½ãä¸ããããã«ãread ã«æ¸¡ããããã¡ã¯ bpf
     ãåé¨ã§ä½¿ç¨ãããããã¡ã¨åããµã¤ãºã§ãªããã°ãªãã¾ããã ãã®ãµã¤ãºã¯ã BIOCGBLEN ioctl
     (ä¸è¨ãåç§) ã§å¾ããã BIOCSBLEN ã§è¨å®ã§ãã¾ãã ãã®ãµã¤ãºãã大ããåãã®ãã±ããã¯ã
     å¿ç¶çã«åãè©°ãããã¦ãã¾ããã¨ã«æ³¨æãã¦ä¸ããã

     ãã®ãã±ãããã£ã«ã¿ã¯ãåºå®é·ãããã§ããã° ã©ã®ãªã³ã¯ã¬ãã«ãããã³ã«ã§ããµãã¼ããã¾ãã
     ä»ã®ã¨ãããã¤ã¼ãµããã㨠SLIP 㨠PPP ãã©ã¤ãã ãã bpf ã¨å調ãã¦åä½ããããã«ä¿®æ‐
     £ããã¦ãã¾ãã

     ãã±ãããã¼ã¿ã¯ãããã¯ã¼ã¯ãã¤ããªã¼ãã«ãªã£ã¦ããã®ã§ã
     ã¢ããªã±ã¼ã·ã§ã³ãè¤æ°ãã¤ãã®å¤ãå¼ãåºãããã«ã¯ byteorder(3) ãã¯ã‐
     ã使ããªããã°ãªãã¾ããã

     bpf ãã¡ã¤ã«è¨è¿°åã«æ¸ãè¾¼ããã¨ã§ãããã¯ã¼ã¯ã«ãã±ããã éåºãããã¨ãã§ãã¾ãã
     æ¸ãè¾¼ã¿ã¯ãããã¡ãªã³ã°ãããªãã®ã§ã1 åã®æ¸ãè¾¼ã¿ã«ã¤ã 1
     ã¤ã®ãã±ããã ãããå¦çããã¾ããã ç¾å¨ã¤ã¼ãµããã㨠SLIP
     ãªã³ã¯ã¸ã®æ¸ãè¾¼ã¿ã ãããµãã¼ãããã¦ãã¾ãã

IOCTL
     次ã®ãã㪠ioctl(2) ã³ãã³ãã³ã¼ãã <net/bpf.h>
     ã§å®ç¾©ããã¦ãã¾ãããã¹ã¦ã®ã³ãã³ãã«ã¯ 次ã®ãããªã¤ã³ã¯ã«ã¼ããã¡ã¤ã«ãå¿è¦ã§ãã

             #include <sys/types.h>
             #include <sys/time.h>
             #include <sys/ioctl.h>
             #include <net/bpf.h>

     ããã«ã BIOCGETIF 㨠BIOCSETIF ã¯ã ⟨sys/socket.h⟩ 㨠⟨net/if.h⟩
     ãå¿è¦ã¨ãã¾ãã

     FIONREAD 㨠SIOCGIFADDR 以å¤ã«ãã次ã®ãããªã³ãã³ãã ãªã¼ãã³ãã bpf
     ãã¡ã¤ã«ã«é©ç¨ã§ãã¾ãã ioctl(2) ã¸ã® (3 çªç®ã®) å¼æ°ã¯ã
     æå®ã®åã¸ã®ãã¤ã³ã¿ã§ãªããã°ãªãã¾ããã


     BIOCGBLEN      (u_int) bpf ãã¡ã¤ã«ä¸ã§èª‐
                    ã¿è¾¼ã¿ãè¡ãããã«å¿è¦ãªãããã¡é·ãè¿ãã¾ãã

     BIOCSBLEN      (u_int) bpf ãã¡ã¤ã«ä¸ã§èªã¿è¾¼ã¿ãè¡ãããã®ãããã¡é·ãè¨‐
                    å®ãã¾ãããããã¡ã¯ããã¡ã¤ã«ã BIOCSETIF
                    ã«ãã£ã¦ã¤ã³ã¿ãã§ã¼ã¹ã«æ¥ç¶ãããåã«è¨å®ãããªããã°ãªãã¾ããã
                    è¦æ±ããããããã¡ãµã¤ãºãé©ç¨ã§ããªãã£ãå ´åã¯ã
                    許容ã§ãããµã¤ãºã§æãè¿ããã®ã«è¨å®ããããããå¼æ°ã®ä¸ã«è¿ããã¾ãã
                    ãã®ãµã¤ãºã§ãªããã±ããããããã¡ãéã£ãã¨ãã«ã¯ã èªã¿è¾¼ã¿ã³ã¼ã«ã¯
                    EIO ã®å¤ã§çµäºãã¾ãã

     BIOCGDLT       (u_int)
                    æ¥ç¶ãããã¤ã³ã¿ãã§ã¼ã¹ã®ä¸ã«ãããã¼ã¿ãªã³ã¯å±¤ã®åãè¿ãã¾ãã
                    ã¤ã³ã¿ãã§ã¼ã¹ãæå®ããã¦ããªãã£ãå ´å EINVAL ãè¿ããã¾ãã
                    ããã¤ã¹ã®åã¯ã “DLT_” ãåã«ä»ããå½¢ã§ããã ⟨net/bpf.h⟩
                    ã§å®ç¾©ããã¦ãã¾ãã

     BIOCPROMISC    å¼·å¶çã«ã¤ã³ã¿ãã§ã¼ã¹ãç¡å·®å¥ (promiscuous) ã¢ã¼ãã«ãã¾ãã
                    ãã¼ã«ã«ãã¹ãã«åãããããã®ã®ã¿ãªãããã¹ã¦ã®ãã±ãããå¦çããã¾ãã
                    è¤æ°ã®ãã¡ã¤ã«ãä¸ããããã¤ã³ã¿ãã§ã¼ã¹ãç£è¦ãããã¨ãã§ããã®ã§ã
                    ãã®ã¤ã³ã¿ãã§ã¼ã¹ãç¡å·®å¥ã§ãªãã¢ã¼ãã§ãªã¼ãã³ããç£è¦èã§ã
                    ãã±ãããç¡å·®å¥ã«åä¿¡ãããã¨ãã§ãã¦ãã¾ãã¾ãã
                    ãã®åé¡ã¯é©å½ãªãã£ã«ã¿ã§ç¯æ£ãããã¨ãã§ãã¾ãã

     BIOCFLUSH      å°çãã±ããã®ãããã¡ããã©ãã·ã¥ããBIOCGSTATS ã§è¿ããã
                    éè¨å¤ããªã»ãããã¾ãã

     BIOCGETIF      (struct ifreq)
                    ãã¡ã¤ã«ãç£è¦ãã¦ãããã¼ãã¦ã§ã¢ã¤ã³ã¿ãã§ã¼ã¹ã®ååãè¿ãã¾ãã ååã¯
                    ifreq æ§é ä½ã® ifr_name ãã£ã¼ã«ãã«è¿ããã¾ãã
                    ä»ã®ãã£ã¼ã«ãã¯ãã¹ã¦æªå®ç¾©ã¨ãªãã¾ãã

     BIOCSETIF      (struct ifreq)
                    ãã¡ã¤ã«ã«é¢é£ä»ãããã¼ãã¦ã§ã¢ã¤ã³ã¿ãã§ã¼ã¹ãè¨å®ãã¾ãã
                    ãã®ã³ãã³ãã¯ãã©ããªãã±ãããèªã¿è¾¼ããããåã« å®è¡ãããªããã°ããã¾ããã
                    ããã¤ã¹ã¯ã ifreq æ§é ä½ã® ifr_name
                    ãã£ã¼ã«ãã使ã£ã¦ååã§ç¤ºããã¾ãã ããã« BIOCFLUSH
                    ã®åä½ãå®è¡ãã¾ãã

     BIOCSRTIMEOUT

     BIOCGRTIMEOUT  (struct timeval) ã¿ã¤ã ã¢ã¦ããã©ã¡ã¼ã¿ãè¨å®ã¾ãã¯åå¾ãã¾ãã
                    å¼æ°ã«ã¯ãèªã¿è¾¼ã¿è¦æ±ã§ã¿ã¤ã ã¢ã¦ãããã¾ã§ã®
                    å¾ã¡æéã®é·ããæå®ãã¾ãã ãã®ãã©ã¡ã¼ã¿ã¯ã open(2) ã«ãã 0
                    ã«åæåãããã¿ã¤ã ã¢ã¦ãããªããã¨ãæ示ãã¾ãã

     BIOCGSTATS     (struct bpf_stat) ãã±ããéè¨å¤ã®æ¬¡ã®æ§é ä½ãè¿ãã¾ã:

                    struct bpf_stat {
                            u_int bs_recv;    /* åä¿¡ãããã±ããæ° */
                            u_int bs_drop;    /* è½ã¨ãããã±ããæ° */
                    };

                    ãã£ã¼ã«ãã¯æ¬¡ã®ããã«ãªãã¾ã:

                          bs_recv ãªã¼ãã³ã¾ãã¯ãªã»ããå¾ã«ããã®è¨è¿°å‐
                                  ã«ãã£ã¦åä¿¡ãããã±ããæ° (æå¾ã®èª‐
                                  ã¿è¾¼ã¿ã³ã¼ã«ãããããã¡ããã¦ãããã®ãå«ã¿ã¾ã)ã

                          bs_drop ãã£ã«ã¿ãåãåãã¯ãããããããã¡ã®ãªã¼ãããã¼ã«ãã
                                  ã«ã¼ãã«ãè½ã¨ãããã±ããã®æ°
                                  (ã¤ã¾ããã¢ããªã±ã¼ã·ã§ã³ã®èª‐
                                  ã¿è¾¼ã¿ããã±ããã®æµéã«è¿½ãã¤ãã¦ããªã
                                  ã¨ãããã¨ã§ã)ã

     BIOCIMMEDIATE  (u_int) å¼æ°ã®çå½å¤ã«åºã¥ã㦠``ç´æ¥ã¢ã¼ã''
                    ãæå¹ã¾ãã¯ç¡å¹ã«ãã¾ãã ç´æ¥ã¢ã¼ããæå¹ãªã¨ãããã±ãããåãåãã¨èª‐
                    ã¿è¾¼ã¿ã¯
                    ãã ã¡ã«è¿ããã¾ããç¡å¹ãªã¨ããå¥åã¯ã«ã¼ãã«ãããã¡ããã£ã±ãã«ãªããã
                    ã¾ãã¯ã¿ã¤ã ã¢ã¦ããèµ·ããã¾ã§ãããã¯ããã¾ãã
                    ããã¯ããªã¢ã«ã¿ã¤ã ã«ã¡ãã»ã¼ã¸ã«å¿çããªããã°ãªããªã rarpd(8)
                    ã®ãããªããã°ã©ã ã«ã¯ä¾¿å©ã§ãã
                    æ°ãããã¡ã¤ã«ã«å¯¾ãã¦ã¯ãããã©ã«ãã§ã¯ãªãã«ãªãã¾ãã

     BIOCSETF       (struct bpf_program) èå³ã®ãªããã±ãããæ¨ã¦ãããã«
                    ã«ã¼ãã«ã使ããã£ã«ã¿ããã°ã©ã ãè¨å®ãã¾ãã
                    次ã®æ§é ä½ãéãã¦å½ä»¤ã並ã¹ãéåã¨ãã®é·ãã渡ããã¾ã:

                    struct bpf_program {
                            int bf_len;
                            struct bpf_insn *bf_insns;
                    };

                    ãã£ã«ã¿ããã°ã©ã 㯠bf_insns ãã£ã¼ã«ãã§æå®ããã ‘struct
                    bpf_insn’ ã®æ§é ä½ä¸ã«ãããããã°ã©ã ã®é·ãã bf_len
                    ãã£ã¼ã«ãã§ä¸ãããã¾ãã ããã¦ã BIOCFLUSH ã®åä½ãå®è¡ããã¾ãã
                    ãã£ã«ã¿è¨èªã®èª¬æã«ã¤ãã¦ã¯ ãã£ã«ã¿ãã·ã³
                    ã®ã»ã¯ã·ã§ã³ãè¦ã¦ä¸ããã

     BIOCVERSION    (struct bpf_version) ç¾å¨ã«ã¼ãã«ã«èªè‐
                    ããã¦ãããã£ã«ã¿è¨èªã®ã¡ã¸ã£ã¼ããã³
                    ãã¤ããã¼ã¸ã§ã³çªå·ãè¿ãã¾ãããã£ã«ã¿ãã¤ã³ã¹ãã¼ã«ããåã«ã
                    ã¢ããªã±ã¼ã·ã§ã³ã¯ãåä½ãã¦ããã«ã¼ãã«ã¨ç¾å¨ã®ãã¼ã¸ã§ã³ã¨ã
                    äºææ§ããããã©ããã調ã¹ãªããã°ãªãã¾ããã
                    ã¡ã¸ã£ã¼çªå·ãä¸è´ããã¢ããªã±ã¼ã·ã§ã³ã®ãã¤ãçªå·ã
                    ã«ã¼ãã«ã®ãã¤ãçªå·ã«çãããããã以ä¸ãªããã¼ã¸ã§ã³çªå·ã¯äºææ§ã
                    ããã¾ãã ã«ã¼ãã«ã®ãã¼ã¸ã§ã³çªå·ã¯ä»¥ä¸ã®æ§é ä½ã§è¿ããã¾ã:

                    struct bpf_version {
                            u_short bv_major;
                            u_short bv_minor;
                    };

                    ç¾å¨ã®ãã¼ã¸ã§ã³çªå·ã¯ ⟨net/bpf.h⟩ ä¸ã® BPF_MAJOR_VERSION
                    㨠BPF_MINOR_VERSION ã«ãã£ã¦ä¸ãããã¾ãã
                    äºææ§ã®ãªããã£ã«ã¿ã§ã¯ãäºæããªãåä½ã«çµããããããã¾ãã
                    (æããããããªã®ã¯ã ioctl()
                    ã«ãã£ã¦ã¨ã©ã¼ãè¿ãããããã¾ãã¯å¶ç¶ã«ãã±ãããä¸è´ãããã¨ã§ã)ã

BPF ããã
     read(2) ã«ãã£ã¦è¿ãããåãã±ããã®åé ã«ã¯ã 次ã®ãããªæ§é ä½ãã¤ãããã¦ãã¾ã:

     struct bpf_hdr {
             struct timeval bh_tstamp;     /* ã¿ã¤ã ã¹ã¿ã³ã */
             u_long bh_caplen;             /* ãã£ããã£ãããé¨åã®é·ã */
             u_long bh_datalen;            /* ãã±ããã®ãªãªã¸ãã«ã®é·ã */
             u_short bh_hdrlen;            /* bpf ãããã®é·ã (ãã®æ§é ä½
                                              + å¢ç調æ´ããã£ã³ã°) */
     };

     ãã£ã¼ã«ãã¯ãã¹ãé ã§ä¿åããã¦ããã次ã®ããã«ãªãã¾ã:

     bh_tstamp   ãã±ãããã£ã«ã¿ã«ãã£ã¦ããã®ãã±ãããå¦çãããæå»
     bh_caplen   ãã±ããã®ãã£ããã£ãããé¨åã®é·ãã ããã¯åãè©°ãéã®æå°å¤ã§ã
                 ãã£ã«ã¿ã¨ãã±ããé·ã«ãã£ã¦æå®ããã¦ãã¾ãã
     bh_datalen  çµè·¯ããé¢ãããã±ããé·ã ãã®å¤ã¯ãã£ã«ã¿ã§æå®ãããåãè©°ãéã«ã¯ä¾å‐
                 ãã¾ããã
     bh_hdrlen   bpf ãããã®é·ãããã㯠sizeof(struct bpf_hdr) ã«çããã¨ã¯éãã¾ããã

     bh_hdrlen ãã£ã¼ã«ãã¯ãããã¨ãªã³ã¯ã¬ãã«ãããã³ã«éã® ããã£ã³ã°ã®ããã«å‐
     å¨ãã¾ãããã®ç®çã¯ã ãã±ãããã¼ã¿æ§é ã®é©åãªå¢ç調æ´ãä¿è¨¼ãããã¨ã§ãã ããã¯ã
     å¢ç調æ´ã«å³ããã¢ã¼ããã¯ãã£ãå¿è¦ã¨ãããã¨ã§ããã ã¾ããããã«ãã£ã¦ä»ã®å¤ãã®ã¢ã¼ã‐
     ãã¯ãã£ã«ãããæ§è½ãåä¸ãã¾ãã ãã±ãããã£ã«ã¿ã¯ bpf_hdr
     ã¨ãããã¯ã¼ã¯å±¤ã®ããããã¯ã¼ãå¢çã«ãªããã¨ãä¿è¨¼ãã¾ãã
     å¢ç調æ´ãå¶ç´ããããã·ã³ä¸ã§ãªã³ã¯å±¤ãããã³ã«ãã¢ã¯ã»ã¹
     ããã¨ãã«ã¯ãé©åãªæ³¨æãæããªããã°ãªãã¾ãã
     (ããã¯ã¤ã¼ãµãããä¸ã§ã¯åé¡ã«ã¯ãªãã¾ããããªããªãã ãã£ã¼ã«ãã®åã short
     ã§ããå¶æ°ãªãã»ããã«è½ã¡çãã¾ããã ã¢ãã¬ã¹ããããããã¤ãåä½ã§ã¢ã¯ã»ã¹ãããããã§ã)ã

     ããã«ãåãã®ãã±ããã¯ã¯ã¼ãå¢çã§å§ã¾ãããã«ããã£ã³ã°ããã¾ãã
     ããã«ãããã¢ããªã±ã¼ã·ã§ã³ã¯ãã±ãããã次ã®ãã±ãããå¾ãæ¹æ³ã ç¥ã£ã¦ãããã¨ãè¦æ±ããã¾ãã
     ãã®ããã»ã¹ãæå©ãããããã«ããã¯ã BPF_WORDALIGN ã ⟨net/bpf.h⟩ ä¸ã§å®ç¾©ããã¦ãã¾ãã
     å¼æ°ã¯æãè¿ãã¯ã¼ãå¢çå¤ (ã¯ã¼ãã BPF_ALIGNMENT ãã¤ãå¹) ã«åãä¸ãããã¾ãã

     ä¾ãã° ‘p’ ããã±ããã®åé ãæãã¨ãã次ã®è¡¨ç¾ã¯ ãã¤ã³ã¿ã次ã®ãã±ããã¸é²ãã¾ã:
           p = (char *)p + BPF_WORDALIGN(p->bh_hdrlen + p->bh_caplen)

     å¢ç調æ´ã®æ©æ§ãé©åã«åä½ãããããã« read(2)
     ã«æ¸¡ããããããã¡ã¯ãããèªèº«ãã¯ã¼ãå¢çã«ãªããã°ãªãã¾ããã malloc(3)
     é¢æ°ã¯å¸¸ã«ã¯ã¼ãå¢çã®ãããã¡ãè¿ãã¾ãã

ãã£ã«ã¿ãã·ã³
     ãã£ã«ã¿ããã°ã©ã ã¯å½ä»¤ã並ã¹ãéåã§ããããã¹ã¦ã®åå²ã
     ã³ã¼ãã®åæ¹ã«åãããã®ã§ãããã¾ãã return å½ä»¤ã§çµãããã®ã§ãã åå½ä»¤ã¯ãã¢ã‐
     ã¥ã ã¬ã¼ã¿ãã¤ã³ããã¯ã¹ã¬ã¸ã¹ã¿ãä¸æã¡ã¢ãªè¨æ¶ã ããã³æé»ã®ãã‐
     ã°ã©ã ã«ã¦ã³ã¿ããæãçä¼¼ãã·ã³ç¶æä¸ã§ ä½ããã®åä½ãè¡ãªãã¾ãã

     次ã®æ§é ä½ãå½ä»¤ãã©ã¼ãããã®å®ç¾©ã§ã:

     struct bpf_insn {
             u_short code;
             u_char  jt;
             u_char  jf;
             u_long k;
     };

     k ãã£ã¼ã«ãã¯å½ä»¤ã«ãã£ã¦ç°ãªãç¨æ³ã§ç¨ãããã jt 㨠jf
     ãã£ã¼ã«ãã¯åå²å½ä»¤ã«ãã£ã¦ãªãã»ããã¨ãã¦ç¨ãããã¾ãã
     æä½ã³ã¼ãã¯åé層çãªå½¢ã§ç¬¦å·åããã¾ãã å½ä»¤ã«ã¯ 8 ã¤ã®ã¯ã©ã¹ BPF_LD,
     BPF_LDX, BPF_ST, BPF_STX, BPF_ALU, BPF_JMP, BPF_RET, BPF_MISC ãããã¾ãã
     ä»ã®ãããããªã¢ã¼ãã¨æä½ãããã¯å®éã®å½ä»¤ãä¸ããããã« ãããå ç® (or)
     ãããã¯ã©ã¹ã«å¤æããã¾ãã ã¯ã©ã¹ã¨ã¢ã¼ã㯠⟨net/bpf.h⟩ åã§å®ç¾©ããã¦ãã¾ãã

     以ä¸ã¯å®ç¾©ãããããããã® bpf å½ä»¤ã§ãã 便å®çã« A ãã¢ãã¥ã ã¬ã¼ã¿ãX
     ãã¤ã³ããã¯ã¹ã¬ã¸ã¹ã¿ã P[] ããã±ãããã¼ã¿ãM[] ãå¯ãéãã®ä¸æã¡ã¢ãªè¨æ¶ã§ããã¨ãã¾ãã
     P[i:n] ã¯ãã±ããåã® ``i'' ãã¤ããªãã»ããã®ãã¼ã¿ãæãã ã¯ã¼ã (n=4)ã符å·ç¡ãåã¯ã¼ã
     (n=2)ã符å·ç¡ããã¤ã (n=1) ã«ç¿»è¨³ããã¾ãã M[i] ã¯ãä¸æã¡ã¢ãªè¨æ¶ã®ä¸ã§ i
     çªç®ã®ã¯ã¼ããæããã¯ã¼ãåä½ã® ã¢ãã¬ã¹ã ããå²ãæ¯ããã¾ããã¡ã¢ãªè¨æ¶ã¯ 0 ãã
     BPF_MEMWORDS - 1 ã«çªå·ä»ãããã¾ãã k, jt, jf ã¯ãå½ä»¤å®ç¾©ã®ä¸‐
     ã§å¯¾å¿ãããã£ã¼ã«ãã«ãªãã¾ãã``len'' ã¯ã ãã±ããé·ãåç§ãã¾ãã

     BPF_LD    ãããã®å½ä»¤ã¯ãå¤ãã¢ãã¥ã ã¬ã¼ã¿ã«è¤åãã¾ãã
               ã½ã¼ã¹ãªãã©ã³ãã®åã¯ã``ã¢ãã¬ãã·ã³ã°ã¢ã¼ã'' ã§æå®ããã å®æ°
               (BPF_IMM) ã§ããåºå®ãªãã»ããã®ãã±ãããã¼ã¿ (BPF_ABS)
               ãå¯å¤ãªãã»ããã®ãã±ãããã¼ã¿ (BPF_IND) ããã±ããé· (BPF_LEN)
               ãä¸æã¡ã¢ãªè¨æ¶åã®ã¯ã¼ã (BPF_MEM) ãã¨ãå¾ã¾ãã BPF_IND 㨠BPF_ABS
               ã®å ´åããã¼ã¿ãµã¤ãºã¯ãã¯ã¼ã (BPF_W) ããã¼ãã¯ã¼ã (BPF_H) ããã¤ã
               (BPF_B) ã®ããããã§ãªããã°ãªãã¾ããã 使ç¨å¯è½ãªå¨ BPF_LD
               å½ä»¤ã®æå³ã¯æ¬¡ã®éãã§ãã

               BPF_LD+BPF_W+BPF_ABS  A <- P[k:4]
               BPF_LD+BPF_H+BPF_ABS  A <- P[k:2]
               BPF_LD+BPF_B+BPF_ABS  A <- P[k:1]
               BPF_LD+BPF_W+BPF_IND  A <- P[X+k:4]
               BPF_LD+BPF_H+BPF_IND  A <- P[X+k:2]
               BPF_LD+BPF_B+BPF_IND  A <- P[X+k:1]
               BPF_LD+BPF_W+BPF_LEN  A <- len
               BPF_LD+BPF_IMM        A <- k
               BPF_LD+BPF_MEM        A <- M[k]

     BPF_LDX   ãããã®å½ä»¤ã¯å¤ãã¤ã³ããã¯ã¹ã¬ã¸ã¹ã¿ã«ãã¼ããã¾ãã
               ãã®å½ä»¤ã®ã¨ãã®ã¢ãã¬ãã·ã³ã°ã¢ã¼ãã¯ãã¢ãã¥ã ã¬ã¼ã¿ã¸ã®ãã¼ã
               æãããå³å¯ã§ãããIP ãããé·ããã¼ãããå¹æçãªæ¹æ³ã§ãã BPF_MSH
               ãå«ãã§ãããã¨ã«æ³¨ç®ãã¦ä¸ããã

               BPF_LDX+BPF_W+BPF_IMM  X <- k
               BPF_LDX+BPF_W+BPF_MEM  X <- M[k]
               BPF_LDX+BPF_W+BPF_LEN  X <- len
               BPF_LDX+BPF_B+BPF_MSH  X <- 4*(P[k:1]&0xf)

     BPF_ST    ãã®å½ä»¤ã¯ã¢ãã¥ã ã¬ã¼ã¿ãä¸æã¡ã¢ãªã«éé¿ãã¾ãã
               è¡ãåã®å¯è½æ§ãä¸ã¤ãããªãã®ã§ã¢ãã¬ãã·ã³ã°ã¢ã¼ãã¯ä¸è¦ã§ãã

               BPF_ST  M[k] <- A

     BPF_STX   ãã®å½ä»¤ã¯ã¤ã³ããã¯ã¹ã¬ã¸ã¹ã¿ãä¸æã¡ã¢ãªã«éé¿ãã¾ãã

               BPF_STX  M[k] <- X

     BPF_ALU   alu å½ä»¤ã¯ãã¢ãã¥ã ã¬ã¼ã¿ã¨ã¤ã³ããã¯ã¹ã¬ã¸ã¹ã¿ã¾ãã¯å®æ°éã®
               æä½ãå®è¡ããçµæãã¢ãã¥ã ã¬ã¼ã¿ã«æ»ãã¾ãã