int tickle;
} child;
+typedef struct {
+ uint16_t DSIreqID;
+ uint8_t AFPcommand;
+ uint32_t result;
+} rc_elem_t;
+
+/*
+ * AFP replay cache:
+ * - fix sized array
+ * - indexed just by taking DSIreqID mod REPLAYCACHE_SIZE
+ */
+rc_elem_t replaycache[REPLAYCACHE_SIZE];
static void afp_dsi_close(AFPObj *obj)
{
void afp_over_dsi(AFPObj *obj)
{
DSI *dsi = (DSI *) obj->handle;
+ int rc_idx;
u_int32_t err, cmd;
u_int8_t function;
struct sigaction action;
function = (u_char) dsi->commands[0];
- /* send off an afp command. in a couple cases, we take advantage
- * of the fact that we're a stream-based protocol. */
- if (afp_switch[function]) {
- dsi->datalen = DSI_DATASIZ;
- child.flags |= CHILD_RUNNING;
+ /* AFP replay cache */
+ rc_idx = REPLAYCACHE_SIZE % dsi->clientID;
+ LOG(log_debug, logtype_afpd, "DSI request ID: %u", dsi->clientID);
- LOG(log_debug, logtype_afpd, "<== Start AFP command: %s", AfpNum2name(function));
+ if (replaycache[rc_idx].DSIreqID == dsi->clientID
+ && replaycache[rc_idx].AFPcommand == function) {
+ LOG(log_debug, logtype_afpd, "AFP Replay Cache match: id: %u / cmd: %s",
+ dsi->clientID, AfpNum2name(function));
+ err = replaycache[rc_idx].result;
+ /* AFP replay cache end */
+ } else {
+ /* send off an afp command. in a couple cases, we take advantage
+ * of the fact that we're a stream-based protocol. */
+ if (afp_switch[function]) {
+ dsi->datalen = DSI_DATASIZ;
+ child.flags |= CHILD_RUNNING;
- err = (*afp_switch[function])(obj,
- (char *)&dsi->commands, dsi->cmdlen,
- (char *)&dsi->data, &dsi->datalen);
+ LOG(log_debug, logtype_afpd, "<== Start AFP command: %s", AfpNum2name(function));
- LOG(log_debug, logtype_afpd, "==> Finished AFP command: %s -> %s",
- AfpNum2name(function), AfpErr2name(err));
+ err = (*afp_switch[function])(obj,
+ (char *)&dsi->commands, dsi->cmdlen,
+ (char *)&dsi->data, &dsi->datalen);
+
+ LOG(log_debug, logtype_afpd, "==> Finished AFP command: %s -> %s",
+ AfpNum2name(function), AfpErr2name(err));
- dir_free_invalid_q();
+ dir_free_invalid_q();
#ifdef FORCE_UIDGID
- /* bring everything back to old euid, egid */
- if (obj->force_uid)
- restore_uidgid ( &obj->uidgid );
+ /* bring everything back to old euid, egid */
+ if (obj->force_uid)
+ restore_uidgid ( &obj->uidgid );
#endif /* FORCE_UIDGID */
- child.flags &= ~CHILD_RUNNING;
- } else {
- LOG(log_error, logtype_afpd, "bad function %X", function);
- dsi->datalen = 0;
- err = AFPERR_NOOP;
+ child.flags &= ~CHILD_RUNNING;
+
+ /* Add result to the AFP replay cache */
+ replaycache[rc_idx].DSIreqID = dsi->clientID;
+ replaycache[rc_idx].AFPcommand = function;
+ replaycache[rc_idx].result = err;
+ } else {
+ LOG(log_error, logtype_afpd, "bad function %X", function);
+ dsi->datalen = 0;
+ err = AFPERR_NOOP;
+ }
}
/* single shot toggle that gets set by dsi_readinit. */
void dsi_opensession(DSI *dsi)
{
u_int32_t i = 0; /* this serves double duty. it must be 4-bytes long */
+ int offs;
/* parse options */
while (i < dsi->cmdlen) {
dsi->header.dsi_flags = DSIFL_REPLY;
dsi->header.dsi_code = 0;
/* dsi->header.dsi_command = DSIFUNC_OPEN;*/
- dsi->cmdlen = 2 + sizeof(i); /* length of data. dsi_send uses it. */
+
+ dsi->cmdlen = 2 * (2 + sizeof(i)); /* length of data. dsi_send uses it. */
+
+ /* DSI Option Server Request Quantum */
dsi->commands[0] = DSIOPT_SERVQUANT;
dsi->commands[1] = sizeof(i);
i = htonl(( dsi->server_quantum < DSI_SERVQUANT_MIN ||
DSI_SERVQUANT_DEF : dsi->server_quantum);
memcpy(dsi->commands + 2, &i, sizeof(i));
+ /* AFP replaycache size option */
+ offs = 2 + sizeof(i);
+ dsi->commands[offs] = DSIOPT_REPLCSIZE;
+ dsi->commands[offs+1] = sizeof(i);
+ i = htonl(REPLAYCACHE_SIZE);
+ memcpy(dsi->commands + offs + 2, &i, sizeof(i));
dsi_send(dsi);
}