コード例 #1
0
 /// <summary>
 /// Checks if a given packet matches this rule.
 /// </summary>
 /// <param name="packet">The packet to test.</param>
 /// <returns>True if the packet matches; otherwise false.</returns>
 public Zen <bool> Matches(Zen <Packet> packet)
 {
     // TODO: If ports are zero, do NOT include in predicate (zero implies "ANY")
     return(And(packet.GetDstIp() >= this.DstIpLow,
                packet.GetDstIp() <= this.DstIpHigh,
                packet.GetDstPort() == this.DstPort,
                packet.GetSrcIp() >= this.SrcIpLow,
                packet.GetSrcIp() <= this.SrcIpHigh,
                packet.GetSrcPort() == this.SrcPort));
 }
コード例 #2
0
        /// <summary>
        /// Match a header against an acl line.
        /// </summary>
        /// <param name="hdr">The header.</param>
        /// <returns>Whether matched.</returns>
        public Zen <bool> Matches(Zen <IpHeader> hdr)
        {
            Zen <bool> dstMatch = this.DstIp != null?this.DstIp.Match(hdr.GetDstIp()) : true;

            Zen <bool> srcMatch = this.SrcIp != null?this.SrcIp.Match(hdr.GetSrcIp()) : true;

            Zen <bool> dstPortLowMatch  = this.DstPortLow.HasValue ? hdr.GetDstPort() >= this.DstPortLow.Value : true;
            Zen <bool> dstPortHighMatch = this.DstPortHigh.HasValue ? hdr.GetDstPort() <= this.DstPortHigh.Value : true;

            Zen <bool> srcPortLowMatch  = this.SrcPortLow.HasValue ? hdr.GetSrcPort() >= this.SrcPortLow.Value : true;
            Zen <bool> srcPortHighMatch = this.SrcPortHigh.HasValue ? hdr.GetSrcPort() <= this.SrcPortHigh.Value : true;

            Zen <bool> protoLowMatch  = this.ProtocolLow.HasValue ? hdr.GetProtocol() >= this.ProtocolLow.Value : true;
            Zen <bool> protoHighMatch = this.ProtocolHigh.HasValue ? hdr.GetProtocol() <= this.ProtocolHigh.Value : true;

            return(And(
                       dstMatch, srcMatch,
                       dstPortHighMatch, dstPortLowMatch,
                       srcPortHighMatch, srcPortLowMatch,
                       protoHighMatch, protoLowMatch));
        }