def update_lease(leases, entry):
    """
    Update a dictionary of DHCP leases with a new entry.

    The dictionary should be indexed by MAC address. The new entry will be
    added to the dictionary unless it would replace an entry for the same MAC
    address from a more recent lease file.
    """
    mac_addr = entry['mac_addr']
    if mac_addr in leases:
        existing = leases[mac_addr]
        if existing['as_of'] >= entry['as_of']:
            return existing
    leases[mac_addr] = entry
    return entry
