dhcp: correct copyright in send.scm

This commit is contained in:
Rohan Prinja 2015-06-10 09:47:20 +05:30
parent 9f3281e5db
commit a60c0f4e88
7 changed files with 69 additions and 76 deletions

View File

@ -22,12 +22,11 @@ coding: utf-8
; DHCP client module
(define-module (dhcp client)
#:use-module (dhcp dhcp)
#:use-module (ice-9 getopt-long)
#:use-module (dhcp messages)
#:export (main))
(use-modules (dhcp dhcp)
(ice-9 getopt-long)
(dhcp messages))
(define *help-message* "\
dhcp-client [options]
-v, --version Display version

View File

@ -16,71 +16,70 @@
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(define-module (dhcp dhcp)
#:use-module (dhcp messages)
#:use-module (oop goops)
#:use-module (rnrs base)
#:use-module (ice-9 regex)
#:use-module (srfi srfi-9)
#:use-module ((srfi srfi-1) #:select (find))
#:export (<dhcp>
dhcp-xid set-dhcp-xid!
dhcp-state set-dhcp-state!
dhcp-tries set-dhcp-tries!
dhcp-start
dhcp-renew
dhcp-release
dhcp-stop
dhcp-inform
get-most-recent-lease
generate-different-xid
generate-random-xid))
(use-modules (dhcp messages)
(oop goops)
(rnrs base)
(ice-9 regex)
((srfi srfi-1) #:select (find)))
;; Class for DHCP objects.
;; A <dhcp> object is held by an interface, and contains
;; information about the configuration process for that
;; specific interface.
(define-record-type <dhcp>
(make-dhcp xid state tries
t0 t1 t2
lease-ack
ip-addr sn-mask gw-addr)
; Class for DHCP objects.
; A <dhcp> object is held by an interface, and contains
; information about the configuration process for that
; specific interface.
(define-class <dhcp> ()
; transaction identifier of last sent request
xid
; number of retries for current request
tries
; current state, see Page 34, RFC 2131 for the transition diagram
(state #:init-form 'DHCP-INIT
#:init-keyword #:state)
t1_renew_time ; time until next renew try
t2_rebind_time ; time until next rebind try
lease_ack ; time since last DHCPACK
t0_timeout ; time until lease expiry
dhcp?
offered_ip_addr
offered_sn_mask
offered_gw_addr
(xid dhcp-xid set-dhcp-xid!)
(state dhcp-state set-dhcp-state!) ; see Page 34, RFC 2131 for the state transition diagram
(tries dhcp-tries set-dhcp-tries!) ; number of retries for current request
offered_t0_lease
offered_t1_renew
offered_t2_rebind
(t0 dhcp-t0) ; time until lease expiry
(t1 dhcp-t1) ; time until next renew try
(t2 dhcp-t2) ; time until next rebind try
(lease-ack dhcp-lease-ack) ; time since last DHCPACK
(config-started-at #:init-form (current-time))
dhcpdiscover-sent-at)
;; Offered IP address, subnet mask and gateway address.
(ip-addr dhcp-ip-addr)
(sn-mask dhcp-sn-mask)
(gw-addr dhcp-gw-addr)
;; Time at which configuration process was started.
(config-start dhcp-config-start set-dhcp-config-start!))
; Generate a random 32-bit number to be used as
; a transaction id.
(define (generate-random-xid)
"Generate a random 32-bit number to be used as
a transaction id."
(random (expt 2 32)))
(define-method (generate-different-xid (dhcp <dhcp>))
"Generate a new, different transaction id for
a dhcp object. We simply increment the old one."
(1+ (slot-ref dhcp 'xid)))
(1+ (dhcp-xid dhcp)))
; config-start: time when config process began
; dhcpdiscover-sent-at: time at which most recent
; DHCPDISCOVER packet was sent
; config-start and dhcpdiscover-sent-at are stored
; as seconds since epoch
; TODO: make a separate lease file for each interface rather than
; logging all interfaces into the same log file. This means no "interface"
; field in the leases file. Apart from this, the file format is the same
; as that of dhclient. See dhclient.conf (5) for more information.
;; TODO: make a separate lease file for each interface rather than
;; logging all interfaces into the same log file. This means no "interface"
;; field in the leases file. Apart from this, the file format is the same
;; as that of dhclient. See dhclient.conf (5) for more information.
(define *leases-file* "/var/lib/dhcp/dhclient.leases")
(define (parse-lease-string lease-str)

View File

@ -16,6 +16,12 @@
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(define-module (dhcp interfaces)
#:use-module (dhcp dhcp)
#:use-module (system foreign)
#:use-module (oop goops)
#:use-module (guix build syscalls)
#:use-module (rnrs base)
#:use-module (rnrs bytevectors)
#:export (<net-interface>
hardware-address
hardware-family
@ -23,13 +29,6 @@
print-hardware-address
make-network-interface))
(use-modules (dhcp dhcp)
(system foreign)
(oop goops)
(guix build syscalls)
(rnrs base)
(rnrs bytevectors))
;;; Taken/modified from (guix build syscalls) begin
(define SIOCGIFHWADDR

View File

@ -15,8 +15,16 @@
;;; You should have received a copy of the GNU General Public License
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
; Module for constructing and parsing DHCP messages
;; Module for constructing and parsing DHCP messages
(define-module (dhcp messages)
#:use-module (dhcp interfaces)
#:use-module (dhcp dhcp)
#:use-module (dhcp options base)
#:use-module (dhcp options names)
#:use-module (oop goops)
#:use-module (rnrs base)
#:use-module (rnrs bytevectors)
#:use-module (rnrs enums)
#:export (<dhcp-message>
set-broadcast-bit
unset-broadcast-bit
@ -27,15 +35,6 @@
make-dhcpdiscover
map-type-to-code))
(use-modules (dhcp interfaces)
(dhcp dhcp)
(dhcp options base)
(dhcp options names)
(oop goops)
(rnrs base)
(rnrs bytevectors)
(rnrs enums))
; Magic cookie that starts off the 'options' field
; in a DHCP message packet.
(define *magic-cookie* #vu8(99 130 83 99))
@ -97,8 +96,8 @@ simply ignored whilst serializing."
(if (eq? #nil opt)
(loop (1+ i))
(let ((code i)
(len (slot-ref opt 'len))
(val (slot-ref opt 'val)))
(len (dhcp-option-len opt))
(val (dhcp-option-val opt)))
(begin
(if (zero? len)
(bytevector-u8-set! dst idx code)
@ -205,14 +204,14 @@ from BV starting at index START"
(define-method (set-option! (msg <dhcp-message>) (opt <dhcp-option>))
"Set an <option> in a <dhcp-message>."
(vector-set! (slot-ref msg 'options)
(slot-ref opt 'code)
(dhcp-option-code opt)
opt))
(define-method (option-value (msg <dhcp-message>) code)
"Retrieve an option's value from a <dhcp-message>."
(let* ((opts (slot-ref msg 'options))
(opt (vector-ref opts code))
(val (slot-ref opt 'val)))
(val (dhcp-option-val opt)))
val))
; Get the DHCP message type. See Section 9.6, RFC 2132.

View File

@ -16,6 +16,8 @@
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(define-module (dhcp options base)
#:use-module (srfi srfi-9)
#:use-module (rnrs bytevectors)
#:export (<dhcp-option>
make-dhcp-option
dhcp-option?
@ -23,9 +25,6 @@
dhcp-option-len
dhcp-option-val))
(use-modules (srfi srfi-9)
(rnrs bytevectors))
; DHCP option object.
; See RFC 2132 for a list of DHCP options.
(define-record-type <dhcp-option>

View File

@ -16,10 +16,9 @@
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(define-module (dhcp options names)
#:use-module (rnrs enums)
#:export (map-name-to-code))
(use-modules (rnrs enums))
; For the options marked UNUSED, refer to RFC 3679.
(define *option-names*
(make-enumeration '(PAD

View File

@ -1,6 +1,6 @@
;;; GNU Guix DHCP Client.
;;;
;;; Copyright 2015 Free Software Foundation, Inc.
;;; Copyright © 2015 Rohan Prinja <rohan.prinja@gmail.com>
;;;
;;; This program is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
@ -16,13 +16,12 @@
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(define-module (dhcp send)
#:use-module (rnrs bytevectors)
#:export (make-dgram-sock
make-broadcast-sockaddr
*client-in-port*
*client-out-port*))
(use-modules (rnrs bytevectors))
(define-syntax-rule (make-dgram-sock)
(socket PF_INET SOCK_DGRAM IPPROTO_UDP))