Example #1
0
 def set_opcode(self, opcode):
     """Set the opcode.
     @param opcode: the opcode
     @type opcode: int
     """
     self.flags &= 0x87FF
     self.flags |= opcode.to_flags(opcode)
Example #2
0
 def set_opcode(self, opcode):
     """Set the opcode.
     @param opcode: the opcode
     @type opcode: int
     """
     self.flags &= 0x87FF
     self.flags |= opcode.to_flags(opcode)
Example #3
0
    def _header_line(self, section):
        """Process one line from the text format header section."""

        token = self.tok.get()
        what = token.value
        if what == 'id':
            self.message.id = self.tok.get_int()
        elif what == 'flags':
            while True:
                token = self.tok.get()
                if not token.is_identifier():
                    self.tok.unget(token)
                    break
                self.message.flags = self.message.flags | \
                                     flags.from_text(token.value)
            if opcode.is_update(self.message.flags):
                self.updating = True
        elif what == 'edns':
            self.message.edns = self.tok.get_int()
            self.message.ednsflags = self.message.ednsflags | \
                                     (self.message.edns << 16)
        elif what == 'eflags':
            if self.message.edns < 0:
                self.message.edns = 0
            while True:
                token = self.tok.get()
                if not token.is_identifier():
                    self.tok.unget(token)
                    break
                self.message.ednsflags = self.message.ednsflags | \
                              flags.edns_from_text(token.value)
        elif what == 'payload':
            self.message.payload = self.tok.get_int()
            if self.message.edns < 0:
                self.message.edns = 0
        elif what == 'opcode':
            text = self.tok.get_string()
            self.message.flags = self.message.flags | \
                      opcode.to_flags(opcode.from_text(text))
        elif what == 'rcode':
            text = self.tok.get_string()
            self.message.set_rcode(rcode.from_text(text))
        else:
            raise UnknownHeaderField
        self.tok.get_eol()
Example #4
0
    def _header_line(self, section):
        """Process one line from the text format header section."""

        token = self.tok.get()
        what = token.value
        if what == 'id':
            self.message.id = self.tok.get_int()
        elif what == 'flags':
            while True:
                token = self.tok.get()
                if not token.is_identifier():
                    self.tok.unget(token)
                    break
                self.message.flags = self.message.flags | \
                                     flags.from_text(token.value)
            if opcode.is_update(self.message.flags):
                self.updating = True
        elif what == 'edns':
            self.message.edns = self.tok.get_int()
            self.message.ednsflags = self.message.ednsflags | \
                                     (self.message.edns << 16)
        elif what == 'eflags':
            if self.message.edns < 0:
                self.message.edns = 0
            while True:
                token = self.tok.get()
                if not token.is_identifier():
                    self.tok.unget(token)
                    break
                self.message.ednsflags = self.message.ednsflags | \
                              flags.edns_from_text(token.value)
        elif what == 'payload':
            self.message.payload = self.tok.get_int()
            if self.message.edns < 0:
                self.message.edns = 0
        elif what == 'opcode':
            text = self.tok.get_string()
            self.message.flags = self.message.flags | \
                      opcode.to_flags(opcode.from_text(text))
        elif what == 'rcode':
            text = self.tok.get_string()
            self.message.set_rcode(rcode.from_text(text))
        else:
            raise UnknownHeaderField
        self.tok.get_eol()
Example #5
0
    def __init__(self,
                 zone,
                 rdclass=rdataclass.IN,
                 keyring=None,
                 keyname=None,
                 keyalgorithm=tsig.default_algorithm):
        """Initialize a new DNS Update object.

        @param zone: The zone which is being updated.
        @type zone: A name.Name or string
        @param rdclass: The class of the zone; defaults to rdataclass.IN.
        @type rdclass: An int designating the class, or a string whose value
        is the name of a class.
        @param keyring: The TSIG keyring to use; defaults to None.
        @type keyring: dict
        @param keyname: The name of the TSIG key to use; defaults to None.
        The key must be defined in the keyring.  If a keyring is specified
        but a keyname is not, then the key used will be the first key in the
        keyring.  Note that the order of keys in a dictionary is not defined,
        so applications should supply a keyname when a keyring is used, unless
        they know the keyring contains only one key.
        @type keyname: name.Name or string
        @param keyalgorithm: The TSIG algorithm to use; defaults to
        tsig.default_algorithm.  Constants for TSIG algorithms are defined
        in tsig, and the currently implemented algorithms are
        HMAC_MD5, HMAC_SHA1, HMAC_SHA224, HMAC_SHA256, HMAC_SHA384, and
        HMAC_SHA512.
        @type keyalgorithm: string
        """
        super(Update, self).__init__()
        self.flags |= opcode.to_flags(opcode.UPDATE)
        if isinstance(zone, (str, unicode)):
            zone = name.from_text(zone)
        self.origin = zone
        if isinstance(rdclass, str):
            rdclass = rdataclass.from_text(rdclass)
        self.zone_rdclass = rdclass
        self.find_rrset(self.question,
                        self.origin,
                        rdclass,
                        rdatatype.SOA,
                        create=True,
                        force_unique=True)
        if not keyring is None:
            self.use_tsig(keyring, keyname, algorithm=keyalgorithm)
Example #6
0
    def __init__(self, zone, rdclass=rdataclass.IN, keyring=None,
                 keyname=None, keyalgorithm=tsig.default_algorithm):
        """Initialize a new DNS Update object.

        @param zone: The zone which is being updated.
        @type zone: A name.Name or string
        @param rdclass: The class of the zone; defaults to rdataclass.IN.
        @type rdclass: An int designating the class, or a string whose value
        is the name of a class.
        @param keyring: The TSIG keyring to use; defaults to None.
        @type keyring: dict
        @param keyname: The name of the TSIG key to use; defaults to None.
        The key must be defined in the keyring.  If a keyring is specified
        but a keyname is not, then the key used will be the first key in the
        keyring.  Note that the order of keys in a dictionary is not defined,
        so applications should supply a keyname when a keyring is used, unless
        they know the keyring contains only one key.
        @type keyname: name.Name or string
        @param keyalgorithm: The TSIG algorithm to use; defaults to
        tsig.default_algorithm.  Constants for TSIG algorithms are defined
        in tsig, and the currently implemented algorithms are
        HMAC_MD5, HMAC_SHA1, HMAC_SHA224, HMAC_SHA256, HMAC_SHA384, and
        HMAC_SHA512.
        @type keyalgorithm: string
        """
        super(Update, self).__init__()
        self.flags |= opcode.to_flags(opcode.UPDATE)
        if isinstance(zone, (str, unicode)):
            zone = name.from_text(zone)
        self.origin = zone
        if isinstance(rdclass, str):
            rdclass = rdataclass.from_text(rdclass)
        self.zone_rdclass = rdclass
        self.find_rrset(self.question, self.origin, rdclass, rdatatype.SOA,
                        create=True, force_unique=True)
        if not keyring is None:
            self.use_tsig(keyring, keyname, algorithm=keyalgorithm)