case LOOKIP_ENTRY:
label = "lookup:";
break;
+ case LOOKIP_NOT_FOUND:
+ label = "not found:";
+ break;
case LOOKIP_NOTIFY_UP:
label = "up:";
break;
resp.id[sizeof(resp.id) - 1] = '\0';
resp.name[sizeof(resp.name) - 1] = '\0';
- printf("%-8s %16s %16s %20s %s\n",
+ printf("%-12s %16s %16s %20s %s\n",
label, resp.vip, resp.ip, resp.name, resp.id);
}
}
/** request a dump of all entries */
LOOKIP_DUMP = 1,
/** lookup a specific virtual IP */
- LOOKIP_LOOKUP = 2,
+ LOOKIP_LOOKUP,
/** reply message for DUMP and LOOKUP */
- LOOKIP_ENTRY = 3,
+ LOOKIP_ENTRY,
+ /** reply message for LOOKUP if no such IP found */
+ LOOKIP_NOT_FOUND,
/** register for notifications about new virtual IPs */
- LOOKIP_REGISTER_UP = 4,
+ LOOKIP_REGISTER_UP,
/** register for notifications about virtual IPs released */
- LOOKIP_REGISTER_DOWN = 5,
+ LOOKIP_REGISTER_DOWN,
/** notify reply message for REGISTER_UP */
- LOOKIP_NOTIFY_UP = 6,
+ LOOKIP_NOTIFY_UP,
/** notify reply message for REGISTER_DOWN */
- LOOKIP_NOTIFY_DOWN = 7,
+ LOOKIP_NOTIFY_DOWN,
/** end of request batch */
- LOOKIP_END = 8,
+ LOOKIP_END,
};
/**
/**
* Response message sent to client.
*
- * Valid response message types are ENTRY and NOTIFY_UP/DOWN.
+ * Valid response message types are ENTRY, NOT_FOUND and NOTIFY_UP/DOWN.
+ *
+ * All fields are set in all messages, except in NOT_FOUND: Only vip is set.
*/
struct lookip_response_t {
/** response message type */
.type = LOOKIP_ENTRY,
};
host_t *vip = NULL;
+ int matches = 0;
if (req)
{ /* lookup */
vip = host_create_from_string(req->vip, 0);
if (vip)
{
- this->listener->lookup(this->listener, vip,
- (void*)listener_cb, &entry);
+ matches = this->listener->lookup(this->listener, vip,
+ (void*)listener_cb, &entry);
vip->destroy(vip);
}
+ if (matches == 0)
+ {
+ lookip_response_t resp = {
+ .type = LOOKIP_NOT_FOUND,
+ };
+
+ snprintf(resp.vip, sizeof(resp.vip), "%s", req->vip);
+ if (send(fd, &resp, sizeof(resp), 0) < 0)
+ {
+ DBG1(DBG_CFG, "sending lookip not-found failed: %s",
+ strerror(errno));
+ }
+ }
}
else
{ /* dump */