Changeset 191 for trunk/dhcp
- Timestamp:
- Oct 11, 2007, 5:02:28 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dhcp/dhcpserver.py
r190 r191 1 1 #!/usr/bin/python 2 import sys .path2 import sys 3 3 sys.path.append('pydhcplib/') 4 4 import pydhcplib … … 7 7 from pydhcplib.type_hw_addr import hwmac 8 8 from pydhcplib.type_ipv4 import ipv4 9 from pydhcplib.type_strlist import strlist 9 10 10 11 import event_logger 11 12 if '__main__' == __name__: 12 event_logger.init("stdout", ' INFO', {})13 event_logger.init("stdout", 'DEBUG', {}) 13 14 from event_logger import Log 14 15 15 16 import sipb_xen_database 17 18 dhcp_options = {'subnet_mask': '255.255.0.0', 19 'router': '18.181.0.1', 20 'domain_name_server': '18.70.0.160,18.71.0.151,18.72.0.3', 21 'domain_name': 'mit.edu'} 22 16 23 17 24 class DhcpBackend: … … 27 34 return None 28 35 return ip 36 def getParameters(self): 37 options = {} 38 for parameter, value in dhcp_options.iteritems(): 39 option_type = DhcpOptionsTypes[DhcpOptions[parameter]] 40 41 if option_type == "ipv4" : 42 # this is a single ip address 43 options[parameter] = map(int,value.split(".")) 44 elif option_type == "ipv4+" : 45 # this is multiple ip address 46 iplist = value.split(",") 47 opt = [] 48 for single in iplist : 49 opt.append(ipv4(single).list()) 50 options[parameter] = opt 51 elif option_type == "32-bits" : 52 # This is probably a number... 53 digit = int(value) 54 options[parameter] = [digit>>24&0xFF,(digit>>16)&0xFF,(digit>>8)&0xFF,digit&0xFF] 55 elif option_type == "16-bits" : 56 digit = int(value) 57 options[parameter] = [(digit>>8)&0xFF,digit&0xFF] 58 59 elif option_type == "char" : 60 digit = int(value) 61 options[parameter] = [digit&0xFF] 62 63 elif option_type == "bool" : 64 if value=="False" or value=="false" or value==0 : 65 options[parameter] = [0] 66 else : options[parameter] = [1] 67 68 elif option_type == "string" : 69 options[parameter] = strlist(value).list() 70 71 else : 72 options[parameter] = strlist(value).list() 73 return options 29 74 30 75 def Discover(self, packet): … … 35 80 ip = ipv4(ip) 36 81 Log.Output(Log.debug,"dhcp_backend : Discover result = "+str(ip)) 37 packet_parameters = {}82 packet_parameters = self.getParameters() 38 83 39 84 # FIXME: Other offer parameters go here … … 105 150 offer.CreateDhcpOfferPacketFrom(packet) 106 151 107 if self.backend.Discover(offer) 152 if self.backend.Discover(offer): 108 153 self.SendPacket(offer) 109 154 # FIXME : what if false ?
Note: See TracChangeset
for help on using the changeset viewer.