Browse files

Support for timed overrides

This change adds support for expiration of override rules. This is intended to
be used by dhcplb to decide whether or not an override rule should be ignored.

Reviewed By: pallotron

Differential Revision: D5015330

fbshipit-source-id: 6ff8f546fdc4cef2a8434d2bdf63483934998e37
  • Loading branch information...
marcoguerri authored and facebook-github-bot committed May 11, 2017
1 parent 5231529 commit 8b1154156b0d4cdda49ffe7856caff3733de1f4f
Showing with 46 additions and 5 deletions.
  1. +21 −1 docs/
  2. +3 −2 lib/config.go
  3. +22 −2 lib/handler.go
@@ -53,7 +53,27 @@ will be sent to the DHCP server at ``, and requests from MAC
`fe:dc:ba:09:87:65` will be sent to the tier of servers `myGroup` (a server will
be picked according to the balancing algorithm's selection from the list of
servers returned by the `GetServersFromTier(tier string)` function of the
`DHCPServerSourcer` being used.)
`DHCPServerSourcer` being used).
Overrides may be associated with an expiration timestamp in the form
the timezone offset with respect to UTC. `dhcplb` will convert the timestamp
in the local timezone and ignore expired overrides.
"v4": {
"12:34:56:78:90:ab": {
"host": "",
"expiration": "2017/05/06 14:00 +0000"
"fe:dc:ba:09:87:65": {
"tier": "myGroup"
"v6": {
@@ -50,8 +50,9 @@ type Config struct {
// want to send packets to.
type Override struct {
// note that Host override takes precedence over Tier
Host string `json:"host"`
Tier string `json:"tier"`
Host string `json:"host"`
Tier string `json:"tier"`
Expiration string `json:"expiration"`
// Overrides is a struct that holds v4 and v6 list of overrides.
@@ -98,9 +98,29 @@ func selectDestinationServer(config *Config, message *DHCPMessage) (*DHCPServer,
func handleOverride(config *Config, message *DHCPMessage) (*DHCPServer, error) {
if override, ok := config.Overrides[FormatID(message.Mac)]; ok {
glog.Infof("Found override rule for %s", FormatID(message.Mac))
var server *DHCPServer
// Checking if override is expired. If so, ignore it. Expiration field should
// be a timestamp in the following format "2006/01/02 15:04 -0700".
// For example, a timestamp in UTC would look as follows: "2017/05/06 14:00 +0000".
var err error
var expiration time.Time
if override.Expiration != "" {
expiration, err = time.Parse("2006/01/02 15:04 -0700", override.Expiration)
if err != nil {
glog.Errorf("Could not parse override expiration for MAC %s: %s", FormatID(message.Mac), err.Error())
return nil, nil
if time.Now().After(expiration) {
glog.Errorf("Ovverride rule for MAC %s expired on %s, ignoring", FormatID(message.Mac), expiration.Local())
return nil, nil
if override.Expiration == "" {
glog.Infof("Found override rule for %s without expiration", FormatID(message.Mac))
} else {
glog.Infof("Found override rule for %s, it will expire on %s", FormatID(message.Mac), expiration.Local())
var server *DHCPServer
if len(override.Host) > 0 {
server, err = handleHostOverride(config, override.Host)
} else if len(override.Tier) > 0 {

0 comments on commit 8b11541

Please sign in to comment.